No promise returned with $cordovaMedia.newMedia


I am trying to use the ngCordova to play a sound. Here is the code:

function MusicCtrl($cordovaMedia) {
    var vm = this; = function() {
        var media = $cordovaMedia.newMedia("htc_windows_8.mp3").then(function() {
        }, function(err) {
          console.log("Failed: " + err);


For some reason, I don’t have “Success” or “Failed”. Why? (seems somebody has the same issue here ngCordova Media plugin not working)

But from my side, I have something in the console:

Error: 'undefined' is not a function (evaluating '')
dispatchEvent@[native code]

I am using a Blackberry Q10 for development with Webworks. The ngCordova worked for file transmission, but it seems the media one does not.

Thanks in advance for your comments!

nobody has some advices to give me to verify what is going on?

I haven’t used the Media plugin with ngCordova but in their docs it says that it is only supported on iOS, Android and WP.

I know the official docs says they support BlackBerry 10 but not sure if ngcordova does it.

Have you tried using the plugin directly without ngcordova?

Hi joseadrian,

Just retried plain cordova: = function() {
  // Play the audio file at url
  var url = "htc_windows_8.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; 

Nothing on the console and got this error from the phone:

Media Error
This media file is of an unsupported type or could not be loaded. It cannot be played.

I tried another sound type, wav and got the same thing. :frowning:

I guess if you put a file that doesn’t exist you will get a message “File not found” but IF you get the same message as the one you got then MAYBE the path is not correct.

Also try with an external file from the phonegap examples => If THAT works then you probably need to fix your files.


I just tried the link that you suggested me and it worked! Still not going to my success callback though, but it plays the mp3.

So now, how come it does not play local application sound?

I found this page:

At the bottom of the article, he says:

On Android, if you’d like to play audio bundled with your application you would need to include /android_asset/ at the beginning of your path

Does this special path exists for Blackberry 10? I am a bit surprised to see that. Does it mean that you need to have different path depending of the OS you are targeting for? Not easy to be universal that way, don’t you think?

Well… I guess what the Media plugin provides is a cross platform way to reproduce audio files but just that. I don’t know. Ask the creators. Haha.

Reading the comments section, the author suggested someone to try this line to get the path of his app:


And concatenating it with the audio path, it should work.

myAudioFile = cordova.file.applicationDirectory + “www/path/to/the/audio/file.ext”;

If the audio plays, then just keep playing with the plugin.

I tried the applicationDirectory and it returned “undefined”!

I tried also “window.location.pathname”, did not work

Do you have the Fileplugin installed?

This may not be a reason but… are you testing on an emulator?

Yeah, just double check. Anyway, when adding the media plugin, it added the file one too (Blackberry Webworks tools)

How can I make sure that cordova and its plugin are correctly installed to my device?

And to answer your last question, I am testing on the device directly.