如何在Android中定位更改时继续rtsp视频播放

时间:2012-07-25 09:24:17

标签: android

  

可能重复:
  How to continue video play while orientation change in android

我只是在Android默认播放器上播放rtsp视频.Halfly,当我将方向更改为横向时,它从头开始流式传输。如何继续播放。我在清单文件上给了androidconfig =“orientation”。但是仍然是相同的。我还需要做什么呢?

我的代码:

private String vSource =“http://commonsware.com/misc/test2.3gp”;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    // sets the Bundle
    super.onCreate(savedInstanceState);
    // sets the context
    setContentView(R.layout.main);
    myVideoView= (VideoView)findViewById(R.id.vview);
       myVideoView.setVideoURI(Uri.parse(vSource));
       myVideoView.setMediaController(new MediaController(this));
       myVideoView.requestFocus();
       myVideoView.start();


}

public void onSaveInstanceState(Bundle outState){

    mStartTime = myVideoView.getCurrentPosition();
    outState.putInt("restartTime", mStartTime);
    super.onSaveInstanceState(outState);
}
 @Override
    public void onRestoreInstanceState(Bundle savedInstanceState) {
      super.onRestoreInstanceState(savedInstanceState);
      myInt  = savedInstanceState.getInt("restartTime");

 }

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);


      myVideoView.seekTo(myInt);

      myVideoView.start();


}

感谢。

1 个答案:

答案 0 :(得分:1)

您可以将视频的实际进度存储在onSaveInstanceState中(在活动被销毁时调用,例如屏幕旋转时),然后在onRestoreInstanceState中恢复。