cordova-plugin-background-mode icon indicating copy to clipboard operation
cordova-plugin-background-mode copied to clipboard

When Application Launch, Music Player Stops in Ios

Open jagan27101986 opened this issue 5 years ago • 10 comments

When the application starts in IOS after Splash Screen, the music player of IOS is stopped working. We are using Ionic 4 application. Please advise how to resolve the issue.

jagan27101986 avatar Nov 13 '19 23:11 jagan27101986

same problem

andreveigaelias avatar Nov 18 '19 21:11 andreveigaelias

Hi, look at: https://stackoverflow.com/questions/38690103/cordova-sounds-stop-background-music Is it fix for that?

kissk01 avatar Nov 19 '19 13:11 kissk01

I resolved the issue by adding the following code [session setCategory:AVAudioSessionCategoryAmbient error:NULL]; in - (void) configureAudioSession method. Everthing works as expected.

@katzer - Could you please update in the file; so everytime i dont have have to copy and paste it.

jagan27101986 avatar Nov 22 '19 00:11 jagan27101986

I resolved the issue by adding the following code [session setCategory:AVAudioSessionCategoryAmbient error:NULL]; in - (void) configureAudioSession method. Everthing works as expected.

@katzer - Could you please update in the file; so everytime i dont have have to copy and paste it.

I have a same problem. I tried your solution but it does not work for me. Which file did you modify?

mehdis34 avatar Nov 26 '19 08:11 mehdis34

FileName - APPBackgroundMode.m Copy and paste this method /**

  • Configure the audio session. */
  • (void) configureAudioSession { AVAudioSession* session = [AVAudioSession sharedInstance];

    // Don't activate the audio session yet [session setActive:NO error:NULL];

    // Play music even in background and dont stop playing music // even another app starts playing sound [session setCategory:AVAudioSessionCategoryPlayback error:NULL];

    [session setCategory:AVAudioSessionCategoryAmbient error:NULL];

    // Active the audio session [session setActive:YES error:NULL]; };

jagan27101986 avatar Nov 26 '19 23:11 jagan27101986

FileName - APPBackgroundMode.m Copie e cole este método / **

  • Configure a sessão de áudio.

    • /
  • (vazio) configureAudioSession { AVAudioSession * session = [AVAudioSession sharedInstance]; // Não ative a sessão de áudio ainda [session setActive: NO error: NULL]; // Toca música mesmo em segundo plano e não para de tocar // outro aplicativo começa a reproduzir som [session setCategory: AVAudioSessionCategoryPlayback error: NULL]; [sessão setCategory: erro AVAudioSessionCategoryAmbient : NULL]; // Ativa a sessão de áudio [session setActive: YES error: NULL]; };

@jagan27101986 do you use cordova-music-controls? How do you control the media you're playing? ios overwrites the media controls automatically, i have been struggling for weeks...

paulovargatt avatar Nov 27 '19 01:11 paulovargatt

The solution is only about when opening the application, the music player or any third party application stops playing the file. However, this has nothing to do with music controls.

jagan27101986 avatar Dec 02 '19 23:12 jagan27101986

@katzer - Could you please add the line [session setCategory:AVAudioSessionCategoryAmbient error:NULL]; and update the git hub repo ?

jagan27101986 avatar Dec 02 '19 23:12 jagan27101986

i think this Plugin is not maintained anymore, so i decided to create a new one and fix this Issue. It also has a Ionic Wrapper, so go ahead and use this: https://github.com/HansKrywaa/cordova-plugin-advanced-background-mode

EinfachHans avatar Feb 09 '20 20:02 EinfachHans

@HansKrywaa Thanks a lot your plugin saved me a lot of time. appreciate it man

bassm avatar Aug 21 '20 06:08 bassm