문제

Recently I designed a multimedia player. But when I try to switch between landscape and portrait modes, the video restarts.

Is there any guide or tutorial for this issue?

I want video to play well in both landscape and portrait view.

This is my sample code in MainActivity.java

    VideoView videoView =(VideoView)findViewById(R.id.videoView1);  

            //Creating MediaController  
    MediaController mediaController= new MediaController(this);  
        mediaController.setAnchorView(videoView);          

          //specify the location of media file  
       Uri uri=Uri.parse(Environment.getExternalStorageDirectory() + "/video.mp4");

          //Setting MediaController and URI, then starting the videoView  
       videoView.setMediaController(mediaController);  
       videoView.setVideoURI(uri);          
       videoView.requestFocus();  
       videoView.start();  

}  
도움이 되었습니까?

해결책

In android manifest set this attribute to yor video activity.

android:configChanges="orientation|keyboardHidden"
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top