Search in sources :

Example 1 with SDKError

use of com.herewhite.sdk.domain.SDKError 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)

Example 2 with SDKError

use of com.herewhite.sdk.domain.SDKError in project whiteboard-android by netless-io.

the class PureReplayActivity method initPlayer.

// endregion
protected void initPlayer(String uuid, String roomToken) {
    WhiteSdk whiteSdk = new WhiteSdk(whiteboardView, PureReplayActivity.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);
    // 如果只想实现部分 PlayerEventListener 可以使用 AbstractPlayerEventListener,替换其中想实现的方法
    whiteSdk.createPlayer(playerConfiguration, this, new Promise<Player>() {

        @Override
        public void then(Player wPlayer) {
            player = wPlayer;
            setupSeekBar();
            wPlayer.seekToScheduleTime(0);
            wPlayer.play();
            mSeekBarUpdateHandler.postDelayed(mUpdateSeekBar, 100);
            enableBtn();
        }

        @Override
        public void catchEx(SDKError t) {
            Log.e(TAG, "create player error" + t.getStackTrace().toString());
            alert("创建回放失败", t.getJsStack());
        }
    });
}
Also used : UrlInterrupter(com.herewhite.sdk.domain.UrlInterrupter) Player(com.herewhite.sdk.Player) PlayerConfiguration(com.herewhite.sdk.domain.PlayerConfiguration) WhiteSdkConfiguration(com.herewhite.sdk.WhiteSdkConfiguration) SDKError(com.herewhite.sdk.domain.SDKError) WhiteSdk(com.herewhite.sdk.WhiteSdk)

Example 3 with SDKError

use of com.herewhite.sdk.domain.SDKError in project whiteboard-android by netless-io.

the class RoomActivity method joinRoom.

// region room
private void joinRoom(String uuid, String token) {
    logRoomInfo("room uuid: " + uuid + "\nroom token: " + token);
    // 存档一下,方便重连
    this.uuid = uuid;
    this.token = token;
    WhiteSdkConfiguration configuration = new WhiteSdkConfiguration(demoAPI.getAppId(), true);
    /*显示用户头像*/
    configuration.setUserCursor(true);
    // 动态 ppt 需要的自定义字体,如果没有使用,无需调用
    configuration.setFonts(new MapBuilder<String, String>().put("宋体", "https://your-cdn.com/Songti.ttf").build());
    mWhiteSdk = new WhiteSdk(mWhiteboardView, this, configuration);
    // 图片替换 API,需要在 whiteSDKConfig 中先行调用 setHasUrlInterrupterAPI,进行设置,否则不会被回调。
    mWhiteSdk.setCommonCallbacks(new CommonCallback() {

        @Override
        public String urlInterrupter(String sourceUrl) {
            return sourceUrl;
        }

        @Override
        public void onMessage(JSONObject message) {
            Log.d(TAG, message.toString());
        }

        @Override
        public void sdkSetupFail(SDKError error) {
            Log.e(TAG, "sdkSetupFail " + error.toString());
        }

        @Override
        public void throwError(Object args) {
            Log.e(TAG, "throwError " + args);
        }

        @Override
        public void onPPTMediaPlay() {
            logAction();
        }

        @Override
        public void onPPTMediaPause() {
            logAction();
        }

        @Override
        public void onLogger(JSONObject object) {
            logAction(object.toString());
        }
    });
    FontFace fontFace = new FontFace("example", "url(https://white-pan.oss-cn-shanghai.aliyuncs.com/Pacifico-Regular.ttf)");
    // mWhiteSdk.setupFontFaces(new FontFace[]{fontFace});
    mWhiteSdk.loadFontFaces(new FontFace[] { fontFace }, new Promise<JSONObject>() {

        @Override
        public void then(JSONObject object) {
            logRoomInfo("loadFontFaces");
        }

        @Override
        public void catchEx(SDKError t) {
        }
    });
    /**
     * 设置自定义全局状态,在后续回调中 GlobalState 直接进行类型转换即可
     */
    WhiteDisplayerState.setCustomGlobalStateClass(MyGlobalState.class);
    // 如需支持用户头像,请在设置 WhiteSdkConfiguration 后,再调用 setUserPayload 方法,传入符合用户信息
    RoomParams roomParams = new RoomParams(uuid, token, DemoAPI.DEFAULT_UID);
    roomParams.setDisableNewPencil(false);
    roomParams.setWritable(true);
    final Date joinDate = new Date();
    logRoomInfo("native join " + joinDate);
    mWhiteSdk.joinRoom(roomParams, new RoomCallbacks() {

        @Override
        public void onCanUndoStepsUpdate(long canUndoSteps) {
            mRoomCallbackHock.onCanUndoStepsUpdate(canUndoSteps);
            logRoomInfo("canUndoSteps: " + canUndoSteps);
        }

        @Override
        public void onCanRedoStepsUpdate(long canRedoSteps) {
            mRoomCallbackHock.onCanRedoStepsUpdate(canRedoSteps);
            logRoomInfo("onCanRedoStepsUpdate: " + canRedoSteps);
        }

        @Override
        public void onCatchErrorWhenAppendFrame(long userId, Exception error) {
            mRoomCallbackHock.onCatchErrorWhenAppendFrame(userId, error);
            logRoomInfo("onCatchErrorWhenAppendFrame: " + userId + " error " + error.getMessage());
        }

        @Override
        public void onPhaseChanged(RoomPhase phase) {
            mRoomCallbackHock.onPhaseChanged(phase);
            // 在此处可以处理断连后的重连逻辑
            logRoomInfo("onPhaseChanged: " + phase.name());
            showToast(phase.name());
        }

        @Override
        public void onDisconnectWithError(Exception e) {
            mRoomCallbackHock.onDisconnectWithError(e);
            logRoomInfo("onDisconnectWithError: " + e.getMessage());
        }

        @Override
        public void onKickedWithReason(String reason) {
            mRoomCallbackHock.onKickedWithReason(reason);
            logRoomInfo("onKickedWithReason: " + reason);
        }

        @Override
        public void onRoomStateChanged(RoomState modifyState) {
            mRoomCallbackHock.onRoomStateChanged(modifyState);
            logRoomInfo("onRoomStateChanged:" + gson.toJson(modifyState));
        }
    }, new Promise<Room>() {

        @Override
        public void then(Room room) {
            // 记录加入房间消耗的时长
            logRoomInfo("native join in room duration: " + (System.currentTimeMillis() - joinDate.getTime()) / 1000f + "s");
            mRoom = room;
            addCustomEventListener();
            testMarkIdling(true);
        }

        @Override
        public void catchEx(SDKError t) {
            logRoomInfo("native join fail: " + t.getMessage());
            showToast(t.getMessage());
        }
    });
}
Also used : CommonCallback(com.herewhite.sdk.CommonCallback) WhiteSdkConfiguration(com.herewhite.sdk.WhiteSdkConfiguration) SDKError(com.herewhite.sdk.domain.SDKError) RoomParams(com.herewhite.sdk.RoomParams) Date(java.util.Date) ConvertException(com.herewhite.sdk.domain.ConvertException) FontFace(com.herewhite.sdk.domain.FontFace) JSONObject(org.json.JSONObject) AbstractRoomCallbacks(com.herewhite.sdk.AbstractRoomCallbacks) RoomCallbacks(com.herewhite.sdk.RoomCallbacks) JSONObject(org.json.JSONObject) RoomPhase(com.herewhite.sdk.domain.RoomPhase) WhiteSdk(com.herewhite.sdk.WhiteSdk) Room(com.herewhite.sdk.Room) RoomState(com.herewhite.sdk.domain.RoomState)

Example 4 with SDKError

use of com.herewhite.sdk.domain.SDKError in project whiteboard-android by netless-io.

the class RoomActivity method nextScene.

public void nextScene(MenuItem item) {
    int nextIndex = mRoom.getSceneState().getIndex() + 1;
    mRoom.setSceneIndex(nextIndex, new Promise<Boolean>() {

        @Override
        public void then(Boolean result) {
        }

        @Override
        public void catchEx(SDKError t) {
        }
    });
}
Also used : SDKError(com.herewhite.sdk.domain.SDKError) Point(com.herewhite.sdk.domain.Point) SuppressLint(android.annotation.SuppressLint)

Example 5 with SDKError

use of com.herewhite.sdk.domain.SDKError in project whiteboard-android by netless-io.

the class ScenesActivity method onClick.

// sample of scenes apis
@Override
public void onClick(View v) {
    switch(v.getId()) {
        case R.id.putScenes:
            // create slides on scenes
            // it should run only once
            mRoom.putScenes(SCENE_DIR, scenes, 0);
            mRoom.setScenePath(SCENE_DIR);
            break;
        case R.id.setScenePath:
            mRoom.setScenePath(SCENE_DIR + "/" + scenes[1].getName());
            break;
        case R.id.setSceneIndex:
            // switch scene by index
            mRoom.setSceneIndex(2, new Promise<Boolean>() {

                @Override
                public void then(Boolean aBoolean) {
                }

                @Override
                public void catchEx(SDKError t) {
                }
            });
            break;
        case R.id.getRoomState:
            // sync SceneState
            SceneState sceneState = mRoom.getSceneState();
            logRoomInfo("current sceneState " + sceneState.toString());
            // get sceneState by async
            mRoom.getSceneState(new Promise<SceneState>() {

                @Override
                public void then(SceneState sceneState) {
                    logRoomInfo("current sceneState " + sceneState.toString());
                }

                @Override
                public void catchEx(SDKError t) {
                }
            });
            break;
    }
}
Also used : SDKError(com.herewhite.sdk.domain.SDKError) SceneState(com.herewhite.sdk.domain.SceneState)

Aggregations

SDKError (com.herewhite.sdk.domain.SDKError)38 JSONObject (org.json.JSONObject)18 JsonSyntaxException (com.google.gson.JsonSyntaxException)13 WhiteSdk (com.herewhite.sdk.WhiteSdk)12 WhiteSdkConfiguration (com.herewhite.sdk.WhiteSdkConfiguration)12 JsonObject (com.google.gson.JsonObject)10 Room (com.herewhite.sdk.Room)10 RoomParams (com.herewhite.sdk.RoomParams)10 RoomPhase (com.herewhite.sdk.domain.RoomPhase)7 RoomState (com.herewhite.sdk.domain.RoomState)7 AbstractRoomCallbacks (com.herewhite.sdk.AbstractRoomCallbacks)5 CommonCallback (com.herewhite.sdk.CommonCallback)5 Test (org.junit.Test)5 RoomCallbacks (com.herewhite.sdk.RoomCallbacks)4 View (android.view.View)3 ConvertException (com.herewhite.sdk.domain.ConvertException)3 FontFace (com.herewhite.sdk.domain.FontFace)3 Scene (com.herewhite.sdk.domain.Scene)3 SceneState (com.herewhite.sdk.domain.SceneState)3 WindowParams (com.herewhite.sdk.domain.WindowParams)3