当我单击按钮时,会在我的应用程序上播放声音,但持续单击一段时间后将不再播放.也许是内存问题?你能解决我的问题吗?这是通过SoundPool实现的播放声音:当我单击按钮时,我调用了play方法:而play方法在后台线程起作用
When i click button plays sound on my app, but keep clicking for a while doesn`t play anymore. Maybe it is memory issue? Could you solve me my issue? Here is implemented play sound via SoundPool: when i click button i called play method: and play method works background thread
private void play(int resId) { soundPool = buildBeforeAPI21();//TODO: refactor with deprecated constructor soundPool.load(activity, Integer.parseInt(resId), 1); } public SoundPool buildBeforeAPI21() { if (soundPool == null) { soundPool = new SoundPool(2, AudioManager.STREAM_MUSIC, 0); soundPool.setOnLoadCompleteListener(new SoundPool.OnLoadCompleteListener() { @Override public void onLoadComplete(SoundPool soundPool, int sampleId, int status) { if (status == 0) { soundPool.play(sampleId, 1.0f, 1.0f, 1, 0, 1.0f); } } }); } return soundPool; } 推荐答案不要每次点击都创建一个新的SoundPool.那是非常浪费的.改为执行此操作:
Don't create a new SoundPool with each click. That is extremely wasteful. Do this instead:
1)仅创建一次SoundPool2)将您想要播放的所有声音加载一次3)等待所有声音加载4)每次单击即可调用soundPool.play().
1) Create the SoundPool just once 2) Load it with all the sounds you want to play, just once 3) Wait for all the sounds to load 4) Just call soundPool.play() with each click.
更多推荐
单击几次后,SoundPool无法播放声音
发布评论