Reputation: 4222
I'm trying to play a .mp3 sound from my raw folder, but somehow the sound doesn't play. The code does execute the play method but it doesn't produce sound. Here's my code:
public SoundPlayer(Context context) {
this.context = context;
AudioManager audioManager = (AudioManager) context.getSystemService(Service.AUDIO_SERVICE);
soundPool = new SoundPool(3, AudioManager.STREAM_MUSIC, 0);
clickId = soundPool.load(context, R.raw.bubbleclick, -1);
errId = soundPool.load(context, R.raw.bubbleclickerror, 1);
countId = soundPool.load(context, R.raw.countdowntick, 1);
float actualVolume = (float) audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
float maxVolume = (float) audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
volume = actualVolume / maxVolume;
}
public void playBubbleClick() {
if (!isMuted()) {
soundPool.play(clickId, volume, volume, 1, 0, 1);
}
}
I first instantiate the SoundPlayer class (custom class), and then call playBubbleClick()
Upvotes: 1
Views: 996
Reputation: 4222
I didn't solve the issue but I worked around it by calling the play method in the onLoad event (when setting an onLoadListener). This does solve it, but still shouldn't be the way it is done.
Upvotes: 1