I want to play a notification sound, and my problem is that the sound loops forever when it should sound only once.
I tried two ways:
notification.sound = Uri.parse("content://media/internal/audio/media/38");
and
mMediaPlayer = new MediaPlayer(); mMediaPlayer.setAudioStreamType(AudioManager.STREAM_NOTIFICATION); mMediaPlayer.setDataSource(this, Uri.parse("content://media/internal/audio/media/38")); mMediaPlayer.setLooping(false); mMediaPlayer.prepare(); mMediaPlayer.setOnPreparedListener(new OnPreparedListener() { @Override public void onPrepared(MediaPlayer mp) { Log.v(Utils.TAG, "onprepared"); mp.start(); } }); mMediaPlayer.setOnCompletionListener(new OnCompletionListener() { @Override public void onCompletion(MediaPlayer mp) { Log.v(Utils.TAG, "end, we should release"); mp.stop(); mp.release(); } });
In the second case, I never see the end, βthe end we must let goβ, the sound is played again and again.
Any idea?
Many thanks
UPDATE:
I tried two devices and:
- He forever obsessed with the Galaxy Nexus with ICS 4.0.4.
- It works fine on HTC Hero 2.2.1
source share