声音一排,为什么打更多的声音时,有时会保持沉默? [英] Sound sometimes remains silent when playing more sounds in a row, why?

查看:161
本文介绍了声音一排,为什么打更多的声音时,有时会保持沉默?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一个奇怪的问题,遇到的困难和希望有人能回答这个问题..我有4×4的按键,每个人扮演了短短的1秒的声音,如果我点击它。我的code吧:

I encountered with a weird problem and hope that someone can answer it.. I have 4x4 buttons, each of them plays a short 1 second sound if I click on it. My code for it:

Button_1= (Button) findViewById(R.id.button1);
            Button_1.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (sound!=null){
                        sound.stop();
                        sound.release();
                        sound=null;
                    }
                    sound = MediaPlayer.create(Main.this, R.raw.short_sound);
                    sound.start();
                }
            });

那么,什么情况是,我接触所有的按钮行,所以,首先Button1的,那么按钮2,每次我触摸它的时候,一短声被播放。但有时,当我到达14或15个或16个按钮,它不播放声音它应该。其他按钮的工作,但不知何故最后1,2或3有时候犯规播放任何声音。如果我开始向后触摸按键,所以我触摸按钮,第16届第一它总是工作,但那么也许二楼和按钮保持沉默。

So what happens is that I touch all the buttons in row, so firstly the button1, then button 2 and every time I touch it, a short sound gets played. But sometimes when I reach the 14th or 15th or 16th button it doesnt play the sound it should. The other buttons work but somehow the last 1,2 or 3 sometimes doesnt play any sound. If I start touching the buttons backwards, so I touch the 16th button first it always works, but then maybe the 1st and 2nd button remain silent.

可能是什么原因? LogCat中不写任何东西。

What might cause this? LogCat does not write anything.

推荐答案

当你调用MediaPlayer.create()分配了一个不一定由GC机构释放资源。您应该手动释放MediaPlayer.release()例程。当您完成与对象

When you call MediaPlayer.create() you allocate resources that aren't necessarily released by the GC mechanism. You should manually release the MediaPlayer.release() routine. when you are finished with the object

这篇关于声音一排,为什么打更多的声音时,有时会保持沉默?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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