只需要重新onSaveInstanceState方法,在其里面记住我们要记录的参数
package com.bawei.day07_videoview; import android.os.Bundle; import android.os.Environment; import android.app.Activity; import android.view.Menu; import android.view.View; import android.widget.MediaController; import android.widget.TextView; import android.widget.VideoView; public class MainActivity extends Activity { private VideoView videoView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); videoView = (VideoView) findViewById(R.id.video); // 得到SD卡路径 String path = Environment.getExternalStorageDirectory().getPath(); videoView.setVideoPath(path + "/xiao.3gp"); // 播放器 MediaController controller = new MediaController(MainActivity.this); videoView.setMediaController(controller); controller.setMediaPlayer(videoView); videoView.start(); // 当横屏时接着播放 if (savedInstanceState != null) { // 得到进度 int ss = savedInstanceState.getInt("aa"); // 接着播放 videoView.seekTo(ss); } } @Override protected void onSaveInstanceState(Bundle outState) { // TODO Auto-generated method stub super.onSaveInstanceState(outState); // 记录当前播放进度 outState.putInt("aa", videoView.getCurrentPosition()); } }
时间: 2024-10-31 03:45:02