【问题标题】:SoundPool stops playingSoundPool 停止播放
【发布时间】:2017-07-02 15:10:25
【问题描述】:

我有一个按钮,当按下该按钮时,SoundPool 会发出短暂的声音效果。该文件是 16k mp3。
声音效果适用于数百次按钮点击,但在某些时候我收到此错误(并且不再播放声音):

E/AudioFlinger(   34): no more track names available
E/AudioTrack(  904): AudioFlinger could not create track, status: -12
E/SoundPool(  904): Error creating AudioTrack
W/AudioFlinger(   34): write blocked for 81 msecs, 4573 delayed writes, thread
xb3f0

创建:

setVolumeControlStream(AudioManager.STREAM_MUSIC);
soundpool = new SoundPool(10, AudioManager.STREAM_MUSIC, 0);
soundpool.setOnLoadCompleteListener(new OnLoadCompleteListener() {
    @Override
    public void onLoadComplete(SoundPool soundPool, int sampleId, int status) {
        // TODO Auto-generated method stub
        loaded = true;
    }
});

//save the effect somewhere:
MyUtil.regularSound = soundpool.load(this, R.raw.regular_click,1);

点击:

AudioManager audioManager = (AudioManager) getSystemService(AUDIO_SERVICE);
float actualVol = (float) audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
float maxVol = (float) audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
float vol = actualVol/maxVol;
if (loaded) {
    soundpool.play(MyUtil.regularSound,vol,vol,1,0,1f);
}

在开始另一个意图之前:

Intent i = new Intent(con, EndScreen.class);
if (soundpool != null) {
    soundpool.release();
    soundpool = null;
}
startActivity(i);

【问题讨论】:

  • 我的 2 美分价值:可能是 Soundpool 释放尚未处理 (GC),并且就 soundpool 而言,插槽仍处于活动状态。您已将 maxstreams 设置为 10。只是一个想法。

标签: android soundpool


【解决方案1】:

我刚刚花了几个小时来解决同样的问题。

-12 错误意味着分配给应用的声音内存不足。使用.finish() 不会释放 SoundPool 的内存。你必须使用.release()

在我的应用程序中,我在 onclick 方法上有一个 soundPool.release() 方法,用于启动下一个活动,

更改声音格式对我也不起作用。

【讨论】:

    【解决方案2】:

    我遇到了同样的错误。我所做的是尝试重新采样曲目,将其转换为 OGG 格式并将质量更改为 0。我用 Audacity 完成了所有这些操作

    【讨论】:

    • OGG 中有什么让问题消失?
    【解决方案3】:

    你试试编码:这里

        /*
        private SoundPool mSoundPool;
        private SparseArray<Integer> mSoundPoolMap;
        private AudioManager mAudioManager;
        */
        public static void clear() {
            if (mSoundManager != null) {
                mSoundManager.mSoundPool = null;
                mSoundManager.mAudioManager = null;
                mSoundManager.mSoundPoolMap = null;
            }
            mSoundManager = null;
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多