问题
i'm trying to play sound in mobile hybrid app (cordova, ionic, howlerJS v 2), https://github.com/goldfire/howler.js/tree/2.0
By this way:
$scope.playSelectedItem = function(index) {
try {
var fileName = $scope.selectedSounds[index].file;
var filePath = "sounds/" +fileName+".mp3";
console.log(filePath);
var sound = new Howl({
src: [filePath]
});
sound.play();
} catch(e) {
$scope.showAlert();
}
};
In Chrome mobile emulator everything works fine, but on device is sound not playing. I checked app permissions in manifest.xml and for sound playing is not required any special permissions.
What i'm doing wrong?
Thanks for any help.
回答1:
Try to use Media Plugin offered by Cordova :
my_media = new Media('/android_asset/www/sound.mp3',
// success callback
function() {
WL.Logger.debug("playAudio():Audio Success");
},
// error callback
function(err) {
WL.Logger.debug("playAudio():Audio Error: " + JSON.stringify(err));
});
// Play audio
my_media.play();
Make sure to add '/android_asset' and then your path to the sound file. Android needs a absolute path to find the file and play it.
来源:https://stackoverflow.com/questions/27748697/howler-js-2-0-sound-is-not-playing-on-cordova-android-device