我正在将exo-player用作我的应用程序的视频播放器。在图库模式下打开后,我无法自动启动视频。 我需要单击“播放”按钮才能播放视频。
如何使其自动播放而不是单击播放?
我使用了以下2种解决方案,均未达到要求的结果,
exoPlayer.setPlayWhenReady(true);
exoPlayer.getPlayWhenReady();
编辑-
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
Log.e("Scroll",String.valueOf(distanceY)+" - "+String.valueOf(distanceX));
if(distanceY>-40&&distanceY<-20&&distanceX<10){
ImageCorouselViewActivity.this.finish();
try {
int position = vpImageCorousel.getCurrentItem();
if(listImagesViewPagers.get(position).isVideo()) {
//exoPlayer.setPlayWhenReady(false);
exoPlayer.setPlayWhenReady(true);
exoPlayer.getPlaybackState();
}
}
catch (Exception e) {
e.printStackTrace();
}
super.onBackPressed();
ImageCorouselViewActivity.this.overridePendingTransition(R.anim.stay,R.anim.slide_down);
return true;
}
return false;
}
答案 0 :(得分:0)
您需要在exoplayer上添加prepare()
if(listImagesViewPagers.get(position).isVideo()) {
//exoPlayer.setPlayWhenReady(false);
exoPlayer.setPlayWhenReady(true);
exoPlayer.getPlaybackState();
// Prepare the player with the source.
mPlayer.prepare(mVideoSource);
}
希望这会有所帮助