This is a migrated thread and some comments may be shown as answers.

How to Play a Small Sound File

2 Answers 241 Views
Apache Cordova
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Kelly
Top achievements
Rank 1
Kelly asked on 07 Apr 2014, 04:07 PM
Hello,

I could use some advice on how to play a small MP3 audio file using the Cordova Media plugin (v 0.2.5). The following test code plays in the simulator when called maybe 3 out of 10 times, then never plays again.  It never plays on an iPhone.  Even when it does play in the simulator, every call throws an error in the console: "Uncaught module cordova/plugin/Media not found". cordova.js: 262.  I've tried specifying the success and error functions to the Media object, but they are never called.

var test = function () {
    media = new Media("media/whoosh.mp3");
    media.play({numberOfLoops: 1});           
};

On a real phone, I can get the call to play if I use a Uri of a remote file on the net, but I can't get it to play a local file. I've tinkered with the path to the file, making sure to use an absolute path to the file, but no joy.

Also, since I've enabled the media plugin to the project in AppBuilder, every Save crashes the simulator with a System.InvalidOperationException.

Thank you,

Kelly

2 Answers, 1 is accepted

Sort by
0
Accepted
Tina Stancheva
Telerik team
answered on 10 Apr 2014, 04:20 PM
Hello Kelly,

The Cordova Media plugin is not fully supported within the AppBuilder Simulator and I believe this might be the cause behind the "Uncaught module cordova/plugin/Media not found" error you're receiving. You can find a list of all supported core, integrated and custom Apache Cordova plugins in the Simulator Known Limitations article.

However, you should be able to play a local file in an application utilizing the Cordova Media plugin once you deploy it on an iOS device (as an actual app package and not in the AppBuilder companion app). You only need to keep in mind that when the src of the media is a file name or simple path, iOS will search in the www for the file and then in the application documents/tmp directory (as explained in the Media documentation). This means that if you add a media folder with a media file in your project, then by default they will be placed within the www folder when the application is deployed on a device. However, please keep in mind that the AppBuilder Companion App cannot deploy the media file in its www folder as this folder cannot be modified after an app is deployed. This is why it instead adds the media folder and its content under the documents folder of the application and therefore you can't test your project in the AppBuilder Companion App when the media src is a relative path to the media file.

I attached a sample project for your convenience. I followed the steps described in the Run App on Remote Devices tutorial and deployed the application on an IPhone device where I was able to successfully play the media file.

As for the simulator crashing I want to thank you for this feedback. We were able to reproduce the issue and we logged it as a bug in our system. I added 500 points to your account as a small token of gratitude for your report.

Regards,
Tina Stancheva
Telerik
 

Share what you think about AppBuilder and Telerik Platform with us in our feedback portal, so we can become even better!

 
0
Kelly
Top achievements
Rank 1
answered on 14 Apr 2014, 09:31 PM
Tina,

Thank you, I rebuilt the package and deployed it using iTunes this time, and it works - the relative media file specs are fine.  Previously, I had deployed using Diawi.com.  I'm not sure if that made any difference, but no matter, since it works now.

Kelly
Tags
Apache Cordova
Asked by
Kelly
Top achievements
Rank 1
Answers by
Tina Stancheva
Telerik team
Kelly
Top achievements
Rank 1
Share this question
or