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

隐身守侯 提交于 2019-12-11 03:20:50

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!