媒体播放器在30次点击后停止播放声音吗? [英] mediaplayer stop sound after 30 click?

查看:106
本文介绍了媒体播放器在30次点击后停止播放声音吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想问一问,为什么在31岁及以后的时间里单击带有声音的按钮30次之后,不再能听到声音,而再单击几下就会挂起?谁能帮帮我吗?预先感谢,这是我的代码.

hi I would like to ask why is that after clicking a button w/ sound 30 times on the 31 onwards the sound will no longer be heard and will hang after a few more click? can anyone please help me? thanks in advance here is my code.

SharedPreferences soundPrefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
boolean sound = soundPrefs.getBoolean("Sound", true);
MediaPlayer clickLetters = MediaPlayer.create(Gameplay.this, R.raw.click_letters);

        switch(v.getId()) {
            case R.id.btnA:
                if (sound == true)
                {
                    clickLetters.start();
                }
                Answer = Answer + alphabetA;
                tvAns.setText(Answer);

            break;
            case R.id.btnB:
                if (sound == true)
                {
                    clickLetters.start();
                }
                Answer = Answer + alphabetS;
                tvAns.setText(Answer);
            break;

推荐答案

可能是因为您为每次点击分配了一个新的MediaPlayer实例.您应该调用release()释放资源,如果不释放,太多MediaPlayer实例将导致异常. 您应该只创建1个Mediaplayer实例,并尽可能重复使用

probably because you are allocating a new MediaPlayer instance on each click. you should call release(), to free the resources, If not released, too many MediaPlayer instances will result in an exception. you should create only 1 instance of mediaplayer and reuse it as much as possible

这篇关于媒体播放器在30次点击后停止播放声音吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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