Commit 61819e8a2e42e85a9af0097e3d6204caa74cc584
1 parent
1c1ed9c4
完善播放获取主播状态demo
Showing
1 changed file
with
15 additions
and
8 deletions
app/src/main/java/com/cnlive/demo/videoqn/VideoStatusActivity.java
| @@ -81,13 +81,13 @@ public class VideoStatusActivity extends VideoPlayerBaseActivity implements View | @@ -81,13 +81,13 @@ public class VideoStatusActivity extends VideoPlayerBaseActivity implements View | ||
| 81 | mVideoView.setAVOptions(options); | 81 | mVideoView.setAVOptions(options); |
| 82 | 82 | ||
| 83 | // Set some listeners | 83 | // Set some listeners |
| 84 | + mVideoView.setOnPreparedListener(onPreparedListener); | ||
| 84 | mVideoView.setOnInfoListener(mOnInfoListener); | 85 | mVideoView.setOnInfoListener(mOnInfoListener); |
| 85 | mVideoView.setOnVideoSizeChangedListener(mOnVideoSizeChangedListener); | 86 | mVideoView.setOnVideoSizeChangedListener(mOnVideoSizeChangedListener); |
| 86 | mVideoView.setOnBufferingUpdateListener(mOnBufferingUpdateListener); | 87 | mVideoView.setOnBufferingUpdateListener(mOnBufferingUpdateListener); |
| 87 | mVideoView.setOnCompletionListener(mOnCompletionListener); | 88 | mVideoView.setOnCompletionListener(mOnCompletionListener); |
| 88 | mVideoView.setOnSeekCompleteListener(mOnSeekCompleteListener); | 89 | mVideoView.setOnSeekCompleteListener(mOnSeekCompleteListener); |
| 89 | mVideoView.setOnErrorListener(mOnErrorListener); | 90 | mVideoView.setOnErrorListener(mOnErrorListener); |
| 90 | - mVideoView.setOnPreparedListener(onPreparedListener); | ||
| 91 | VideoStatusUtil.setOnVideoPlayStatusCallback(mOnVideoStatusCallback); | 91 | VideoStatusUtil.setOnVideoPlayStatusCallback(mOnVideoStatusCallback); |
| 92 | 92 | ||
| 93 | //播放普通视频 | 93 | //播放普通视频 |
| @@ -120,7 +120,8 @@ public class VideoStatusActivity extends VideoPlayerBaseActivity implements View | @@ -120,7 +120,8 @@ public class VideoStatusActivity extends VideoPlayerBaseActivity implements View | ||
| 120 | super.onPause(); | 120 | super.onPause(); |
| 121 | mToast = null; | 121 | mToast = null; |
| 122 | mIsActivityPaused = true; | 122 | mIsActivityPaused = true; |
| 123 | - setPlayState(false); | 123 | + if (mVideoView != null && mVideoView.isPlaying()) |
| 124 | + setPlayState(false); | ||
| 124 | } | 125 | } |
| 125 | 126 | ||
| 126 | @Override | 127 | @Override |
| @@ -179,7 +180,7 @@ public class VideoStatusActivity extends VideoPlayerBaseActivity implements View | @@ -179,7 +180,7 @@ public class VideoStatusActivity extends VideoPlayerBaseActivity implements View | ||
| 179 | Log.e(TAG, "Error happened, errorCode = " + errorCode); | 180 | Log.e(TAG, "Error happened, errorCode = " + errorCode); |
| 180 | // Return true means the error has been handled | 181 | // Return true means the error has been handled |
| 181 | // If return false, then `onCompletion` will be called | 182 | // If return false, then `onCompletion` will be called |
| 182 | - return true; | 183 | + return false; |
| 183 | } | 184 | } |
| 184 | }; | 185 | }; |
| 185 | 186 | ||
| @@ -187,9 +188,10 @@ public class VideoStatusActivity extends VideoPlayerBaseActivity implements View | @@ -187,9 +188,10 @@ public class VideoStatusActivity extends VideoPlayerBaseActivity implements View | ||
| 187 | @Override | 188 | @Override |
| 188 | public void onCompletion(IMediaPlayer plMediaPlayer) { | 189 | public void onCompletion(IMediaPlayer plMediaPlayer) { |
| 189 | Log.d(TAG, "Play Completed !"); | 190 | Log.d(TAG, "Play Completed !"); |
| 190 | - isPlay = false; | ||
| 191 | showToastTips("Play Completed !"); | 191 | showToastTips("Play Completed !"); |
| 192 | - finish(); | 192 | +// finish(); |
| 193 | + isPlay = false; | ||
| 194 | + | ||
| 193 | } | 195 | } |
| 194 | }; | 196 | }; |
| 195 | 197 | ||
| @@ -282,9 +284,14 @@ public class VideoStatusActivity extends VideoPlayerBaseActivity implements View | @@ -282,9 +284,14 @@ public class VideoStatusActivity extends VideoPlayerBaseActivity implements View | ||
| 282 | 284 | ||
| 283 | @Override | 285 | @Override |
| 284 | public void onClick(View v) { | 286 | public void onClick(View v) { |
| 285 | - if (mVideoView != null) { | ||
| 286 | - isPlay = !isPlay; | ||
| 287 | - setPlayState(isPlay); | 287 | + switch (v.getId()) { |
| 288 | + case R.id.playerPlayPause: | ||
| 289 | + if (mVideoView != null) { | ||
| 290 | + isPlay = !isPlay; | ||
| 291 | + setPlayState(isPlay); | ||
| 292 | + } | ||
| 293 | + break; | ||
| 288 | } | 294 | } |
| 295 | + | ||
| 289 | } | 296 | } |
| 290 | } | 297 | } |