Android无法用soundpool播放一些wav文件?

时间:2011-02-21 15:53:14

标签: android audio

一些.wav文件我无法使用soundpool。我听不到任何声音。有些文件播放得很好。为什么呢?

代码

    AudioManager mgr = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    int streamVolume = mgr.getStreamVolume(AudioManager.STREAM_MUSIC);
    soundPool.play(soundPoolMap.get(sound), streamVolume, streamVolume, 1, 0, 1f);

2 个答案:

答案 0 :(得分:2)

我在soundpool和文件格式方面遇到了很多问题。 Read my original question,它可能会对您有所帮助。

基本上,我改为使用MediaPlayer,没有更多问题。

答案 1 :(得分:1)

我使用运行 Jellybean 4.1.2 LG Optimus F3 使用.WAV资源文件的结果是其MediaPlayer库无法解码:

  1. 比特率超过256kbps的文件,
  2. 持续时间小于.075秒的文件
  3. 在任何一种情况下,logcat中的症状是:

    V/SoundPool﹕ load: fd=49, offset=123932, length=536, priority=1
    V/SoundPool﹕ create sampleID=3, fd=50, offset=536, length=123932
    V/SoundPool﹕ doLoad: loading sample sampleID=3
    V/SoundPool﹕ Start decode
    V/MediaPlayer﹕ decode(50, 123932, 536)
    V/SoundPool﹕ close(50)
    E/SoundPool﹕ Unable to load sample: (null)
    

    上述错误导致SoundPool稍后尝试使用这些" null"而不是生成致命异常。声音,这反过来可能导致手机锁定和/或丢失帧。 降低比特率并使用Audacity"添加沉默"延长声音文件时间的效果解决了这个问题。

    与上述症状相反,成功的SoundPool加载在logcat中如下所示:

    V/SoundPool﹕ load: fd=55, offset=765700, length=3534, priority=1
    V/SoundPool﹕ create sampleID=7, fd=56, offset=3534, length=765700
    V/SoundPool﹕ doLoad: loading sample sampleID=7
    V/SoundPool﹕ Start decode
    V/MediaPlayer﹕ decode(56, 765700, 3534)
    V/SoundPool﹕ close(56)
    V/SoundPool﹕ pointer = 0x5f464000, size = 6976, sampleRate = 8000, numChannels = 2
    

    如果您正在加载多个声音(这是SoundPool的目的),请记下您的sampleID值,因为它们告诉哪个声音文件无法加载,第一个声音文件加载为sampleID=1,依此类推。这有助于我区分"坏"来自"好" .WAV文件。

    请注意,我有 在运行Android Kitkat的LG和三星的其他几个平台上出现此问题,这会成功加载更高比特率和短声音文件。

相关问题