Search in sources :

Example 1 with WhiteExoPlayer

use of com.herewhite.demo.player.exo.WhiteExoPlayer in project whiteboard-android by netless-io.

the class PlayActivity method setupPlayer.

// region override
protected void setupPlayer() {
    final String uuid = getIntent().getStringExtra(StartActivity.EXTRA_ROOM_UUID);
    try {
        if (mIsUsedExoPlayer) {
            // WhiteExoPlayer demo
            PlayerView playerView = findViewById(R.id.exo_video_view);
            playerView.setVisibility(View.VISIBLE);
            mWhiteMediaPlayer = new WhiteExoPlayer(this);
            ((WhiteExoPlayer) mWhiteMediaPlayer).setPlayerView(playerView);
            ((WhiteExoPlayer) mWhiteMediaPlayer).setVideoPath("https://white-pan.oss-cn-shanghai.aliyuncs.com/101/oceans.mp4");
        } else {
            // WhiteIjkPlayer demo
            IjkVideoView videoView = findViewById(R.id.ijk_video_view);
            videoView.setVisibility(View.VISIBLE);
            mWhiteMediaPlayer = new WhiteIjkPlayer(videoView);
            ((WhiteIjkPlayer) mWhiteMediaPlayer).setVideoPath("https://white-pan.oss-cn-shanghai.aliyuncs.com/101/oceans.mp4");
        }
        mPlayerSyncManager = new PlayerSyncManager(mWhiteMediaPlayer, new PlayerSyncManager.Callbacks() {

            @Override
            public void startBuffering() {
                Log.d(TAG_Native, "startBuffering: ");
            }

            @Override
            public void endBuffering() {
                Log.d(TAG_Native, "endBuffering: ");
            }
        });
        Log.d(TAG_Native, "create success");
    } catch (Throwable e) {
        Log.e(TAG_Native, "create fail");
    }
    DemoAPI.Result result = new DemoAPI.Result() {

        @Override
        public void success(String uuid, String roomToken) {
            initPlayer(uuid, roomToken);
        }

        @Override
        public void fail(String message) {
            alert("创建回放失败: ", message);
        }
    };
    if (uuid != null) {
        demoAPI.getRoomToken(uuid, result);
    } else if (demoAPI.hasDemoInfo()) {
        demoAPI.getNewRoom(result);
    } else {
        alert("无数据", "没有房间 uuid");
    }
}
Also used : WhiteIjkPlayer(com.herewhite.demo.player.ijk.WhiteIjkPlayer) WhiteExoPlayer(com.herewhite.demo.player.exo.WhiteExoPlayer) DemoAPI(com.herewhite.demo.common.DemoAPI) IjkVideoView(com.herewhite.demo.player.ijk.widget.media.IjkVideoView) PlayerView(com.google.android.exoplayer2.ui.PlayerView) PlayerSyncManager(com.herewhite.sdk.combinePlayer.PlayerSyncManager)

Example 2 with WhiteExoPlayer

use of com.herewhite.demo.player.exo.WhiteExoPlayer in project whiteboard-android by netless-io.

the class PlayActivity method initPlayer.

// endregion
protected void initPlayer(String uuid, String roomToken) {
    WhiteSdk whiteSdk = new WhiteSdk(mWhiteboardView, PlayActivity.this, new WhiteSdkConfiguration(demoAPI.getAppId(), true), new UrlInterrupter() {

        @Override
        public String urlInterrupter(String sourceUrl) {
            return sourceUrl;
        }
    });
    PlayerConfiguration playerConfiguration = new PlayerConfiguration(uuid, roomToken);
    // 只回放 60 秒。如果时间太长,seek bar 进度条移动不明显。
    // 实际播放时,需要对齐原始音视频和白板
    playerConfiguration.setDuration(60000L);
    whiteSdk.createPlayer(playerConfiguration, this, new Promise<Player>() {

        @Override
        public void then(Player wPlayer) {
            mPlaybackPlayer = wPlayer;
            mPlayerSyncManager.setWhitePlayer(mPlaybackPlayer);
            setupSeekBar();
            if (mWhiteMediaPlayer != null) {
                if (mIsUsedExoPlayer) {
                    ((WhiteExoPlayer) mWhiteMediaPlayer).setPlayerSyncManager(mPlayerSyncManager);
                } else {
                    ((WhiteIjkPlayer) mWhiteMediaPlayer).setPlayerSyncManager(mPlayerSyncManager);
                }
            }
            // seek 一次才能主动触发
            mPlaybackPlayer.seekToScheduleTime(0);
            enableBtn();
            play();
            mSeekBarUpdateHandler.postDelayed(mUpdateSeekBar, 100);
            testMarkIdling(true);
        }

        @Override
        public void catchEx(SDKError t) {
            alert("create player error, ", t.getJsStack());
        }
    });
}
Also used : UrlInterrupter(com.herewhite.sdk.domain.UrlInterrupter) WhiteExoPlayer(com.herewhite.demo.player.exo.WhiteExoPlayer) NativePlayer(com.herewhite.sdk.combinePlayer.NativePlayer) Player(com.herewhite.sdk.Player) WhiteIjkPlayer(com.herewhite.demo.player.ijk.WhiteIjkPlayer) PlayerConfiguration(com.herewhite.sdk.domain.PlayerConfiguration) WhiteSdkConfiguration(com.herewhite.sdk.WhiteSdkConfiguration) SDKError(com.herewhite.sdk.domain.SDKError) WhiteSdk(com.herewhite.sdk.WhiteSdk)

Aggregations

WhiteExoPlayer (com.herewhite.demo.player.exo.WhiteExoPlayer)2 WhiteIjkPlayer (com.herewhite.demo.player.ijk.WhiteIjkPlayer)2 PlayerView (com.google.android.exoplayer2.ui.PlayerView)1 DemoAPI (com.herewhite.demo.common.DemoAPI)1 IjkVideoView (com.herewhite.demo.player.ijk.widget.media.IjkVideoView)1 Player (com.herewhite.sdk.Player)1 WhiteSdk (com.herewhite.sdk.WhiteSdk)1 WhiteSdkConfiguration (com.herewhite.sdk.WhiteSdkConfiguration)1 NativePlayer (com.herewhite.sdk.combinePlayer.NativePlayer)1 PlayerSyncManager (com.herewhite.sdk.combinePlayer.PlayerSyncManager)1 PlayerConfiguration (com.herewhite.sdk.domain.PlayerConfiguration)1 SDKError (com.herewhite.sdk.domain.SDKError)1 UrlInterrupter (com.herewhite.sdk.domain.UrlInterrupter)1