2014-11-08 241 views
0

我想從所有Android版本(4.0-4.4.4)上使用MediaPlayer原始文件夾播放wav文件,但它在Android L預覽(和Android棒棒糖AOSP版本)沒有聲音,也沒有錯誤。 這裏是我的代碼:Android MediaPlayer不從原始文件夾播放wav文件(Android棒棒糖)

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

    } 
}); 
+0

剛剛檢查官方android棒棒糖,仍然無法正常工作。 – Alex 2014-11-16 08:26:07

回答

-1

這裏有一個報告的問題https://code.google.com/p/android/issues/detail?id=77860

Reported by [email protected], 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 [email protected] 
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: [email protected] 
Labels: 18080636 
0

有多久音效您要玩嗎?

根據我的經驗,我無法獲得0.2秒以內的任何.wav文件來製作棒棒糖上的聲音,其他版本的4.0-4.4.4播放聲音時效果都很好。我通過使用Audacity(或其他一些音頻操作工具)來緩解聲音效果的結尾。一旦他們> = 0.2s,他們玩棒棒糖沒有問題。

我不知道這是否是您的問題,但您可能需要試一試。