[英]Audio is continue playing after second video is playing in ExoPlayer at android
我正在嘗試在 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
並且每次都重新創建一個新的。
如果您想一個接一個播放多個視頻,則需要使用播放列表 API
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.