是有可能减少被播放用的MediaPlayer音轨之间的周期? [英] Is it possible to reduce the period between audio tracks being played with MediaPlayer?
问题描述
我有一个数字,我需要按顺序播放音轨。我使用MediaPlayer的 OnCompletionListener
如下:
I have a number of audio tracks that I need to play in sequence. I'm using MediaPlayer's OnCompletionListener
as follows:
public void OnCompletion(MediaPlayer mp)
{
_completed++;
mp.Reset();
if (_completed < _tracks.Length)
{
try
{
AssetFileDescriptor afd = _context.Resources.OpenRawResourceFd(_tracks[_completed]);
if (afd != null)
{
mp.SetDataSource(afd.FileDescriptor, afd.StartOffset, afd.Length);
afd.Close();
mp.Prepare();
mp.Start();
}
}
catch (Exception ex)
{
throw;
}
}
}
这个工作,但有轨道之间的明显的延迟。我想,以减少该段期间尽可能接近零越好。这可能吗?
This works, but there is a noticeable delay between tracks. I'd like to reduce that period to as close to zero as possible. Is this possible?
推荐答案
MediaPlayer的链接与API级16(杰利贝恩)补充道。该方法你会感兴趣的是<一个href=\"http://developer.android.com/reference/android/media/MediaPlayer.html#setNextMediaPlayer%28android.media.MediaPlayer%29\"相对=nofollow> setNextMediaPlayer(MediaPlayer的下一个)
:
MediaPlayer "chaining" was added with API level 16 (Jellybean). The method you'd be interested in is setNextMediaPlayer(MediaPlayer next)
:
将的MediaPlayer
时,这个的MediaPlayer
结束播放开始(即到达流的末尾)。媒体框架将尝试从这个球员尽可能无缝地过渡到下一个。下一个玩家可以在完成前的任何时间进行设置。下一个玩家必须由应用ppared $ P $,并且应用程序不应该调用的start()
就可以了。
Set the
MediaPlayer
to start when thisMediaPlayer
finishes playback (i.e. reaches the end of the stream). The media framework will attempt to transition from this player to the next as seamlessly as possible. The next player can be set at any time before completion. The next player must be prepared by the app, and the application should not callstart()
on it.
这篇关于是有可能减少被播放用的MediaPlayer音轨之间的周期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!