【问题标题】:Android MediaPlayer not playing wav file from raw folder (Android Lollipop)Android MediaPlayer 不播放原始文件夹中的 wav 文件(Android Lollipop)
【发布时间】:2014-11-08 08:09:56
【问题描述】:
我正在尝试使用 MediaPlayer 从原始文件夹播放 wav 文件,在所有 android 版本(4.0-4.4.4)上它都可以工作,但在 Android L 预览版(和 Android Lollipop AOSP 版本上)没有声音,并且没有错误。
这是我的代码:
mPlayer = MediaPlayer.create(GlobalParameters.mContext, R.raw.beep);
mPlayer.start();
mPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
if (mPlayer != null) {
mPlayer.reset();
mPlayer.release();
}
}
});
【问题讨论】:
标签:
android
android-mediaplayer
android-5.0-lollipop
【解决方案1】:
您要播放多长时间的音效?
根据我的经验,我无法让任何短于 0.2 秒的 .wav 文件在 Lollipop 上产生声音,而在其他版本(4.0 - 4.4.4)中,它们可以正常播放。我通过使用 Audacity(或其他一些音频操作工具)在音效的结尾处用静音来解决这个问题。一旦他们 >= 0.2 秒,他们就可以毫无问题地在 Lollipop 上玩。
我不知道这是否是您的问题,但您可能想试一试。
【解决方案2】:
这里报告了一个问题https://code.google.com/p/android/issues/detail?id=77860
Reported by h6a.h4...@gmail.com, Oct 21, 2014
Description:
I noticed MediaPlayer.OnCompletionListener callback behavior seems to be changed since Lollipop.
[KitKat]
- setLooping(false), setNextMediaPlayer(null)
-> onCompletion() is fired
- setLooping(true), setNextMediaPlayer(null)
-> onCompletion() is not fired
- setLooping(false), setNextMediaPlayer(other valid instance)
-> onCompletion() is not fired
- setLooping(true), setNextMediaPlayer(other valid instance)
-> onCompletion() is not fired
[Lollipop (when using AwesomePlayer)]
- setLooping(false), setNextMediaPlayer(null)
-> onCompletion() is fired : OK
- setLooping(true), setNextMediaPlayer(null)
-> onCompletion() is not fired : OK
- setLooping(false), setNextMediaPlayer(other valid instance)
-> onCompletion() is fired : ???
- setLooping(true), setNextMediaPlayer(other valid instance)
-> onCompletion() is not fired : OK
[Lollipop (when using NuPlayer)]
- setLooping(false), setNextMediaPlayer(null)
-> onCompletion() is fired : OK
- setLooping(true), setNextMediaPlayer(null)
-> onCompletion() is fired : ???
- setLooping(false), setNextMediaPlayer(other valid instance)
-> onCompletion() is fired : ???
- setLooping(true), setNextMediaPlayer(other valid instance)
-> onCompletion() is fired : ???
Tested environment:
- Nexus 7 2013
- Android 5.0 (LPX13D)
bugreport.txt.tar.gz
740 KB Download
Oct 22, 2014 Project Member #1 michaelb...@google.com
Thank you for reporting this issue. We have passed this on to the development team and will update this issue with more information as it becomes available.
Status: Accepted
Owner: michaelb...@google.com
Labels: 18080636