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 | 81 | mVideoView.setAVOptions(options); |
| 82 | 82 | |
| 83 | 83 | // Set some listeners |
| 84 | + mVideoView.setOnPreparedListener(onPreparedListener); | |
| 84 | 85 | mVideoView.setOnInfoListener(mOnInfoListener); |
| 85 | 86 | mVideoView.setOnVideoSizeChangedListener(mOnVideoSizeChangedListener); |
| 86 | 87 | mVideoView.setOnBufferingUpdateListener(mOnBufferingUpdateListener); |
| 87 | 88 | mVideoView.setOnCompletionListener(mOnCompletionListener); |
| 88 | 89 | mVideoView.setOnSeekCompleteListener(mOnSeekCompleteListener); |
| 89 | 90 | mVideoView.setOnErrorListener(mOnErrorListener); |
| 90 | - mVideoView.setOnPreparedListener(onPreparedListener); | |
| 91 | 91 | VideoStatusUtil.setOnVideoPlayStatusCallback(mOnVideoStatusCallback); |
| 92 | 92 | |
| 93 | 93 | //播放普通视频 |
| ... | ... | @@ -120,7 +120,8 @@ public class VideoStatusActivity extends VideoPlayerBaseActivity implements View |
| 120 | 120 | super.onPause(); |
| 121 | 121 | mToast = null; |
| 122 | 122 | mIsActivityPaused = true; |
| 123 | - setPlayState(false); | |
| 123 | + if (mVideoView != null && mVideoView.isPlaying()) | |
| 124 | + setPlayState(false); | |
| 124 | 125 | } |
| 125 | 126 | |
| 126 | 127 | @Override |
| ... | ... | @@ -179,7 +180,7 @@ public class VideoStatusActivity extends VideoPlayerBaseActivity implements View |
| 179 | 180 | Log.e(TAG, "Error happened, errorCode = " + errorCode); |
| 180 | 181 | // Return true means the error has been handled |
| 181 | 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 | 188 | @Override |
| 188 | 189 | public void onCompletion(IMediaPlayer plMediaPlayer) { |
| 189 | 190 | Log.d(TAG, "Play Completed !"); |
| 190 | - isPlay = false; | |
| 191 | 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 | 284 | |
| 283 | 285 | @Override |
| 284 | 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 | } | ... | ... |