Android MediaPlayer没有从原始文件夹(Android Lollipop)播放wav文件

时间:2014-11-08 08:09:57

标签: android android-mediaplayer android-5.0-lollipop

我正在尝试使用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();
        }

    }
 });

2 个答案:

答案 0 :(得分:0)

您尝试播放的声音效果有多长?

根据我的经验,我无法获得任何短于0.2秒的.wav文件在Lollipop上产生声音,在其他版本中,4.0 - 4.4.4,它们打得很好。我通过使用Audacity(或其他一些音频处理工具)用静音来填充声音效果的结尾。一旦他们> = 0.2秒,他们就在棒棒糖上玩了没有问题。

我不知道这是不是你的问题,但你可能想试一试。

答案 1 :(得分:-1)

此处报告的问题为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