1

I want that when I turn the phone and change the screen orientation, the video continue playing where it was playing and no start again. I have tried change the Manifest:

android:configChanges="keyboardHidden|orientation"

and change in my activity

public void onConfigurationChanged(Configuration newConfig)
    {
        super.onConfigurationChanged(newConfig);
        setContentView(R.layout.main);
        InitializeUI();
    }

does not work and start the video again when I change the orientation. Can anyone help me, please?


Thank you very much for the help, but I think that I have not explained well, my English is not very good.
In the application I'm developing, I have a video that plays automatically when I turn the phone, the video starts again. I need, continues the video where he was playing. This problem is similar to this one. I have tried to modify the code as explained here, but I have not worked. I've also been looking at the links you gave me you, but neither works. Is there a method, changing classes to solve the problem?. Thank you very much.

Community
  • 1
  • 1
lûr
  • 191
  • 12
  • your InitializeUI() method is probably starting the video. You'd have to not call this from onConfigureChanged to get it to keep playing instead of restarting. – FoamyGuy Oct 18 '11 at 16:21
  • I tried to change and is still happening. I leave my new code. thanks.[code]@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); myvideo = (VideoView) findViewById(R.id.video); final MediaController mediaController = new MediaController(this); String uri = "android.resource://" + getPackageName() + "/" + R.raw.video; myvideo.setVideoPath(uri); myvideo.requestFocus(); myvideo.start(); myvideo.setMediaController(mediaController); mediaController.setAnchorView(myvideo); mediaController.show(); – lûr Oct 19 '11 at 12:48

1 Answers1

0

I solved the problem with the next code:

private int timevideo;
//Oncreate()
    Bundle returnData = (Bundle) getLastNonConfigurationInstance();
        if (returnData == null) {
            String uri = "android.resource://" + getPackageName() + "/"
                    + R.raw.videoname;
            myvideo.setVideoPath(uri);
            myvideo.requestFocus();
            myvideo.start();
        } else {
            String uri = "android.resource://" + getPackageName() + "/"
                    + R.raw.videoname;
            myvideo.setVideoPath(uri);
            timevideo = returnData.getInt("POSVIDEO");
            myvideo.seekTo(timevideo);
            myvideo.requestFocus();
            myvideo.start();
        }
@Override
    public Object onRetainNonConfigurationInstance() {
        Bundle data = new Bundle();
        timevideo = myvideo.getCurrentPosition();
        data.putInt("POSVIDEO", timevideo);
        return data;
    }

Thank you

lûr
  • 191
  • 12