Search in sources :

Example 1 with IDanmakus

use of master.flame.danmaku.danmaku.model.IDanmakus in project DanmakuFlameMaster by Bilibili.

the class MainActivity method findViews.

private void findViews() {
    mMediaController = findViewById(R.id.media_controller);
    mBtnRotate = (Button) findViewById(R.id.rotate);
    mBtnHideDanmaku = (Button) findViewById(R.id.btn_hide);
    mBtnShowDanmaku = (Button) findViewById(R.id.btn_show);
    mBtnPauseDanmaku = (Button) findViewById(R.id.btn_pause);
    mBtnResumeDanmaku = (Button) findViewById(R.id.btn_resume);
    mBtnSendDanmaku = (Button) findViewById(R.id.btn_send);
    mBtnSendDanmakuTextAndImage = (Button) findViewById(R.id.btn_send_image_text);
    mBtnSendDanmakus = (Button) findViewById(R.id.btn_send_danmakus);
    mBtnRotate.setOnClickListener(this);
    mBtnHideDanmaku.setOnClickListener(this);
    mMediaController.setOnClickListener(this);
    mBtnShowDanmaku.setOnClickListener(this);
    mBtnPauseDanmaku.setOnClickListener(this);
    mBtnResumeDanmaku.setOnClickListener(this);
    mBtnSendDanmaku.setOnClickListener(this);
    mBtnSendDanmakuTextAndImage.setOnClickListener(this);
    mBtnSendDanmakus.setOnClickListener(this);
    // VideoView
    VideoView mVideoView = (VideoView) findViewById(R.id.videoview);
    // DanmakuView
    // 设置最大显示行数
    HashMap<Integer, Integer> maxLinesPair = new HashMap<Integer, Integer>();
    // 滚动弹幕最大显示5行
    maxLinesPair.put(BaseDanmaku.TYPE_SCROLL_RL, 5);
    // 设置是否禁止重叠
    HashMap<Integer, Boolean> overlappingEnablePair = new HashMap<Integer, Boolean>();
    overlappingEnablePair.put(BaseDanmaku.TYPE_SCROLL_RL, true);
    overlappingEnablePair.put(BaseDanmaku.TYPE_FIX_TOP, true);
    mDanmakuView = (IDanmakuView) findViewById(R.id.sv_danmaku);
    mContext = DanmakuContext.create();
    mContext.setDanmakuStyle(IDisplayer.DANMAKU_STYLE_STROKEN, 3).setDuplicateMergingEnabled(false).setScrollSpeedFactor(1.2f).setScaleTextSize(1.2f).setCacheStuffer(new SpannedCacheStuffer(), // 图文混排使用SpannedCacheStuffer
    mCacheStufferAdapter).setMaximumLines(maxLinesPair).preventOverlapping(overlappingEnablePair);
    if (mDanmakuView != null) {
        mParser = createParser(this.getResources().openRawResource(R.raw.comments));
        mDanmakuView.setCallback(new master.flame.danmaku.controller.DrawHandler.Callback() {

            @Override
            public void updateTimer(DanmakuTimer timer) {
            }

            @Override
            public void drawingFinished() {
            }

            @Override
            public void danmakuShown(BaseDanmaku danmaku) {
            //                    Log.d("DFM", "danmakuShown(): text=" + danmaku.text);
            }

            @Override
            public void prepared() {
                mDanmakuView.start();
            }
        });
        mDanmakuView.setOnDanmakuClickListener(new IDanmakuView.OnDanmakuClickListener() {

            @Override
            public boolean onDanmakuClick(IDanmakus danmakus) {
                Log.d("DFM", "onDanmakuClick: danmakus size:" + danmakus.size());
                BaseDanmaku latest = danmakus.last();
                if (null != latest) {
                    Log.d("DFM", "onDanmakuClick: text of latest danmaku:" + latest.text);
                    return true;
                }
                return false;
            }

            @Override
            public boolean onViewClick(IDanmakuView view) {
                mMediaController.setVisibility(View.VISIBLE);
                return false;
            }
        });
        mDanmakuView.prepare(mParser, mContext);
        mDanmakuView.showFPS(true);
        mDanmakuView.enableDanmakuDrawingCache(true);
    }
    if (mVideoView != null) {
        mVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {

            @Override
            public void onPrepared(MediaPlayer mediaPlayer) {
                mediaPlayer.start();
            }
        });
        mVideoView.setVideoPath(Environment.getExternalStorageDirectory() + "/1.flv");
    }
}
Also used : IDanmakuView(master.flame.danmaku.controller.IDanmakuView) HashMap(java.util.HashMap) VideoView(android.widget.VideoView) BaseDanmaku(master.flame.danmaku.danmaku.model.BaseDanmaku) SpannedCacheStuffer(master.flame.danmaku.danmaku.model.android.SpannedCacheStuffer) DanmakuTimer(master.flame.danmaku.danmaku.model.DanmakuTimer) IDanmakus(master.flame.danmaku.danmaku.model.IDanmakus) MediaPlayer(android.media.MediaPlayer)

Example 2 with IDanmakus

use of master.flame.danmaku.danmaku.model.IDanmakus in project DanmakuFlameMaster by Bilibili.

the class DanmakuFactory method updateSpecialDanmakusDate.

private void updateSpecialDanmakusDate(final float scaleX, final float scaleY) {
    IDanmakus list = sSpecialDanmakus;
    list.forEachSync(new IDanmakus.DefaultConsumer<BaseDanmaku>() {

        @Override
        public int accept(BaseDanmaku danmaku) {
            SpecialDanmaku speicalDanmaku = (SpecialDanmaku) danmaku;
            fillTranslationData(speicalDanmaku, speicalDanmaku.beginX, speicalDanmaku.beginY, speicalDanmaku.endX, speicalDanmaku.endY, speicalDanmaku.translationDuration, speicalDanmaku.translationStartDelay, scaleX, scaleY);
            LinePath[] linePaths = speicalDanmaku.linePaths;
            if (linePaths != null && linePaths.length > 0) {
                int length = linePaths.length;
                float[][] points = new float[length + 1][2];
                for (int j = 0; j < length; j++) {
                    points[j] = linePaths[j].getBeginPoint();
                    points[j + 1] = linePaths[j].getEndPoint();
                }
                fillLinePathData(speicalDanmaku, points, scaleX, scaleY);
            }
            return ACTION_CONTINUE;
        }
    });
}
Also used : BaseDanmaku(master.flame.danmaku.danmaku.model.BaseDanmaku) SpecialDanmaku(master.flame.danmaku.danmaku.model.SpecialDanmaku) IDanmakus(master.flame.danmaku.danmaku.model.IDanmakus)

Example 3 with IDanmakus

use of master.flame.danmaku.danmaku.model.IDanmakus in project DanmakuFlameMaster by Bilibili.

the class DrawTask method removeAllDanmakus.

@Override
public synchronized void removeAllDanmakus(boolean isClearDanmakusOnScreen) {
    if (danmakuList == null || danmakuList.isEmpty())
        return;
    synchronized (danmakuList) {
        if (!isClearDanmakusOnScreen) {
            long beginMills = mTimer.currMillisecond - mContext.mDanmakuFactory.MAX_DANMAKU_DURATION - 100;
            long endMills = mTimer.currMillisecond + mContext.mDanmakuFactory.MAX_DANMAKU_DURATION;
            IDanmakus tempDanmakus = danmakuList.subnew(beginMills, endMills);
            if (tempDanmakus != null)
                danmakus = tempDanmakus;
        }
        danmakuList.clear();
    }
}
Also used : IDanmakus(master.flame.danmaku.danmaku.model.IDanmakus)

Example 4 with IDanmakus

use of master.flame.danmaku.danmaku.model.IDanmakus in project ABPlayer by winkstu.

the class Danmakus method sub.

@Override
public IDanmakus sub(long startTime, long endTime) {
    if (mSortType == ST_BY_LIST || items == null || items.size() == 0) {
        return null;
    }
    if (subItems == null) {
        subItems = new Danmakus(mDuplicateMergingEnabled);
    }
    if (startItem == null) {
        startItem = createItem("start");
    }
    if (endItem == null) {
        endItem = createItem("end");
    }
    if (subItems != null) {
        long dtime = startTime - startItem.time;
        if (dtime >= 0 && endTime <= endItem.time) {
            return subItems;
        }
    }
    startItem.time = startTime;
    endItem.time = endTime;
    subItems.setItems(((SortedSet<BaseDanmaku>) items).subSet(startItem, endItem));
    return subItems;
}
Also used : BaseDanmaku(master.flame.danmaku.danmaku.model.BaseDanmaku) IDanmakus(master.flame.danmaku.danmaku.model.IDanmakus)

Example 5 with IDanmakus

use of master.flame.danmaku.danmaku.model.IDanmakus in project ABPlayer by winkstu.

the class DrawTask method drawDanmakus.

protected RenderingState drawDanmakus(AbsDisplayer<?> disp, DanmakuTimer timer) {
    if (clearRetainerFlag) {
        DanmakusRetainer.clear();
        clearRetainerFlag = false;
    }
    if (danmakuList != null) {
        Canvas canvas = (Canvas) disp.getExtraData();
        DrawHelper.clearCanvas(canvas);
        if (mIsHidden) {
            return mRenderingState;
        }
        long beginMills = timer.currMillisecond - DanmakuFactory.MAX_DANMAKU_DURATION - 100;
        long endMills = timer.currMillisecond + DanmakuFactory.MAX_DANMAKU_DURATION;
        if (mLastBeginMills > beginMills || timer.currMillisecond > mLastEndMills) {
            IDanmakus subDanmakus = danmakuList.sub(beginMills, endMills);
            if (subDanmakus != null) {
                danmakus = subDanmakus;
            } else {
                danmakus.clear();
            }
            mLastBeginMills = beginMills;
            mLastEndMills = endMills;
        } else {
            beginMills = mLastBeginMills;
            endMills = mLastEndMills;
        }
        if (danmakus != null && !danmakus.isEmpty()) {
            RenderingState renderingState = mRenderingState = mRenderer.draw(mDisp, danmakus, mStartRenderTime);
            if (renderingState.nothingRendered) {
                if (renderingState.beginTime == RenderingState.UNKNOWN_TIME) {
                    renderingState.beginTime = beginMills;
                }
                if (renderingState.endTime == RenderingState.UNKNOWN_TIME) {
                    renderingState.endTime = endMills;
                }
            }
            return renderingState;
        } else {
            mRenderingState.nothingRendered = true;
            mRenderingState.beginTime = beginMills;
            mRenderingState.endTime = endMills;
            return mRenderingState;
        }
    }
    return null;
}
Also used : Canvas(android.graphics.Canvas) RenderingState(master.flame.danmaku.danmaku.renderer.IRenderer.RenderingState) IDanmakus(master.flame.danmaku.danmaku.model.IDanmakus)

Aggregations

IDanmakus (master.flame.danmaku.danmaku.model.IDanmakus)13 BaseDanmaku (master.flame.danmaku.danmaku.model.BaseDanmaku)8 Danmakus (master.flame.danmaku.danmaku.model.android.Danmakus)3 Canvas (android.graphics.Canvas)2 MediaPlayer (android.media.MediaPlayer)2 VideoView (android.widget.VideoView)2 HashMap (java.util.HashMap)2 IDanmakuView (master.flame.danmaku.controller.IDanmakuView)2 DanmakuTimer (master.flame.danmaku.danmaku.model.DanmakuTimer)2 SpecialDanmaku (master.flame.danmaku.danmaku.model.SpecialDanmaku)2 RenderingState (master.flame.danmaku.danmaku.renderer.IRenderer.RenderingState)2 Bitmap (android.graphics.Bitmap)1 Paint (android.graphics.Paint)1 TextPaint (android.text.TextPaint)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 DataFormatException (java.util.zip.DataFormatException)1 ILoader (master.flame.danmaku.danmaku.loader.ILoader)1 IllegalDataException (master.flame.danmaku.danmaku.loader.IllegalDataException)1