Search code examples
javascriptangularjscordovaaudiohowler.js

Howler.JS + Angular - path for playing sound file


I'm trying to play mp3 file in cordova + ionic hybrid app.

Sound is stored in:

www/sounds/dubstep/sound.mp3

And i'm trying to play file from service placed in /www/scripts/services/global.js using following code:

var sound = new Howl({
     src: ['sounds/dubstep/sound.mp3'],
     onend: function() {
         console.log('Finished!');
     },
     onloaderror: function() {
        console.log('Error!');
    },
});

sound.play();

But it is always throwing onloaderror.

How I should set path in right way?

Thanks for any help.


Solution

  • According to github documentation you should be using urls instead of src:

    var sound = new Howl({
        urls: ['sounds/dubstep/sound.mp3'],
        onend: function() {
            console.log('Finished!');
        },
        onloaderror: function() {
            console.log('Error!');
        },
    });
    

    Src: https://github.com/goldfire/howler.js/