2017-04-02 58 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(); 
});