Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cordova sounds stop background music

Tags:

cordova

audio

mp3

I search a lot about my problem and I found no solution. In my app using Cordova, I play mp3 sounds. Everything is fine except when you played background music (mp3s, google music, ...), the sound stop the background music. I would like to not stop the background music when my sound is played.

I tried 3 differents methods:

1 - Plugin: cordova-plugin-media

When the sound play, the background music stops and do not restart at the end.

2 - Plugin: cordova-plugin-nativeaudio

Worst, the background music stops when I launch my application

3 - Using javascript function

var mySound = new Audio('sounds/entering.mp3');
mySound.play();

Works fine on Android, the sound is playing, the background music volume decrease and after the sound is finished, the volume of the background music come back to normal. On iOS, the background music stops and do not replay at the end.

Does anyone already had this problem?

Thanks!

like image 870
PatrickB Avatar asked Aug 01 '16 02:08

PatrickB


1 Answers

I created a cordova plugin to handle this situation: https://github.com/davidfig/cordova-allow-background-audio

cordova add plugin cordova-allow-background-audio

The plugin was based on answers I found here: iphone app allow background music to continue to play

like image 77
David Figatner Avatar answered Oct 19 '22 08:10

David Figatner