Commit a77d871434be71b44b6e20c27916936aded76550
1 parent
902b0957
修改播放状态判断逻辑
Showing
1 changed file
with
31 additions
and
22 deletions
app/src/main/java/com/cnlive/demo/video/VideoStatusActivity.java
| ... | ... | @@ -31,11 +31,13 @@ public class VideoStatusActivity extends Activity implements View.OnClickListene |
| 31 | 31 | private boolean isPlay = false; |
| 32 | 32 | //记录当前视频是否能播 |
| 33 | 33 | private boolean canPlay = true; |
| 34 | + //记录当前视频状态是否结束,结束后就不再播 | |
| 35 | + protected boolean isStatusEnd = false; | |
| 34 | 36 | |
| 35 | 37 | @Override |
| 36 | 38 | protected void onCreate(Bundle savedInstanceState) { |
| 37 | 39 | super.onCreate(savedInstanceState); |
| 38 | - setContentView(R.layout.activity_videoview_status); | |
| 40 | + setContentView(com.cnlive.libs.R.layout.activity_videoview_status); | |
| 39 | 41 | |
| 40 | 42 | initView(); |
| 41 | 43 | } |
| ... | ... | @@ -110,27 +112,34 @@ public class VideoStatusActivity extends Activity implements View.OnClickListene |
| 110 | 112 | switch (status) { |
| 111 | 113 | case IVideoStatus.MEDIA_STATUS_LIVING: |
| 112 | 114 | //直播中' |
| 113 | - canPlay = true; | |
| 114 | - if (videoView != null && !videoView.getPlayState()) | |
| 115 | - videoView.reload(); | |
| 116 | - setStatusViewVisible(false, ""); | |
| 117 | - Toast.makeText(VideoStatusActivity.this, "直播中", Toast.LENGTH_LONG).show(); | |
| 115 | + if (!isStatusEnd) { | |
| 116 | + canPlay = true; | |
| 117 | + isPlay = true; | |
| 118 | + setPlayState(true); | |
| 119 | + setStatusViewVisible(false, ""); | |
| 120 | + Toast.makeText(VideoStatusActivity.this, "直播中", Toast.LENGTH_LONG).show(); | |
| 121 | + } | |
| 118 | 122 | break; |
| 119 | 123 | case IVideoStatus.MEDIA_STATUS_LEAVE: |
| 120 | 124 | //主播暂时离开 |
| 121 | - canPlay = false; | |
| 122 | - if (videoView != null) | |
| 123 | - videoView.stop(); | |
| 124 | - setStatusViewVisible(true, "主播暂时离开"); | |
| 125 | - Toast.makeText(VideoStatusActivity.this, "主播暂时离开", Toast.LENGTH_LONG).show(); | |
| 125 | + if (!isStatusEnd) { | |
| 126 | + canPlay = false; | |
| 127 | + isPlay = false; | |
| 128 | + setPlayState(false); | |
| 129 | + setStatusViewVisible(true, "主播暂时离开"); | |
| 130 | + Toast.makeText(VideoStatusActivity.this, "主播暂时离开", Toast.LENGTH_LONG).show(); | |
| 131 | + } | |
| 126 | 132 | break; |
| 127 | 133 | case IVideoStatus.MEDIA_STATUS_END: |
| 128 | 134 | //直播结束 |
| 129 | - canPlay = false; | |
| 130 | - if (videoView != null) | |
| 131 | - videoView.stop(); | |
| 132 | - setStatusViewVisible(true, "直播已经结束"); | |
| 133 | - Toast.makeText(VideoStatusActivity.this, "直播结束", Toast.LENGTH_LONG).show(); | |
| 135 | + if (!isStatusEnd) { | |
| 136 | + canPlay = false; | |
| 137 | + isPlay = false; | |
| 138 | + isStatusEnd = true; | |
| 139 | + videoView.release(); | |
| 140 | + setStatusViewVisible(true, "直播已经结束"); | |
| 141 | + Toast.makeText(VideoStatusActivity.this, "直播结束", Toast.LENGTH_LONG).show(); | |
| 142 | + } | |
| 134 | 143 | break; |
| 135 | 144 | } |
| 136 | 145 | |
| ... | ... | @@ -139,7 +148,7 @@ public class VideoStatusActivity extends Activity implements View.OnClickListene |
| 139 | 148 | @Override |
| 140 | 149 | public void onError(int what, String extra) { |
| 141 | 150 | Log.e(TAG, "onError: " + what + "_" + extra); |
| 142 | - Toast.makeText(VideoStatusActivity.this,"onError: " + what + "_" + extra,Toast.LENGTH_LONG).show(); | |
| 151 | + Toast.makeText(VideoStatusActivity.this, "onError: " + what + "_" + extra, Toast.LENGTH_LONG).show(); | |
| 143 | 152 | } |
| 144 | 153 | }; |
| 145 | 154 | |
| ... | ... | @@ -172,13 +181,13 @@ public class VideoStatusActivity extends Activity implements View.OnClickListene |
| 172 | 181 | } |
| 173 | 182 | |
| 174 | 183 | private void initView() { |
| 175 | - playBtn = (Button) findViewById(R.id.playerPlayPause); | |
| 184 | + playBtn = (Button) findViewById(com.cnlive.libs.R.id.playerPlayPause); | |
| 176 | 185 | playBtn.setOnClickListener(this); |
| 177 | 186 | |
| 178 | - statusView = findViewById(R.id.statusView); | |
| 179 | - statusViewText = (TextView) findViewById(R.id.statusViewText); | |
| 187 | + statusView = findViewById(com.cnlive.libs.R.id.statusView); | |
| 188 | + statusViewText = (TextView) findViewById(com.cnlive.libs.R.id.statusViewText); | |
| 180 | 189 | |
| 181 | - videoView = (VideoView) findViewById(R.id.videoview); | |
| 190 | + videoView = (VideoView) findViewById(com.cnlive.libs.R.id.videoview); | |
| 182 | 191 | videoView.setOnBufferingUpdateListener(mOnBufferingUpdateListener); |
| 183 | 192 | videoView.setOnCompletionListener(mOnCompletionListener); |
| 184 | 193 | videoView.setOnPreparedListener(mOnPrepareListener); |
| ... | ... | @@ -223,7 +232,7 @@ public class VideoStatusActivity extends Activity implements View.OnClickListene |
| 223 | 232 | @Override |
| 224 | 233 | public void onClick(View v) { |
| 225 | 234 | switch (v.getId()) { |
| 226 | - case R.id.playerPlayPause: | |
| 235 | + case com.cnlive.libs.R.id.playerPlayPause: | |
| 227 | 236 | if (videoView != null) { |
| 228 | 237 | isPlay = !isPlay; |
| 229 | 238 | setPlayState(isPlay); | ... | ... |