Android MediaPlayer stops playing after some time

不羁的心 提交于 2019-12-12 19:02:51

问题


Having small game to play short sound after onclick ImageButton. But after touching 10times MediaPlayer stop playing sounds on short time. After sometime it play sound again. When I look to LogCat console it show error: E/MediaPlayer(19584): error (1, -2147483648).

Please can you show me the way to find sollution to solve this problem ? Why MediaPlayer gives me error ?

I use this part of code to play Sound:

public void playAudio () {
    try {
        mediaPlayer = MediaPlayer.create(getBaseContext(), R.raw.trefa);
    mediaPlayer.setLooping(false);
    mediaPlayer.start();
    mediaPlayer.setOnCompletionListener(new OnCompletionListener() {
            public void onCompletion(MediaPlayer arg0) {

            }
    });
    } catch (Exception e) {
    Log.e("beep", "error: " + e.getMessage(), e);
    }
    }

回答1:


The sollution for me is really to use SoundPool (not MediaPlayer). I have replaced my MediaPlayer with SoundPool from this tutorial: http://www.edumobile.org/android/android-programming-tutorials/sound-pool-example-in-android-development and everything is ok.



来源:https://stackoverflow.com/questions/19566450/android-mediaplayer-stops-playing-after-some-time

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!