Search in sources :

Example 1 with DanmakuTimer

use of master.flame.danmaku.danmaku.model.DanmakuTimer 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 DanmakuTimer

use of master.flame.danmaku.danmaku.model.DanmakuTimer in project GSYVideoPlayer by CarGuo.

the class DanmakuVideoPlayer method initDanmaku.

private void initDanmaku() {
    // 设置最大显示行数
    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);
    DanamakuAdapter danamakuAdapter = new DanamakuAdapter(mDanmakuView);
    mDanmakuContext = DanmakuContext.create();
    mDanmakuContext.setDanmakuStyle(IDisplayer.DANMAKU_STYLE_STROKEN, 3).setDuplicateMergingEnabled(false).setScrollSpeedFactor(1.2f).setScaleTextSize(1.2f).setCacheStuffer(new SpannedCacheStuffer(), // 图文混排使用SpannedCacheStuffer
    danamakuAdapter).setMaximumLines(maxLinesPair).preventOverlapping(overlappingEnablePair);
    if (mDanmakuView != null) {
        //todo 替换成你的数据流
        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) {
            }

            @Override
            public void prepared() {
                if (getDanmakuView() != null) {
                    getDanmakuView().start();
                    if (getDanmakuStartSeekPosition() != -1) {
                        resolveDanmakuSeek(DanmakuVideoPlayer.this, getDanmakuStartSeekPosition());
                        setDanmakuStartSeekPosition(-1);
                    }
                    resolveDanmakuShow();
                }
            }
        });
        mDanmakuView.enableDanmakuDrawingCache(true);
    }
}
Also used : HashMap(java.util.HashMap) DanamakuAdapter(com.example.gsyvideoplayer.adapter.DanamakuAdapter) BaseDanmaku(master.flame.danmaku.danmaku.model.BaseDanmaku) SpannedCacheStuffer(master.flame.danmaku.danmaku.model.android.SpannedCacheStuffer) DanmakuTimer(master.flame.danmaku.danmaku.model.DanmakuTimer)

Example 3 with DanmakuTimer

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

the class CacheManagingDrawTask method initTimer.

@Override
protected void initTimer(DanmakuTimer timer) {
    mTimer = timer;
    mCacheTimer = new DanmakuTimer();
    mCacheTimer.update(timer.currMillisecond);
}
Also used : DanmakuTimer(master.flame.danmaku.danmaku.model.DanmakuTimer)

Example 4 with DanmakuTimer

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

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);
    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);
    mBtnSendDanmakus.setOnClickListener(this);
    // VideoView
    VideoView mVideoView = (VideoView) findViewById(R.id.videoview);
    // DanmakuView
    mDanmakuView = (IDanmakuView) findViewById(R.id.sv_danmaku);
    DanmakuGlobalConfig.DEFAULT.setDanmakuStyle(DanmakuGlobalConfig.DANMAKU_STYLE_STROKEN, 3).setDuplicateMergingEnabled(false);
    if (mDanmakuView != null) {
        mParser = createParser(this.getResources().openRawResource(R.raw.comments));
        mDanmakuView.setCallback(new Callback() {

            @Override
            public void updateTimer(DanmakuTimer timer) {
            }

            @Override
            public void prepared() {
                mDanmakuView.start();
            }
        });
        mDanmakuView.prepare(mParser);
        mDanmakuView.showFPS(true);
        mDanmakuView.enableDanmakuDrawingCache(true);
        ((View) mDanmakuView).setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                mMediaController.setVisibility(View.VISIBLE);
            }
        });
    }
    if (mVideoView != null) {
        mVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {

            @Override
            public void onPrepared(MediaPlayer mediaPlayer) {
                mediaPlayer.start();
            }
        });
        // mVideoView.setVideoPath(Environment.getExternalStorageDirectory() + "/1.flv");
        mVideoView.setVideoURI(Uri.parse("http://us-chicago.acgvideo.com/e/e9/3444659.mp4?expires=1429119900&ssig=o8fAECKGmZkIsdZE31EYOQ&o=401361084&rate=0"));
    }
}
Also used : Callback(master.flame.danmaku.controller.DrawHandler.Callback) VideoView(android.widget.VideoView) DanmakuTimer(master.flame.danmaku.danmaku.model.DanmakuTimer) View(android.view.View) VideoView(android.widget.VideoView) DanmakuSurfaceView(master.flame.danmaku.ui.widget.DanmakuSurfaceView) IDanmakuView(master.flame.danmaku.controller.IDanmakuView) MediaPlayer(android.media.MediaPlayer)

Example 5 with DanmakuTimer

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

the class CacheManagingDrawTask method initTimer.

@Override
protected void initTimer(DanmakuTimer timer) {
    mTimer = timer;
    mCacheTimer = new DanmakuTimer();
    mCacheTimer.update(timer.currMillisecond);
}
Also used : DanmakuTimer(master.flame.danmaku.danmaku.model.DanmakuTimer)

Aggregations

DanmakuTimer (master.flame.danmaku.danmaku.model.DanmakuTimer)6 MediaPlayer (android.media.MediaPlayer)3 VideoView (android.widget.VideoView)3 HashMap (java.util.HashMap)3 IDanmakuView (master.flame.danmaku.controller.IDanmakuView)3 BaseDanmaku (master.flame.danmaku.danmaku.model.BaseDanmaku)3 IDanmakus (master.flame.danmaku.danmaku.model.IDanmakus)2 SpannedCacheStuffer (master.flame.danmaku.danmaku.model.android.SpannedCacheStuffer)2 Bitmap (android.graphics.Bitmap)1 Paint (android.graphics.Paint)1 TextPaint (android.text.TextPaint)1 View (android.view.View)1 DanamakuAdapter (com.example.gsyvideoplayer.adapter.DanamakuAdapter)1 Callback (master.flame.danmaku.controller.DrawHandler.Callback)1 AndroidDisplayer (master.flame.danmaku.danmaku.model.android.AndroidDisplayer)1 DanmakuSurfaceView (master.flame.danmaku.ui.widget.DanmakuSurfaceView)1