1

I have the following situation:

  • I have phonegap project.
  • I build it using "cordova build browser" and then run via "cordova run browser".
  • The piece of code does not work because it seems that filename.mp3 does not exist in sounds/ dir which is in root dir (i.e. 'www' dir):

    path = 'sounds/filename.mp3'; 
    if (OS === "Android") {  
        path = '/android_asset/www/' + path;
    } else {
        //
    }
    
    //Open music file
    var mediaFile = new Media(path,
        function() { console.log("Playing"); },
        function(error) { console.log("Error:" + JSON.stringify(err)); },
        function(st) { if (st === Media.MEDIA_STOPPED && exit === !true) {
            //console.log("audio status changed");
            mediaFile.play();
        }}
    );
    
    mediaFile.play();
    
  • It does work on Android platform but on desktop log contains interesting thing:

    200 /js/lib/scorebar.js (/home/raian/my_project/platforms/browser/www/js/lib/scorebar.js) - as one can see we have both the link and the true path to the file (the same is true for many other resources like images or CSS files...);

    404 /sounds/filename.mp3 - here the true path is missing?

  • Question: is that possible to somehow add/include path to true mp3 file? It looks like mp3 file just has not been copied to sounds/ directory that may easily be somewhere in the filesystem and it is directly depends on how cordova run its server.

Peter Leontev
  • 107
  • 1
  • 8
  • My example code works. You can find it on github under [Phonegap-Media-Test](https://github.com/jessemonroy650/Phonegap-Media-Test) –  Sep 28 '15 at 01:18
  • I looked at your code. Am I right that it works only under Android and iOS? – Peter Leontev Sep 28 '15 at 08:44
  • Yes, you are correct. At the moment, it only works with Andriod and iOS. It will works with Windows as soon as I own a Windows device. It will likely work with Windows Universal. –  Sep 28 '15 at 20:42
  • I was asking about how to do the same thing on desktop browser because it seems there is a bug in cordova. – Peter Leontev Sep 29 '15 at 10:37
  • there are bugs in all the plugins. You might see them labelled *quirks* in the documentation. For the audio plugin, the paths to the audio file differ from platform to platform. You'll see that in my notes. The best thing to do is clone my code and build it. -- As for *phonegap desktop app*, I have not used it, so I can't give you any advice on that. -- If you are talking about the webbrowser, the phonegap plugin does NOT work with browsers. OTHERWiSE your last statement is not clear. –  Sep 29 '15 at 13:25
  • Thank you for detailed answer! > the phonegap plugin does NOT work with browsers. According to https://github.com/apache/cordova-plugin-media it does work on browsers otherwise it is not well written manual and that is really bad :( – Peter Leontev Sep 30 '15 at 13:38
  • it is not clear what "browser" means. Most modern browsers use the [HTML5 media API](http://www.w3.org/2010/05/video/mediaevents.html). Does the plugin use the HTML5 media API? **NO**. Near the top is says, * does not adhere to a W3C specification*. Well the *HTML5 Media API* is based on the W3C standard, but it says it does not comply with the standard. So, is it a documentation mistake? I would say yes. –  Oct 01 '15 at 03:13
  • Thank you again. It seems it is better to use some other way to play audio when using cordova... – Peter Leontev Oct 01 '15 at 19:46

0 Answers0