我正在使用我的第一个android应用程序,在其中按下按钮时它会播放.wav声音,当我运行phonegap服务器应用程序对其进行测试但随后将其打包为带有phonegap的.APK并安装时,效果很好在我的手机上,它不会播放.wav声音。
$('.sound1').on('touchstart', function () {
var thissound = new Audio();
thissound.src = $(this).attr('key');
thissound.play();
});
最佳答案
我所做的更改代替了新的audio();我做了新的Media();在阅读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();
});
关于android - 使用phonegap应用进行测试时,声音会在PhoneGap中播放,但在使用PhoneGap Build构建声音时不会播放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43171766/