0
我試圖從ExoPlayer
從URL播放MP3文件。ExoPlayer getDuration
一切都很好,但現在我想知道什麼時候它是安全的音軌的getDuration()
。一旦軌道加載,我只需要它。沒有在谷歌的示例項目中找到它。
當我試圖在exoPlayer.prepare()
之後馬上得到它時,我得到UNKNOWN_TIME
。
我試圖從ExoPlayer
從URL播放MP3文件。ExoPlayer getDuration
一切都很好,但現在我想知道什麼時候它是安全的音軌的getDuration()
。一旦軌道加載,我只需要它。沒有在谷歌的示例項目中找到它。
當我試圖在exoPlayer.prepare()
之後馬上得到它時,我得到UNKNOWN_TIME
。
好吧,看起來這是這裏唯一的解決方案。
我們將監聽器添加到我們的播放器中,並在狀態更改爲STATE_READY
時獲取持續時間。它顯然會在每個播放/暫停動作中都要求播放,所以我們需要用boolean durationSet
標誌if
將其打包並在音軌開始時調用一次。然後durationSet = false
附近audioPlayer.prepare()
audioPlayer.addListener(new ExoPlayer.Listener() {
@Override
public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
if (playbackState == ExoPlayer.STATE_READY && !durationSet) {
long realDurationMillis = audioPlayer.getDuration();
durationSet = true;
}
}
@Override
public void onPlayWhenReadyCommitted() {
// No op.
}
@Override
public void onPlayerError(ExoPlaybackException error) {
// No op.
}
});
地方我想.MP3和.AAC文件的播放ExoPlayer。我得到MP3的持續時間,但不適用於AAC。我可以嘗試什麼?我可能在哪裏錯了? –
請查看http://stackoverflow.com/questions/39777975/not-able-to-get-getduration-for-aac-file-using-exoplayer –