我目前正在开发一个必须播放音频的应用程序。我有一种按顺序播放一系列.mp3 的方法。这是方法:
/**
* Plays a series of sounds in order without delay.
*
* @param audioResourceIds
* An in-order array of the audio asset resources to play.
* */
public void playQueuedPlaylist(int[] audioResourceIds)
{
float lastPlayedSoundDuration;
for(int i = 0; i<audioResourceIds.length; i++)
{
lastPlayedSoundDuration = playMedia(audioResourceIds[i], null);
try
{
Thread.sleep((long)lastPlayedSoundDuration);
}
catch(Exception eh)
{
Log.v("BulacsAlmighty","Exception caught at playQueuedPlaylist()");
}
}
}
/**
* Used to play voice overs
*
* @param index
* id of the sound
* @param listener
* on completion listener
*/
public int playMedia(int index, OnCompletionListener listener)
{
MediaPlayer mp = MediaPlayer.create(context, index);
mp.setVolume(streamVolume, streamVolume);
stopMedia(index); // Stops the sound if it still is playing.
mp.start();
return mp.getDuration();
}
问题是声音有时不播放。并且当它们播放时,时间正确,顺序正确,但是最后播放的音频资源的播放音量明显低于之前播放的其他声音。
告诉我,我哪里做错了!?