简体   繁体   English

声音无法在android中播放

[英]Sound cannot be played in android

Why sound cannot be played in android version 4.1? 为什么在Android 4.1中无法播放声音? When in browser sound can be played very well. 在浏览器中时,声音可以很好地播放。

i am trying to play the sound when the card match and when the card mismatch. 我试图在卡匹配和卡不匹配时播放声音。

this is my code: 这是我的代码:

function checkPattern() { 
    if (isMatchPattern()) { 
        $(".card-flipped").removeClass("card-flipped").addClass("card-removed"); 
        if(document.webkitTransitionEnd){ 
            $(".card-removed").bind("webkitTransitionEnd",  removeTookCards); 
        }else{ 
            playAudio("mp3/WinLevel.mp3"); 
            removeTookCards(); 
        } 
    } else { 
        $(".card-flipped").removeClass("card-flipped"); 
        playAudio("mp3/WrongLose.mp3"); 
    } 
} 

Did i missed anything? 我错过了什么吗?

To play a sound try this method: 要播放声音,请尝试以下方法:

MediaPlayer mp = MediaPlayer.create(YourActivity.this, R.raw.mysound);
            mp.setOnCompletionListener(new OnCompletionListener() {
                    @Override
                    public void onCompletion(MediaPlayer mp) {
                        // TODO Auto-generated method stub
                        mp.release();
                    }
                });   
                mp.start();

This is the best way I found to play a sound in Android. 这是我发现在Android中播放声音的最佳方式。 Hope it helps! 希望能帮助到你!

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

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