Skip to content Skip to sidebar Skip to footer

Ibm Worklight 6.1 - Unable To Play A Local Media File Using Cordova

Tested in Android Emulator. I am trying to use Cordova Media API to manage the playing of audio stored locally within the Worklight project. Initially I attempted to update my proj

Solution 1:

The sample code provided at Cordova's website works, however it looks like the URL they point to is broken. I've replaced it with another and then it worked.

As for playing a local media file, you need to provide the full path to the media file's location where it'll be in the generated Android project. For example, if you create a common\audio folder in the Worklight application and place a .mp3 file in it, you need to use the following path (in the HTML or JavaScript, or however you'd like...):

<ahref="#"onclick="playAudio('/android_asset/www/default/audio/myMediaFile.mp3');">Play Audio</a>

This is because in Worklight, every application is considered a "skin". There is the "default" skin, and if you add another, it will have its own folder in the www folder.

Sample project: Android Cordova Media API


P.S., I do not find it a good practice to copy-paste an example as-is from Cordova to a Worklight project.

  • There is no cordova.js to link to.
  • It is redundant to listen to deviceready as this is handled internally. Putting it this way: if you've reached wlCommonInit(), you're good to go.
  • There is no need to add extra permissions, unless you want what those permissions offer...

Post a Comment for "Ibm Worklight 6.1 - Unable To Play A Local Media File Using Cordova"