ANDROID_LOOP = true — how to avoid MediaPlayer looping audios with this metadata tag

夙愿已清 提交于 2019-12-30 18:50:13

问题


I want to play device ringtones with MediaPlayer yet it seems when the metadata tag

ANDROID_LOOP = true

is set MediaPlayer is ignoring the call of the method setLooping

mMediaPlayer.setLooping(false);

and loops the audio in any case. Also the onCompletionListener method is not called.

I noticed that even audio apps like ES Media Player loop audios with this tag set to true regardless if looping is enabled or not.

So my question is if I can

  • make MediaPlayer ignoring this tag
  • temporary modify the tag so that MediaPlayer does not loop the audio

This question arose around ringtones yet it is of course not ringtone specific. Funnily the tutorials I found on how to play ringtones all set mMediaPlayer.setLooping(true); so that they dont have to handle this problem it seems ...

Thanks


回答1:


Might not be a satisfactory answer, but it seems the engineers are not inclined to change the behavior of MediaPlayer and the metadata tag ANDROID_LOOP=true for ogg files. See issue: http://code.google.com/p/android/issues/detail?id=1314

As for temporarily modifying the tag, I don't know how you could go about doing that.

I haven't tested it but I believe other sound formats don't exhibit this behavior (e.g. mp3 or wav). Perhaps you could convert the ogg files to a different format and keep them as temp data (might help with this: Java - Convert ogg to mp3) This of course seems like a lot of overhead to play back some files, but at least they're usually small files.



来源:https://stackoverflow.com/questions/12834727/android-loop-true-how-to-avoid-mediaplayer-looping-audios-with-this-metadat

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!