我写了一段代码来播放我网站上的视频。它能够正常工作,但是当我旋转我的手机时,视频会从头开始重新播放。如何解决这个问题?
public class ActivityVideoDetail extends Activity {
private VideoDetail videoDetail;
private TextView txtResult;
// -------------------------
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_activity_video_detail);
if (savedInstanceState != null)
{
}
else {
ini();
}
}
// -------------------------
private void ini() {
videoDetail = (VideoDetail) getIntent().getExtras().getSerializable(VideoDetail.VIDEO_DETAIL);
txtResult = (TextView) findViewById(R.id.txtResult);
txtResult.setText(videoDetail.getVideoTitle());
Uri uri = Uri.parse(videoDetail.getVideoPath());
// Uri uri = Uri.parse("http://daily3gp.com/vids/747.3gp");
VideoView videoView = (VideoView) findViewById(R.id.videoPlayer);
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(videoView);
mediaController.setMediaPlayer(videoView);
videoView.setMediaController(mediaController);
videoView.setVideoURI(uri);
videoView.start();
}
}