一段时间后,Android MediaPlayer停止播放 [英] Android MediaPlayer stops playing after some time

查看:679
本文介绍了一段时间后,Android MediaPlayer停止播放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

具有一个小游戏,可以在单击ImageButton后播放短声音.但是在接触10次之后,MediaPlayer会在短时间内停止播放声音.一段时间后,它会再次播放声音.当我查看LogCat控制台时,它显示错误:E/MediaPlayer(19584): error (1, -2147483648).

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).

请您告诉我解决该问题的方法吗?为什么MediaPlayer给我错误?

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);
    }
    }

推荐答案

对我来说,解决方案实际上是使用SoundPool(而非MediaPlayer).我已从本教程中用SoundPool替换了MediaPlayer:

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.

这篇关于一段时间后,Android MediaPlayer停止播放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆