對於自定義視頻,我必須重寫MediaController(更改按鈕的設計並連接到按鈕暫停/播放選擇器)。情況是這樣的:將視頻暫停並轉動應用程序,然後再次恢復,視頻開始再次播放,而不是從暫停的位置開始播放,因此問題出現了:如何使視頻開始播放從哪裏停下來? VideoActivity中需要更改哪些內容?從VideoView中的暫停狀態播放視頻
public class VideoActivity extends Activity {
VideoView videoView;
VkMediaController mc;
private static final String CURRENT = "duration";
private static final String URL = "url";
private Uri mURI;
private int mCurrentPosition = -1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.video_view_player);
videoView = (VideoView) findViewById(R.id.videoViewplayer);
mc = new VkMediaController(this);
mURI = getIntent().getData();
if (savedInstanceState != null) {
mURI = Uri.parse(savedInstanceState.getString(URL));
mCurrentPosition = savedInstanceState.getInt(CURRENT);
}
videoView.setMediaController(mc);
videoView.setVideoURI(mURI);
videoView.requestFocus();
}
@Override
protected void onStart() {
super.onStart();
videoView.start();
if (mCurrentPosition != -1) {
videoView.seekTo(mCurrentPosition);
}
}
@Override
public void onSaveInstanceState(Bundle outState) {
outState.putInt(CURRENT, videoView.getCurrentPosition());
outState.putString(URL, mURI.toString());
super.onSaveInstanceState(outState);
}
}
什麼是錯誤/問題?這段代碼有什麼錯誤? – njzk2
沒有錯誤,但沒有從當前位置開始播放,並且從 – ricky
開始您是否檢查了mCurrentPosition的值? – njzk2