媒体播放器错误一旦多次使用 [英] Mediaplayer error once used multiple times

查看:209
本文介绍了媒体播放器错误一旦多次使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个游戏,这是接近完成,但我还有一个问题:
有一次,我preSS一个按钮,我希望有一个健全的发挥,我这样做是与此code:

I've created a game which is nearly complete, but I've still got one problem: Once I press a button I want a sound to play, I did this with this code:

                    MediaPlayer planeSound = MediaPlayer.create(ObjectCanvas.getDrawContext(), R.raw.plane);
                planeSound.start();

它可以完美,但唯一的问题是,当我preSS了很多次,那么MediaPlayer的给出了一个错误,是误差(-19,0​​)。我搜索,但我无法找到一个解决方案。如果错误发生,直到该actvity重新创建在MediaPlayer将不再发出任何声音。本场比赛没有得到一个FC,只是错误(-19,0​​)。

It works perfectly, but the only problem is when I press it a lot of times, then the MediaPlayer gives a error which is error (-19,0). I searched but I can't find a solution for this. If the error happens the MediaPlayer won't play any sounds anymore untill the actvity is recreated. The game doesn't get a FC, but just the error (-19,0).

我不知道如何解决它,我希望有人可以给我一些建议或解释。

I don't know how to fix it, I hope someone can give me some suggestions or explanation.

推荐答案

去声音池,或重复使用媒体播放器的一个实例,或者一旦你已经完成了它释放每个实例。

Go for sound pool, or reuse one instance of media player, or release each instance once you have finished with it.

在用的MediaPlayer完成后,你应该调用发布(),以释放
  资源。如果没有释放,太多的MediaPlayer实例将会导致
  异常。

When done with the MediaPlayer, you should call release(), to free the resources. If not released, too many MediaPlayer instances will result in an exception.

还建议,一旦MediaPlayer对象不再
  被使用,呼叫释放()立刻让使用的资源
  与MediaPlayer对象相关的内部播放引擎可
  立即释放。资源可以包括单等资源
  硬件加速组件和失败调用Release()可能
  导致后续实例对象的MediaPlayer回退到
  软件实现或完全失败。一旦MediaPlayer的
  目的是在最终状态时,它不再能使用,并且不存在
  办法把它带回来给任何其他国家。

It is also recommended that once a MediaPlayer object is no longer being used, call release() immediately so that resources used by the internal player engine associated with the MediaPlayer object can be released immediately. Resource may include singleton resources such as hardware acceleration components and failure to call release() may cause subsequent instances of MediaPlayer objects to fallback to software implementations or fail altogether. Once the MediaPlayer object is in the End state, it can no longer be used and there is no way to bring it back to any other state.

查看文档: http://developer.android.com/reference/安卓/媒体/ MediaPlayer.html

这篇关于媒体播放器错误一旦多次使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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