|
@@ -38,15 +38,12 @@ public class SuperPlayerImpl implements SuperPlayer, ITXVodPlayListener, ITXLive
|
|
|
private TXVodPlayer mVodPlayer; // 点播播放器
|
|
|
private TXVodPlayConfig mVodPlayConfig; // 点播播放器配置
|
|
|
|
|
|
- private TXLivePlayer mLivePlayer; // 直播播放器
|
|
|
- private TXLivePlayConfig mLivePlayConfig; // 直播播放器配置
|
|
|
-
|
|
|
private ISuperPlayerListener mSuperPlayerListener;
|
|
|
private SuperPlayerModel mCurrentModel; // 当前播放的model
|
|
|
private SuperPlayerObserver mObserver;
|
|
|
- private SuperPlayerDef.PlayerType mCurrentPlayType = SuperPlayerDef.PlayerType.VOD; // 当前播放类型
|
|
|
private SuperPlayerDef.PlayerMode mCurrentPlayMode = SuperPlayerDef.PlayerMode.WINDOW; // 当前播放模式
|
|
|
- private SuperPlayerDef.PlayerState mCurrentPlayState = SuperPlayerDef.PlayerState.INIT; // 当前播放状态
|
|
|
+ private SuperPlayerDef.PlayerState mCurrentPlayState = SuperPlayerDef.PlayerState.INIT;
|
|
|
+
|
|
|
private String mCurrentPlayVideoURL; // 当前播放的URL
|
|
|
private int mSeekPos; // 记录切换硬解时的播放时间
|
|
|
private float mStartPos; // 视频开始播放时间
|
|
@@ -84,19 +81,12 @@ public class SuperPlayerImpl implements SuperPlayer, ITXVodPlayListener, ITXLive
|
|
|
break;
|
|
|
case TXLiveConstants.PLAY_ERR_NET_DISCONNECT:
|
|
|
case TXLiveConstants.PLAY_EVT_PLAY_END:
|
|
|
- if (mCurrentPlayType == SuperPlayerDef.PlayerType.LIVE_SHIFT) { // 直播时移失败,返回直播
|
|
|
- mLivePlayer.resumeLive();
|
|
|
- updatePlayerType(SuperPlayerDef.PlayerType.LIVE);
|
|
|
- onError(SuperPlayerCode.LIVE_SHIFT_FAIL, "时移失败,返回直播");
|
|
|
- updatePlayerState(SuperPlayerDef.PlayerState.PLAYING);
|
|
|
+ stop();
|
|
|
+ updatePlayerState(SuperPlayerDef.PlayerState.END);
|
|
|
+ if (event == TXLiveConstants.PLAY_ERR_NET_DISCONNECT) {
|
|
|
+ onError(SuperPlayerCode.NET_ERROR, "网络不给力,点击重试");
|
|
|
} else {
|
|
|
- stop();
|
|
|
- updatePlayerState(SuperPlayerDef.PlayerState.END);
|
|
|
- if (event == TXLiveConstants.PLAY_ERR_NET_DISCONNECT) {
|
|
|
- onError(SuperPlayerCode.NET_ERROR, "网络不给力,点击重试");
|
|
|
- } else {
|
|
|
- onError(SuperPlayerCode.LIVE_PLAY_END, param.getString(TXLiveConstants.EVT_DESCRIPTION));
|
|
|
- }
|
|
|
+ onError(SuperPlayerCode.LIVE_PLAY_END, param.getString(TXLiveConstants.EVT_DESCRIPTION));
|
|
|
}
|
|
|
break;
|
|
|
case TXLiveConstants.PLAY_EVT_PLAY_LOADING:
|
|
@@ -233,7 +223,7 @@ public class SuperPlayerImpl implements SuperPlayer, ITXVodPlayListener, ITXLive
|
|
|
private void initialize(Context context, TXCloudVideoView videoView) {
|
|
|
mContext = context;
|
|
|
mVideoView = videoView;
|
|
|
- initLivePlayer(mContext);
|
|
|
+
|
|
|
initVodPlayer(mContext);
|
|
|
}
|
|
|
|
|
@@ -263,24 +253,6 @@ public class SuperPlayerImpl implements SuperPlayer, ITXVodPlayListener, ITXLive
|
|
|
mVodPlayer.setMirror(config.mirror);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 初始化直播播放器
|
|
|
- *
|
|
|
- * @param context
|
|
|
- */
|
|
|
- private void initLivePlayer(Context context) {
|
|
|
- mLivePlayer = new TXLivePlayer(context);
|
|
|
- SuperPlayerGlobalConfig config = SuperPlayerGlobalConfig.getInstance();
|
|
|
- mLivePlayConfig = new TXLivePlayConfig();
|
|
|
- mLivePlayConfig.setHeaders(config.headers);
|
|
|
- mLivePlayer.setConfig(mLivePlayConfig);
|
|
|
- mLivePlayer.setRenderMode(config.renderMode);
|
|
|
- mLivePlayer.setRenderRotation(TXLiveConstants.RENDER_ROTATION_PORTRAIT);
|
|
|
- mLivePlayer.setPlayListener(this);
|
|
|
- mLivePlayer.enableHardwareDecode(config.enableHWAcceleration);
|
|
|
- mLivePlayer.setMute(config.mute);
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 播放视频
|
|
|
*
|
|
@@ -300,17 +272,12 @@ public class SuperPlayerImpl implements SuperPlayer, ITXVodPlayListener, ITXLive
|
|
|
onError(SuperPlayerCode.PLAY_URL_EMPTY, "播放视频失败,播放链接为空");
|
|
|
return;
|
|
|
}
|
|
|
- if (isRTMPPlay(videoURL)) { // 直播播放器:普通RTMP流播放
|
|
|
- mReportLiveStartTime = System.currentTimeMillis();
|
|
|
- mLivePlayer.setPlayerView(mVideoView);
|
|
|
- playLiveURL(videoURL, TXLivePlayer.PLAY_TYPE_LIVE_RTMP);
|
|
|
- } else { // 点播播放器:播放点播文件
|
|
|
- mReportVodStartTime = System.currentTimeMillis();
|
|
|
- mVodPlayer.setPlayerView(mVideoView);
|
|
|
- playVodURL(videoURL);
|
|
|
- }
|
|
|
- boolean isLivePlay = (isRTMPPlay(videoURL) || isFLVPlay(videoURL));
|
|
|
- updatePlayerType(isLivePlay ? SuperPlayerDef.PlayerType.LIVE : SuperPlayerDef.PlayerType.VOD);
|
|
|
+
|
|
|
+ // 点播播放器:播放点播文件
|
|
|
+ mReportVodStartTime = System.currentTimeMillis();
|
|
|
+ mVodPlayer.setPlayerView(mVideoView);
|
|
|
+ playVodURL(videoURL);
|
|
|
+
|
|
|
updatePlayProgress(0, model.duration);
|
|
|
}
|
|
|
|
|
@@ -325,23 +292,6 @@ public class SuperPlayerImpl implements SuperPlayer, ITXVodPlayListener, ITXLive
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 播放直播URL
|
|
|
- */
|
|
|
- private void playLiveURL(String url, int playType) {
|
|
|
- mCurrentPlayVideoURL = url;
|
|
|
- if (mLivePlayer != null) {
|
|
|
- mLivePlayer.setPlayListener(this);
|
|
|
- mLivePlayer.setPlayerView(mVideoView);
|
|
|
- int result = mLivePlayer.startPlay(url, playType); // result返回值:0 success; -1 empty url; -2 invalid url; -3 invalid playType;
|
|
|
- if (result != 0) {
|
|
|
- Log.e(TAG, "playLiveURL videoURL:" + url + ",result:" + result);
|
|
|
- } else {
|
|
|
- updatePlayerState(SuperPlayerDef.PlayerState.PLAYING);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 播放点播url
|
|
|
*/
|
|
@@ -386,18 +336,6 @@ public class SuperPlayerImpl implements SuperPlayer, ITXVodPlayListener, ITXLive
|
|
|
return majorVer > SUPPORT_MAJOR_VERSION || (majorVer == SUPPORT_MAJOR_VERSION && minorVer >= SUPPORT_MINOR_VERSION);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 配置多码流url
|
|
|
- *
|
|
|
- * @param url
|
|
|
- */
|
|
|
- private void startMultiStreamLiveURL(String url) {
|
|
|
- mLivePlayConfig.setAutoAdjustCacheTime(false);
|
|
|
- mLivePlayConfig.setMaxAutoAdjustCacheTime(5);
|
|
|
- mLivePlayConfig.setMinAutoAdjustCacheTime(5);
|
|
|
- mLivePlayer.setConfig(mLivePlayConfig);
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 上报播放时长
|
|
|
*/
|
|
@@ -426,17 +364,6 @@ public class SuperPlayerImpl implements SuperPlayer, ITXVodPlayListener, ITXLive
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 更新播放类型
|
|
|
- *
|
|
|
- * @param playType
|
|
|
- */
|
|
|
- private void updatePlayerType(SuperPlayerDef.PlayerType playType) {
|
|
|
- if (playType != mCurrentPlayType) {
|
|
|
- mCurrentPlayType = playType;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 更新播放状态
|
|
|
*
|
|
@@ -510,56 +437,33 @@ public class SuperPlayerImpl implements SuperPlayer, ITXVodPlayListener, ITXLive
|
|
|
|
|
|
@Override
|
|
|
public void restart() {
|
|
|
- if (mCurrentPlayType == SuperPlayerDef.PlayerType.LIVE || mCurrentPlayType == SuperPlayerDef.PlayerType.LIVE_SHIFT) {
|
|
|
- if (isRTMPPlay(mCurrentPlayVideoURL)) {
|
|
|
- playLiveURL(mCurrentPlayVideoURL, TXLivePlayer.PLAY_TYPE_LIVE_RTMP);
|
|
|
- }
|
|
|
+ if (mCurrentPlayVideoURL != null) {
|
|
|
+ playVodURL(mCurrentPlayVideoURL);
|
|
|
} else {
|
|
|
- if (mCurrentPlayVideoURL != null) {
|
|
|
- playVodURL(mCurrentPlayVideoURL);
|
|
|
- } else {
|
|
|
- playWithModel(mCurrentModel);
|
|
|
- }
|
|
|
+ playWithModel(mCurrentModel);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void pause() {
|
|
|
- if (mCurrentPlayType == SuperPlayerDef.PlayerType.VOD) {
|
|
|
- mVodPlayer.pause();
|
|
|
- } else {
|
|
|
- mLivePlayer.pause();
|
|
|
- }
|
|
|
+ mVodPlayer.pause();
|
|
|
updatePlayerState(SuperPlayerDef.PlayerState.PAUSE);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void pauseVod() {
|
|
|
- if (mCurrentPlayType == SuperPlayerDef.PlayerType.VOD) {
|
|
|
- mVodPlayer.pause();
|
|
|
- }
|
|
|
+ mVodPlayer.pause();
|
|
|
updatePlayerState(SuperPlayerDef.PlayerState.PAUSE);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void resume() {
|
|
|
- if (mCurrentPlayType == SuperPlayerDef.PlayerType.VOD) {
|
|
|
- isNeedResume = true;
|
|
|
- if (isPrepared) {
|
|
|
- mVodPlayer.resume();
|
|
|
- }
|
|
|
- } else {
|
|
|
- mLivePlayer.resume();
|
|
|
+ isNeedResume = true;
|
|
|
+ if (isPrepared) {
|
|
|
+ mVodPlayer.resume();
|
|
|
}
|
|
|
- updatePlayerState(SuperPlayerDef.PlayerState.PLAYING);
|
|
|
- }
|
|
|
|
|
|
- @Override
|
|
|
- public void resumeLive() {
|
|
|
- if (mCurrentPlayType == SuperPlayerDef.PlayerType.LIVE_SHIFT) {
|
|
|
- mLivePlayer.resumeLive();
|
|
|
- }
|
|
|
- updatePlayerType(SuperPlayerDef.PlayerType.LIVE);
|
|
|
+ updatePlayerState(SuperPlayerDef.PlayerState.PLAYING);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -581,11 +485,6 @@ public class SuperPlayerImpl implements SuperPlayer, ITXVodPlayListener, ITXLive
|
|
|
mVodPlayer.setVodListener(null);
|
|
|
mVodPlayer.stopPlay(false);
|
|
|
}
|
|
|
- if (mLivePlayer != null) {
|
|
|
- mLivePlayer.setPlayListener(null);
|
|
|
- mLivePlayer.stopPlay(false);
|
|
|
- mVideoView.removeVideoView();
|
|
|
- }
|
|
|
reportPlayTime();
|
|
|
}
|
|
|
|
|
@@ -604,75 +503,40 @@ public class SuperPlayerImpl implements SuperPlayer, ITXVodPlayListener, ITXLive
|
|
|
|
|
|
@Override
|
|
|
public void enableHardwareDecode(boolean enable) {
|
|
|
- if (mCurrentPlayType == SuperPlayerDef.PlayerType.VOD) {
|
|
|
- mVodPlayer.enableHardwareDecode(enable);
|
|
|
- if (mCurrentPlayState != SuperPlayerDef.PlayerState.END) {
|
|
|
- mChangeHWAcceleration = true;
|
|
|
- mSeekPos = (int) mVodPlayer.getCurrentPlaybackTime();
|
|
|
- Log.i(TAG, "save pos:" + mSeekPos);
|
|
|
- resetPlayer();
|
|
|
- playModeVideo(mCurrentModel);
|
|
|
- }
|
|
|
- } else {
|
|
|
- mLivePlayer.enableHardwareDecode(enable);
|
|
|
- playWithModel(mCurrentModel);
|
|
|
+ mVodPlayer.enableHardwareDecode(enable);
|
|
|
+ if (mCurrentPlayState != SuperPlayerDef.PlayerState.END) {
|
|
|
+ mChangeHWAcceleration = true;
|
|
|
+ mSeekPos = (int) mVodPlayer.getCurrentPlaybackTime();
|
|
|
+ Log.i(TAG, "save pos:" + mSeekPos);
|
|
|
+ resetPlayer();
|
|
|
+ playModeVideo(mCurrentModel);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void setPlayerView(TXCloudVideoView videoView) {
|
|
|
mVideoView = videoView;
|
|
|
- if (mCurrentPlayType == SuperPlayerDef.PlayerType.VOD) {
|
|
|
- mVodPlayer.setPlayerView(videoView);
|
|
|
- } else {
|
|
|
- mLivePlayer.setPlayerView(videoView);
|
|
|
- }
|
|
|
+ mVodPlayer.setPlayerView(videoView);
|
|
|
+
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void seek(int position) {
|
|
|
- if (mCurrentPlayType == SuperPlayerDef.PlayerType.VOD) {
|
|
|
- if (mVodPlayer != null) {
|
|
|
- mVodPlayer.seek(position);
|
|
|
- if (!mVodPlayer.isPlaying()) {
|
|
|
- mVodPlayer.resume();
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- updatePlayerType(SuperPlayerDef.PlayerType.LIVE_SHIFT);
|
|
|
- if (mLivePlayer != null) {
|
|
|
- mLivePlayer.seek(position);
|
|
|
+ if (mVodPlayer != null) {
|
|
|
+ mVodPlayer.seek(position);
|
|
|
+ if (!mVodPlayer.isPlaying()) {
|
|
|
+ mVodPlayer.resume();
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
if (mObserver != null) {
|
|
|
mObserver.onSeek(position);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public void snapshot(TXLivePlayer.ITXSnapshotListener listener) {
|
|
|
- if (mCurrentPlayType == SuperPlayerDef.PlayerType.VOD) {
|
|
|
- mVodPlayer.snapshot(listener);
|
|
|
- } else if (mCurrentPlayType == SuperPlayerDef.PlayerType.LIVE) {
|
|
|
- mLivePlayer.snapshot(listener);
|
|
|
- } else {
|
|
|
- listener.onSnapshot(null);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
@Override
|
|
|
public void setRate(float speedLevel) {
|
|
|
- if (mCurrentPlayType == SuperPlayerDef.PlayerType.VOD) {
|
|
|
- mVodPlayer.setRate(speedLevel);
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void setMirror(boolean isMirror) {
|
|
|
- if (mCurrentPlayType == SuperPlayerDef.PlayerType.VOD) {
|
|
|
- mVodPlayer.setMirror(isMirror);
|
|
|
- }
|
|
|
+ mVodPlayer.setRate(speedLevel);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -690,11 +554,6 @@ public class SuperPlayerImpl implements SuperPlayer, ITXVodPlayListener, ITXLive
|
|
|
return mCurrentPlayState;
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public SuperPlayerDef.PlayerType getPlayerType() {
|
|
|
- return mCurrentPlayType;
|
|
|
- }
|
|
|
-
|
|
|
@Override
|
|
|
public void setObserver(SuperPlayerObserver observer) {
|
|
|
mObserver = observer;
|