简体   繁体   English

Android MediaPlayer无法播放原始文件夹中的wav文件(Android Lollipop)

[英]Android MediaPlayer not playing wav file from raw folder (Android Lollipop)

I am trying to play wav file from raw folder using MediaPlayer, on all android versions(4.0-4.4.4) it is working, but on Android L preview(and on Android Lollipop AOSP build) there is no sound, and no error. 我正在尝试使用MediaPlayer从原始文件夹播放wav文件,在所有android版本(4.0-4.4.4)上都可以,但是在Android L预览(以及Android Lollipop AOSP构建)上没有声音,也没有错误。 Here is my code: 这是我的代码:

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();
        }

    }
 });

How long is the sound effect you are trying to play? 您要播放的音效多长时间?

In my experience, i could not get any .wav files that were shorter than 0.2s to produce sound on Lollipop, where in other versions, 4.0 - 4.4.4, they played fine. 以我的经验,我无法获得任何短于0.2s的.wav文件来在Lollipop上产生声音,而在其他版本(4.0-4.4.4)中,它们可以正常播放。 I got around this by using Audacity (or some other audio manipulation tool) to pad the end of the sound effect with silence. 我通过使用Audacity(或其他音频处理工具)解决了这一问题,使声音效果的末端保持沉默。 Once they were >= 0.2s, they played on Lollipop with no problem. 一旦> = 0.2s,他们就可以毫无问题地在棒棒糖上演奏。

I do not know if that is your problem, but you might want to give it a shot. 我不知道这是否是您的问题,但您可能想尝试一下。

There is a reported issue here https://code.google.com/p/android/issues/detail?id=77860 这里有报告的问题, 网址为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 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM