Search code examples
ioscordovaaudiophonegap-pluginscordova-plugins

Phonegap media stops system music


Phonegap media play method has a magic option playAudioWhenScreenIsLocked = false that does good job:

  1. Prevents app music from playing when app is in background;
  2. Makes app music obey the hardware "mute" button: without this option your app will ignore if user device is muted and play sound anyway.

But there is third hidden magic in this option. It stops current playing song from native Music app. Most of all it's annoying when I want to play short single sound.

Actually I would like to implement this scenario:

  1. Music: Check if system music is playing on the app start. If it is not, play my app music, otherwise let user enjoy his own media.
  2. Sound FX: Just play my little sound once and don't spoil anything.
  3. And never play anything in background and when device is muted! Even if system Music app can let itself do so.

Has anyone managed to do something similar? Thank you.


Solution

  • Ended up using https://github.com/floatinghotpot/cordova-plugin-nativeaudio (https://build.phonegap.com/plugins/2291)

    Be aware: simple sound effects are not working in Simulator.