1

MediaPlayer gives error(-38,0) when playing audio repeats by clicking play button. I am trying to make an app like musical pad first time it plays OK but when you click multiple times it goes in hang mode and shows error.

pb2q
  • 58,613
  • 19
  • 146
  • 147
Naresh29
  • 49
  • 9

2 Answers2

0

the media player buffer is getting full . Use SoundPool instead

 int SoundArr[] = { R.raw.birds_whistling, R.raw.come_bye,
            R.raw.cute_whistle, R.raw.kill_bill_whistle, R.raw.look_back,
             };

SoundPool mSoundPool;
HashMap<Integer,Integer> mSoundPoolMap;
AudioManager  mAudioManager;

 mSoundPool=(SoundPool) SoundImageAdaptor.mSoundPool;
 mSoundPoolMap =SoundImageAdaptor.mSoundPoolMap;//i'm using a grid view adaptor
 mAudioManager = (AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE);
/* code to that ensures the sound plays even when media player buffer gets full*/
                 if(!(mSoundPoolMap.containsKey(position)))
                 addSound(position, SoundArr[position]);
                 playSound(position);

You can check this link also How to properly use SoundPool on a game?

Community
  • 1
  • 1
Rachita Nanda
  • 4,509
  • 9
  • 42
  • 66
0

I assume you just prepare the mediaplayer with the same source once more when clicked again. You need to either release the old data

mMediaPlayer.release();

or if it is the same audio better just use

mMediaPlayer.seekTo(0)

to jump to the beginning again, no need for another prepare round.

Soundpoool is great for small files yet cant handle bigger audio files.

UPDATE:

Actually just got the same error in one of my apps: So my mistake was

mMediaPlayer.stop();
mMediaPlayer.seekTo(0);

which is not correct as after stop you have to prepare again. The correct way is

mMediaPlayer.pause();
mMediaPlayer.seekTo(0);

The official docu as usual is very good

http://developer.android.com/reference/android/media/MediaPlayer.html

dorjeduck
  • 7,624
  • 11
  • 52
  • 66