I am building an iOS/Android app using Cordova and Ionic and I'm in the unfortunate position where I cannot test on a physical iPad and have to rely on the iOS Simulator for testing. It was just made known to me that this app does not play audio through the speakers when headphones are NOT plugged in, like you would expect, but other Cordova (non-Ionic) apps work fine on both speakers and headphones.
I am on: Cordova v5.1.1, and Ionic v1.0.0-beta.9
I am also using this Cordova plugin for native audio:
de.neofonie.cordova.plugin.nativeaudio 3.1.0 "Cordova Native Audio"
The audio works perfectly fine on my Nexus 7, OS X/Windows browsers, and the iOS Simulator (if there is a way to simulate plugging and unplugging headphones, that would be great but I have not found an option like that).
Here is some code for what I am using for audio:
Preloading one of the files:
//First is the name of the file to play
window.plugins.NativeAudio
.preloadSimple(first, 'audio/' + first + '.mp3', function(msg){}, function(msg) {
console.log('NativeAudio error: ' + msg);
});
Playing the file:
window.plugins.NativeAudio.play(id);
The code above works perfectly fine, it's just that the iPad does not seem to want to play out of the speakers for some reason.
Old question, but I just ran into a similar issue on Ionic 3 with the same plugin and ended up here, so I thought maybe this will help someone at some point.
I have found this plugin to play sounds over the speaker only when the phone's mute switch is off.