Playing local app sound with Cordova media (Blackberry)

97 views Asked by At

I am using Webworks for Blackberry 10 and using cordova too.

When doing this, the mp3 is played:

var url = "http://audio.ibeat.org/content/p1rj1s/p1rj1s_-_rockGuitar.mp3";

var my_media = new Media(url,
    // success callback
    function () {
        console.log("playAudio():Audio Success");
    },
    // error callback
    function (err) {
        console.log("playAudio():Audio Error: " + err);
    }
);
// Play audio
my_media.play();

(If you can explain me why it does not go to the success callback, it will be nice. :-))

But if I do this:

var url = "local.mp3";

var my_media = new Media(url,
    // success callback
    function () {
        console.log("playAudio():Audio Success");
    },
    // error callback
    function (err) {
        console.log("playAudio():Audio Error: " + err);
    }
);
// Play audio
my_media.play();

Nothing is played! No error, no nothing. I read that I need to specify a local directory. I then tried "cordova.file.applicationDirectory + "www/sounds/local.mp3", but for some reason, the applicatioDirectory gives me "undefined"!

I also saw this site, but don't know what to put for Blackberry path and iOS.

Any clue why? How can I fix that?

Big thanks in advance guys!

2

There are 2 answers

0
Dietmar On

If your audio file is www/audio/audilofile.mp3, then the url should be:

var url = "local:///audio/soundfile.mp3";

Alternatively, you can get the full path using the IO Plugin:

var url = blackberry.io.home + "/../app/native/audio/audiofile.mp3";

Take a look also at http://developer.blackberry.com/native/documentation/device_platform/data_access/file_system.html for understanding the directory structure of BlackBerry apps.

I also don't know why the callbacks don't get called. This is what I was searching for when I found this question.

0
Kris Braun On

I'm also seeing no callbacks. From what I can see from the plugin source (https://github.com/apache/cordova-plugin-media/blob/master/src/blackberry10/index.js), the callbacks are never called for BlackBerry.