iOS 9.2 cordova-plugin-media no sound [fix on the way]

Greeting IonicFramework Developers,

I’ve been bashing my head against the wall over the last day trying to figure out why cordova-plugin-media does not play back any sound on ** iOS 9.2 (iPhone 6 + 6s).

After debugging cordova-plugin-media/src/ios/CDVSound.m on ln 352, 355, looks like the avPlayer object doesn’t have a handle to the sound resource:

I’ve raised a Jira ticket to Apache Cordova to get this fixed:

However if you need sound ASAP in your apps, just make this small change to the following files and rebuild your app:

[root]/plugins/cordova-plugin-media/src/ios/CDVSound.m, ln 352, 355
[root]/platforms/ios/Sleepy/Plugins/cordova-plugin-media/CDVSound.m, ln 352, 355


 if (audioFile.rate != nil){
    float customRate = [audioFile.rate floatValue];
    NSLog(@"Playing stream with AVPlayer & custom rate");
} else {
    NSLog(@"Playing stream with AVPlayer & custom rate");
    [avPlayer play];


if (audioFile.rate != nil){
    float customRate = [audioFile.rate floatValue];
    NSLog(@"Playing stream with AVPlayer & custom rate");
    [audioFile.player setRate:customRate];
} else {
    NSLog(@"Playing stream with AVPlayer & custom rate");
    [audioFile.player play];

Hope this helps anyone out there struggling with sound.



Thought I was going crazy. Thanks for posting the fix.

No worries revie!
What tipped me off was the HTML5 <audio> tag was still working on the device!
Rage face! ლ(ಠ益ಠლ)

Thanks for this. Are the Cordova guys even testing what they do before releasing? I am baffled… wasted 3 hours chasing ghosts

I’m sure the dudes at Cordova are on top of things.

However digging into master branch, looks like the start of those avPlayer changes happened around 29 July 2015:

So local resource playback might of been broken for a while???

Thank you so much for posting this. I wasted a few hours but that could have easily become days.

Not a problem, it appears that a regression bug was introduce sometime last year when the streaming feature was introduced.

Have a look at the Jira ticket, as there’s been a lot of back and forth with other developers on a official fix (this was only a temporarily measure):

OMG, thanks for the temp fix. Made my day!

@johnnydong - Does media.getCurrentPosition() works on your app?

In my app i use local audio play and streaming audio play. There is a way that will work both? As we have to wait for the official release?
Thank you.

Hi Pasinetti,

The dev that added the breaking change for Streaming suggested using file:// or cdvfile:// (which I obviously tried last month before providing the hack).

The were other devs contributing to the main Jira ticket, but it appears to be stalled at the moment. You’re welcome to join in and help out.


Hi Ionicoser,

Apologies for the late response, been preoccupied with other activities.
I was actually more happy to get the sound file to play and didn’t hook the other methods in like getCurrentPosition :slight_smile:

The dev that put the original streaming code in insist everything still works (streaming, local, record) - obviously doesn’t, hence the hack.
Might pick this up again (on the weekend) as the Jira ticket has kinda stalled a bit and there’s a lot of noise about it working without clear examples of implementation.


Hi johnnydong,
Thank you for the answer, unfortunately i’m not an ios developer and i don’t know swift. But, is possibile insert an “if” in the code, that check if file are streaming(src start with http:\ or https:\) or local file(src start with ) and use two different player?
It’s just my idea, i don’t know if could be right.


Just spent 2+ days scratching my head over this one. Thanks for posting a workaround.

The fact that the cordova plugin site doesnt mention this showstopping bug in any way is really frustrating. Anyone who is coming to the site now is going to be building for iOS 9.2 or 9.3 and they’ll be completely unaware until they spend hours searching for why their device and/or seems broken.

I reported 4 months ago cordova-plugin-media bug when playing on Android on cordova bug list, and never got a reply. I had to create a complex workaround to make it.

@johnnydong the jira issue status is ‘resolved’ and there’s a new release v2.3.0 on github but it hasnt been pushed to npm yet (latest npm version is 2.2.0).

i was able to install the latest stable version of the plugin using

cordova plugin add

which installed a couple other dependencies:


which i presume allow for npm and git installed plugins to work together?

anyway, its working on Android (specifically on 6.0.1) and iOS (9.3.1).

My build works on Android but not iOS. I see this in my Xcode logs. Do you guys have any advice?

2016-07-13 18:07:38.670370 SpotShuffle[819:101801] [] <<<< FIGSANDBOX >>>> Path </private/var/mobile/Containers/Data/Application/CA12E3E3-BB41-45D7-8F4E-DE52BEFDFA4E/tmp/MediaCache> could not be converted by realpath() (requires all elements of path are present)
2016-07-13 18:07:38.671385 SpotShuffle[819:101801] [] __InternalSandboxRegisterURL_block_invoke signalled err=-12780 (kFigBaseObjectError_ParamErr) (Could not obtain realpath for specified URL) at /BuildRoot/Library/Caches/ line 590

I have installed Cordova media 2.3.0 version. When I launch the ios emulate. I can here audio. But not on andriod and ionic view app.

As mentioned above in this forum. changed in .h file. But still same problem.

Can someone please help me.

Hello everyone
I’ve added the lines in CDVSound.m file but still audio doesn’t play. My audio link shows like the following:-


I’ve tried the following

var audio_url = "file:///var/mobile/Containers/Data/Application/B932CD99-B274-4D5D-A9C2-032F77A1DDF4/Documents/hello.mp3";

var m = new Media(audio_url);;

Any help is appreciated.

Hi @jkcybertron (and any developer who’s come across this post),

It’s been months since I looked at this post and it appears there are still some developers experiencing the same issue I had back in March.

We’ve skipped multiple versions of iOS (iOS9.2 to 10.1), and cordova-plugin-media (2.2.0 to 2.4.0) so I thought i’d give the newer modules a try and it appears to be fixed!!!

Instead of providing small snippets of code as an answer, I’ve hacked together a test app (minus unit test :frowning:) for you guys to try out. Only tested for iOS (not sure what’s going to happen with Android…)
(Still written in Angular 1.0, but you should get the gist of what’s happening - when i get more time, i’ll convert it to Angular 2.0).

Repo for the Demo:

To build, just run “npm start” and it should trigger:

npm install
bower install
ionic state restore
ionic build ios
ionic emulate ios

And just to emphasis, there’s no sound when testing via a webpage (ionic serve)
Please build and emulate or deploy to a device to test for audio.

Hopefully you guys will find this useful.