开发者

Android video restarted with orientation

开发者 https://www.devze.com 2023-04-03 23:42 出处:网络
How to avoid reloading of video with orientation change i.e force the video to resume from same. ihave tried below but it fails

How to avoid reloading of video with orientation change i.e force the video to resume from same.

i have tried below but it fails

vd = (VideoView) findViewById(R.id.vplayer);
.......
public void onSaveInstanceState(Bundle savedInstanceState) {
    super.onSaveInstanceState(savedInstanceState);
    savedInstanceState.putInt("Position",vd.getCurrentPosition());
}

public void onRestoreInstanceState(Bundle savedInstanceState) {
    super.onRestoreInstanceState(savedInstanceState);
    int position= savedInstanceState.getInt("Position"开发者_开发知识库);
    vd.seekTo(position);
}


What you can do is stop your Activity to get re-created when orientation changes. You can do that by adding in your AndroidManifest.xml file in the activity tag

android:configChanges="keyboardHidden|orientation"
0

精彩评论

暂无评论...
验证码 换一张
取 消