views:

205

answers:

1

Hi all i've ran into another problems with VideoView. Then video is playing, and i put device asleep, using hard button, onPause is called. But it followed by

03-17 11:26:33.779: WARN/ActivityManager(884): Activity pause timeout for HistoryRecord{4359f620 com.package/com.package.VideoViewActivity}

And then i have onStart/onResume again and Video starts playing. I've try to move code around onStart/onStop - doesn't seems to make difference.

sample code :

public class VideoViewActivity extends Activity {


    private String path = "";
    private VideoView mVideoView;
    private static final String MEDIA_URL = "media_url";

    @Override
    public void onCreate(Bundle icicle) {

        super.onCreate(icicle);
        setContentView(R.layout.videoview);
        mVideoView = (VideoView)findViewById(R.id.surface_view);
        path = getIntent().getStringExtra(MEDIA_URL);
    }

    @Override
    public void onResume() {

        super.onResume();
        mVideoView.setVideoPath(path);
        mVideoView.setMediaController(new MediaController(this));
        mVideoView.requestFocus();
        mVideoView.start();
    }

    @Override
    public void onPause() {

        super.onPause();
        mVideoView.stopPlayback();

        mVideoView.setMediaController(null);
    }
}
A: 

OK, Looks like the behavior is related to activity lifecycle and the fact that VideoViewActivity is set to landscape in the manifest. Adding

android:configChanges="keyboardHidden|orientation" 

for that activity seems to fix the problem and then you put device to sleep only onPause() called vs before - all lifecycle methods were executed. I'll do more testing to make sure it fixed...

Alex Volovoy