如何保持播放视频,而改变为横向模式android(恢复视频)



我在肖像模式下使用VideoView播放视频(不是全屏)。当我切换到横向模式时,视频不会恢复(像youtube)。任何建议吗?这是我的代码。

    @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
        //Checks the orientation of the screen
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_box_office_detail);
        final ProgressDialog ringProgressDialog = ProgressDialog.show(BoxOfficeDetailActivity.this, "Please wait ...", "Video now loading ...", true);
        ringProgressDialog.setCancelable(true);
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.sleep(15000);
                } catch (Exception e) {
                }
                ringProgressDialog.dismiss();
            }
        }).start();
        videoView =(VideoView) findViewById(R.id.tvVideo);
        tvTitle = (TextView) findViewById(R.id.tvTitle);
        tvSynopsis = (TextView) findViewById(R.id.tvSynopsis);
        tvCast = (TextView) findViewById(R.id.tvCast);
        BoxOfficeMovie movie = (BoxOfficeMovie) getIntent().getSerializableExtra(BoxOfficeActivity.MOVIE_DETAIL_KEY);
        loadMovie(movie);
    }
    public void loadMovie(BoxOfficeMovie movie) {
         videoView.setVideoPath(movie.getVideo());
         MediaController mediaController = new
         MediaController(this);
         mediaController.setAnchorView(videoView);
         videoView.setMediaController(mediaController);
         videoView.start();
         videoView.requestFocus();
         tvTitle.setText(movie.getTitle());
         tvCast.setText(movie.getCastList() + " views");
         tvSynopsis.setText(movie.getSynopsis());
    }
}

通过在清单android:configChanges="orientation|uiMode|screenSize"中为活动添加此内容来避免活动破坏

很可能在方向改变时,你需要破坏视频视图,然后在方向改变后恢复它,并从它停止的地方恢复播放。

一个小边注,我没有什么,但问题与VideoView和MediaPlayer在Android开发工作。特别是让这两件事在多个设备上正确工作。如果我是你,我会查看ExoPlayer库来支持视频播放。但我想这取决于你的应用中视频播放占多大比例。ExoPlayer花了大量的时间来安装和正确工作,但它仍然不难,性能和稳定性的改进使它工作。

最新更新