简体   繁体   English

Howler JS 2.0-Cordova,Android,设备上未播放声音

[英]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 我正在尝试在移动混合应用程序(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. 在Chrome移动模拟器中,一切正常,但在设备上无法播放声音。 I checked app permissions in manifest.xml and for sound playing is not required any special permissions. 我在manifest.xml中检查了应用程序权限,并且不需要任何特殊权限来播放声音。

What i'm doing wrong? 我做错了什么?

Thanks for any help. 谢谢你的帮助。

Try to use Media Plugin offered by Cordova : 尝试使用Cordova提供的Media Plugin:

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_asset”,然后添加声音文件的路径。 Android needs a absolute path to find the file and play it. Android需要找到文件并播放的绝对路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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