Mediaplayer错误(-19 0)不适用于release() [英] Mediaplayer error (-19 0) doesn't work with release()

查看:163
本文介绍了Mediaplayer错误(-19 0)不适用于release()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为Soundboard编码,当您在声音上单击20次以上时,出现了问题.

I'm coding a Soundboard and I got a problem when you have clicked 20+ times on the sounds.

首先,我收到MediaPlayer错误(-19 0),您再也听不到声音了.我知道这是我的记忆. 因此,当我尝试添加Release()时;根本没声音.

First I get MediaPlayer error(-19 0) and you can't hear any more sounds. I know it's my memory. So when I try to add Release(); it doesn't sound at all.

这是一个播放声音的按钮:

Here is a button that plays sound:

public void click7(View v) {
MediaPlayer mp = MediaPlayer.create(NewActivity3.this, R.raw.hahah);
mp.start(); 
    }

我也一直在尝试发行,所以没有声音:

I have been trying with release as well then there's no sound:

public void click7(View v) {
        MediaPlayer mp = MediaPlayer.create(NewActivity3.this, R.raw.hahah);
        mp.start();
        mp.stop();
        mp.reset();
        mp.release();
    }

我在做什么错了?

推荐答案

使用以下代码

MediaPlayer mp=MediaPlayer.create(NewActivity3.this, R.raw.hahah);

   public void click7(View v) {
    if(mp!=null ){
    mp.reset();
    mp.prepare();
    mp.start(); 
   }

每当您按下按钮并想要播放声音文件时,此代码将非常有用.

Whenever u press button and u want to play sound file ,this code will be very useful for that.

这篇关于Mediaplayer错误(-19 0)不适用于release()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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