2017-04-02 54 views
0

我正在使用我的第一個Android應用程序,您在其中按下按鈕並播放.wav聲音,它在我運行phonegap服務器時效果很好應用程序來測試它,但是當我將它打包爲帶有phonegap的.APK並將其安裝到手機上時,它不會播放.wav聲音。使用PhoneGap測試PhoneGap時播放的聲音,但使用PhoneGap製作時不會播放

$('.sound1').on('touchstart', function() { 

var thissound = new Audio(); 
thissound.src = $(this).attr('key'); 
thissound.play(); 
}); 

回答

0

我所做的更改不是新的audio();我做了新的媒體();並在閱讀Playing Local Sound In Phonegap後發現它可能與需要成爲絕對本地路徑的路徑有關,它現在在真正打包的應用程序中工作。我也發現你也需要使用media.release();因爲finite number of times you can play a sound.

$('.sound1').on('touchstart', function() { 
    var path = window.location.pathname; 
    path = path.substr(path, path.length - 10); 
    var finalpath = 'file://' + path; 
    var key = $(this).attr('key'); 
    var thissound = new Media(finalpath + key, function onSuccess() { 
    // release the media resource once finished playing 
    thissound.release(); 
    }); 
    thissound.play(); 
});