我在纵向模式下使用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());
}
}
答案 0 :(得分:1)
通过为清单android:configChanges="orientation|uiMode|screenSize"
答案 1 :(得分:0)
很可能在方向改变时,您需要销毁视频视图,然后在方向更改后恢复它并从中断处继续播放。
一点注意事项,我在Android开发中使用VideoView和MediaPlayer时遇到了问题。特别是让这两件事在多个设备上正常工作。如果我是你,我会调查ExoPlayer库以支持视频播放。但我想这取决于您的应用视频播放的大部分内容。 ExoPlayer需要花费大量的时间来设置和正常工作,但它仍然不难,性能和稳定性的提高使它能够正常工作。