简体   繁体   中英

Howler JS 2.0 - sound is not playing on cordova, android, device

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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