如何解决在Android的ExoPlayer中播放第二个视频后,音频仍在继续播放
我正在尝试使用android中的ExoPlayer播放本地视频,但是当我一个接一个地尝试两个视频时,第一个视频的音频继续播放而第二个视频没有播放,我该如何解决问题
SimpleExoPlayer exo;
public playVideo(Url url,String type){
if (type.equals("VideoStart")) {
Timber.i("VideoStart");
File file = new File(url);
Uri localUri = Uri.fromFile(file);
exo = new SimpleExoPlayer.Builder(context).build();
exo.setPlayWhenReady(true);
playerView.setPlayer(exo);
MediaSource mediaSource = buildMediaSource(localUri,context);
exo.prepare(mediaSource,true,false);
} else if (type.equals("VideoEnd")) {
Timber.i("VideoEnd");
if (exo != null) {
Timber.i("ExoStopped");
exo.setPlayWhenReady(false);
exo.stop();
exo.seekTo(0L);
exo.release();
exo = null;
}
}
}
private static MediaSource buildMediaSource(Uri uri,Context context) {
return new ProgressiveMediaSource.Factory(new DefaultDataSourceFactory(context,Util.getUserAgent(context,"ExoPlayerDemo"))).createMediaSource(uri);
}
调用方法
playVideo(/storage/emulated/0/Android/data/com.exoplayer/files/Files/test.mp4,"VideoStart");
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
playVideo(/storage/emulated/0/Android/data/com.exoplayer/files/Files/test.mp4,"VideoEnd");
playVideo(/storage/emulated/0/Android/data/com.exoplayer/files/Files/second.mp4,"VideoStart");
}
},10000);
解决方法
我怀疑您没有使用相同的SimpleExoPlayer
,而是每次都在重新创建一个。
如果要一个接一个地播放多个视频,则需要使用playlist API
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。