-
Notifications
You must be signed in to change notification settings - Fork 287
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix background music interruption on plugin init on Android and iOS #139
base: master
Are you sure you want to change the base?
Conversation
I just tried this and can verify it works on iOS |
hi @Rodmg I just discovered an issue with this PR fix. It works well in the case when say I'm listening to Spotify and then switch over to my app. Spotify keeps playing as intended. However it fails when my app is playing music and I hit the home button and put my app in the background. Note: Background Mode for Audio is enabled in XCode. And when I switch back to the master branch, my app keeps playing when put in the background. |
This PR should be fixed asap. Before applying the patch, every audio from html5 was beeing interrupted. (even playing videos was paused). After applying this patch, I can run those at the same time. Good work! |
@shi11 You are describing a different case, whereas your app is the one that should play in the background. The fix and this issue is about not stopping possibly running background music (switched roles of the apps). |
@mxmzb correct - audio from my app should continue in the background. This is existing behavior in the master branch. Unfortunately this PR breaks that. I would love for this patch to work as well as not break existing behavior. |
We are now maintaining a forked version wizpanda/cordova-plugin-nativeaudio of this plugin which includes commits from this PR. |
Hey, really appreciate you maintaining a fork with these changes. Has saved me a lot of time! I'm trying to use it in a project but can't get the sound to play on iOS for some reason. The app is basically a timer that plays a sound when it reaches 0. Was working fine using cordova-plugin-nativeaudio 3.0.9 on npm but I got complaints about it stopping spotify/background music so needed an alternative. Using ionic native on ios12.2. My code is as follows: Preload the audio: And when the timer reaches 0: If I monitor the events, the are all triggered. As in, the audio seems to be preloaded, and thinks it is playing. Not getting any errors. However I never hear a sound. Any ideas what could be going wrong? |
I just tried with one of my app and it worked fine. Is it possible for you to create a fresh app & test that? |
@sagrawal31 many thanks for maintaining your fork of this repo. Unfortunately I don't see the Issues section in your repo so I don't know where to add my comments. |
Thanks @andrey3diq. We can make that as configuration for sure. |
This patch fixes background audio or music from other apps being interrupted when an app with this plugin was started, both on iOS and Android.
On iOS: Removed deprecated AudioSessionInitialize call and extra setCategory and setActive calls that where not really needed and where overriding the main initialization call.
On Android: removed the AudioManager requestAudioFocus call that is not really needed, playing audio will work fine without this call.