How to play ringtone once through MediaPlayer?
I can't play a ringtone once even if mediaplayer looping property is set to false. It looks like this property was overriden by the ringt开发者_JS百科one URI
used. So onCompletion
is never fired.
Curiously, if the URI
corresponds to a notification tone, looping behaves according to setLooping
. It works well here.
So is there a way to play a ringtone once?
I faced this problem before and solved it by using OnSeekCompleteListener:
mMediaPlayer.setOnSeekCompleteListener(new OnSeekCompleteListener() {
public void onSeekComplete(MediaPlayer mp) {
//Your stuff
}});
I don't know if it's the best way to solve this, but it worked for me.
Edit: BTW, I use both listeners, oncompletionlistener AND onseekcompletelistener. Hope this helps!
精彩评论