I am developing an application with Cordova and AnuglarJS
I'm using the Cordova Media plugin, but I have a problem that I can not solve and it only happens in iOs, in other platforms it works fine
I have a background audio loop, and another audio when opening a pop up that only sounds once.
While I am playing the background audio if the other audio is playing, at the end of this audio the background audio is also stopped
Any ideas on how to solve it?
Thank you very much
EDIT:
backgroundMusic = new Media(path,
function () {
//success (object has completed the current play, record, or stop)
},
function (err) {
//error
console.log("playAudio():Audio Error: " + err);
},
function (status) {
//status, volvemos a lanzar el sonido si se para
if(status == Media.MEDIA_STOPPED){
//trapi para que en mobile el audio no se pare y haga bien el loop
backgroundMusic.seekTo(1);
backgroundMusic._position = 0;
//hasta aqui el trapi
backgroundMusic.play({playAudioWhenScreenIsLocked : false});
}
}
);
I create the short audio
if(openPopUp == undefined){
openPopUp = new Media(pathPopUp,
function () {
//success (object has completed the current play, record, or stop)
},
function (err) {
//error
console.log("playAudio():Audio Error: " + err);
},
function (status) {
//status, volvemos a lanzar el sonido si se para
if(status == Media.MEDIA_STOPPED){
//trapi para que en mobile el audio no se pare y haga bien el loop
openPopUp.seekTo(1);
openPopUp._position = 0;
}
}
);
}
I play background audio
backgroundMusic.play({playAudioWhenScreenIsLocked : false});
then I have a function that performs popup audio
$rootScope.$on("playOpenPopUp", function(){
playOpenPopUp();
});
function playOpenPopUp(){
openPopUp.play({playAudioWhenScreenIsLocked : false});
}
I have all this in a controller, as you can see there is a listener in this controler that executes the play of the audio, other controllers launch this event so that it captures it and makes the play.