-2

可能重复:
如何在 android 中更改方向时继续视频播放

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

我的代码:

私有字符串 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();


}

谢谢。

4

1 回答 1

1

您可以将视频的实际进度存储在onSaveInstanceState(在活动被破坏时调用,例如屏幕旋转时),然后将其恢复为onRestoreInstanceState.

于 2012-07-25T09:33:20.930 回答