0

我正在使用 SoundPool 和MediaPlayer. 每次播放任何音频声音时,都会在 LogCat 中显示错误。

public class MusicSoundResources {

    private static final String CLASS_TAG = "SoundResources";

    private static MusicSoundResources _instance;
    public static HashMap<String, MediaPlayer> mSoundPoolMap;
    private static AudioManager  mAudioManager;
    private static Context mContext;

    public MusicSoundResources() {

    }

    public static void initSounds(Context theContext) {
         mContext = theContext;
         mSoundPoolMap = new HashMap<String, MediaPlayer>();
         mAudioManager = (AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE);

         loadSounds();
    }

    private static void loadSounds()    {
        mSoundPoolMap.put("swallowed", MediaPlayer.create(mContext, R.raw.swallowed));
    }

    public static void playSound(String soundTrackIndex, boolean loop) {
        MediaPlayer mediaPlayer = mSoundPoolMap.get(soundTrackIndex);
        float streamVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
        streamVolume = streamVolume / mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);

        mediaPlayer.setVolume(streamVolume, streamVolume);
        mediaPlayer.setLooping(loop);
        mediaPlayer.start();
    }
}

这是两个显示的日志:

05-31 15:02:56.400: ERROR/AudioTrack(2384): getAudioMode[0]
05-31 15:02:56.400: ERROR/AudioR2VS(2384): The 11025 sample rate is not supported by R2VS solution.

当我使用 SoundPool 时也会出现同样的问题。

告诉我支持的采样率是多少。

4

2 回答 2

1

最后我得到了这个答案。当我们播放比特率高于 11025 Hz 的声音时会出现此错误。这是 android 媒体播放器的内部错误。

于 2011-10-03T07:39:15.020 回答
0

- 方法的最后一个参数play()是 a float,而不是 a int

public final int play (int soundID, float leftVolume, float rightVolume, int priority, int loop, float rate )

这应该有效:

mSoundPool.play(mSoundPoolMap.get("fire"), streamVolume, streamVolume, 1, 0, 1.0);
于 2011-05-31T11:57:08.450 回答