E/MediaPlayer:错误(1,-19) [英] E/MediaPlayer: error (1, -19)
问题描述
我正在创建一个简单的音板,以在用户单击按钮时播放声音.问题是,如果充分按下该按钮(通常约10次),它将最终停止播放并显示错误E/MediaPlayer: error (1, -19)
我究竟做错了什么?我的播放声音的代码:
I'm creating a simple soundboard to play sounds when a user clicks a button. Problem is, if the button is pressed enough ( usually around 10 times ) it will eventually stop playing and show the error E/MediaPlayer: error (1, -19)
what am I doing wrong? My code that plays the sound:
private void playSound(int soundID){
final MediaPlayer mp = MediaPlayer.create(this,soundID);
mp.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mediaPlayer) {
mp.start();
}
});
}
推荐答案
您应该使用Soundpool.它是专为播放短音效而创建的.而且它比MediaPlayer使用起来简单得多. MediaPlayer仅应用于播放常规/大型音乐.
You should use Soundpool. It's created exactly for playing short sound effects. And it's much simpler to use than MediaPlayer. MediaPlayer should only be used for playing regular/large music.
请参见此处的示例: http://www.vogella.com/tutorials/AndroidMedia/article.html#tutorial-play-sounds-via-soundpool
See here for example: http://www.vogella.com/tutorials/AndroidMedia/article.html#tutorial-play-sounds-via-soundpool
注意:无需在本示例中使用onTouch,为简单起见,您可以使用onClick.
Note: No need to use onTouch as in the example, you can just use onClick for simplicity.
这篇关于E/MediaPlayer:错误(1,-19)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!