使用Android MediaPlayer进行无间隙播放 [英] Gapless Playback with android MediaPlayer
问题描述
我正在尝试不间断地连续播放音频.我已经尝试过了,
I'm trying to repeatedly play a audio continuously, without any gap. I've tried,
mediaplayer.setLooping(true);
但是它在重复时间之间存在间隔.并尝试了这一点,
But it gives a gap between repeat time. And tried this,
mediaplayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp)
{
mediaplayer.start();
}
});
它也提供了一个空白.我尝试了不同的音频格式.但是,这两种方法都不适合我. android中还有其他方法吗?
It gives a gap also. I've tried with different audio format. But neither way worked for me. Is there any other way in android?
推荐答案
回放完成后,播放器引擎将检查所有轨道是否都已完成,一旦完成,它将检查looping
标志.根据looping
标志,从seek
到0
秒.作为搜索的一部分,播放器引擎将从特定位置读取数据并开始播放.
When a playback finishes, the player engine would check if all tracks are completed and once done, it will check for the looping
flag. Based on the looping
flag, a seek
to 0
seconds. As part of the seek, the player engine will read the data from the specific position and start the playback.
延迟可能是由于seek
实现以及存储介质(如sdcard
)引入的延迟,除了重新初始化所有轨道并重新启动它们之外.因此,在玩家返回到起始位置时存在一定的延迟.
The delay may be due to the seek
implementation along with the delay introduced by the storage medium like sdcard
apart from re-initializing all tracks and restarting them. Hence, there is definite delay by the time the player reverts back to the starting position.
底层循环实现可在此函数AwesomePlayer::onStreamDone
中找到,如下所示:
The underlying looping implementation can be found in this function AwesomePlayer::onStreamDone
as shown here: http://androidxref.com/4.2.2_r1/xref/frameworks/av/media/libstagefright/AwesomePlayer.cpp#834
要实现真正的gapless playback
,您还可以考虑 setNextMediaPlayer()
功能.
To implement a true gapless playback
, you could also consider the setNextMediaPlayer()
feature.
这篇关于使用Android MediaPlayer进行无间隙播放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!