【发布时间】:2012-10-14 12:40:46
【问题描述】:
MediaPlayer 在通过单击播放按钮重复播放音频时给出错误(-38,0)。 我正在尝试制作一个像音乐垫这样的应用程序,它第一次播放正常,但是当你点击多次时它进入挂起模式并显示错误。
【问题讨论】:
-
你能贴出你的代码吗?
标签: android media-player
MediaPlayer 在通过单击播放按钮重复播放音频时给出错误(-38,0)。 我正在尝试制作一个像音乐垫这样的应用程序,它第一次播放正常,但是当你点击多次时它进入挂起模式并显示错误。
【问题讨论】:
标签: android media-player
媒体播放器缓冲区已满。
请改用SoundPool
int SoundArr[] = { R.raw.birds_whistling, R.raw.come_bye,
R.raw.cute_whistle, R.raw.kill_bill_whistle, R.raw.look_back,
};
SoundPool mSoundPool;
HashMap<Integer,Integer> mSoundPoolMap;
AudioManager mAudioManager;
mSoundPool=(SoundPool) SoundImageAdaptor.mSoundPool;
mSoundPoolMap =SoundImageAdaptor.mSoundPoolMap;//i'm using a grid view adaptor
mAudioManager = (AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE);
/* code to that ensures the sound plays even when media player buffer gets full*/
if(!(mSoundPoolMap.containsKey(position)))
addSound(position, SoundArr[position]);
playSound(position);
【讨论】:
我假设您再次单击时只需再次准备具有相同来源的媒体播放器。您需要释放旧数据
mMediaPlayer.release();
或者如果是相同的音频,最好使用
mMediaPlayer.seekTo(0)
再次跳到起点,无需另一轮准备。
Soundpoool 非常适合小文件但无法处理较大的音频文件。
更新:
实际上我的一个应用程序中出现了同样的错误:所以我的错误是
mMediaPlayer.stop();
mMediaPlayer.seekTo(0);
这是不正确的,因为停止后你必须重新准备。正确的做法是
mMediaPlayer.pause();
mMediaPlayer.seekTo(0);
官方文档一如既往的好
http://developer.android.com/reference/android/media/MediaPlayer.html
【讨论】: