ionic-team / cordova-plugin-ionic-webview

Web View plugin for Cordova, specialized for Ionic apps.
Apache License 2.0
487 stars 395 forks source link

Audio pauses when going into background even though the proper settings are performed #26

Open ScottMBerger opened 6 years ago

ScottMBerger commented 6 years ago

This is working as intended on UIWebView and doesn't when trying with WKWebView. I have tested using the Web Audio API. The proper configuration to enable background audio is set. https://github.com/AubreyHewes/cordova-background-audio

ghenry22 commented 6 years ago

if you are using web audio / HTML5 audio tag then this is a known problem. WKwebview completely stops processing when sent to the background.

If you use the media plugin then sounds will continue to play if it is started before going to the background but the native code gets out of sync with the javascript code then.

Try installing the background mode plugin to keep wkwebview running when backgrounded. If your purpose is audio usage though then you may have to hack the background mode plugin a bit as it continually plays a silent sound file to keep the app alive by default. I have a forked copy with that code removed so that it wont' tread all over your apps audio.

ghenry22 commented 6 years ago

actually you shouldn't need that plugin. Just install the standard media plugin or use web audio and set the background audio capability to enabled in xcode and you should be good for background audio.

with wkwebview currently you would also need the background mode plugin to keep it running in the background.

nickh364 commented 5 years ago

actually you shouldn't need that plugin. Just install the standard media plugin or use web audio and set the background audio capability to enabled in xcode and you should be good for background audio.

with wkwebview currently you would also need the background mode plugin to keep it running in the background.

In iOS 13 the audio will only play for like a minute before stopping with this console message " [ProcessSuspension] Background task expired while holding WebKit ProcessAssertion (isMainThread? 1)." it worked fine before iOS 13 but it sounds similar to this. What did you have to do to the background mode plugin to play audio in the background? I tried commenting out the "[audioPlayer play];" and "[audioPlayer pause];" lines and it still stops playing.

jerodfritz commented 4 years ago

With iOS 13 I cannot get the audio to continue playing for more than 30 seconds. Has anyone found a solution to this?

nickh364 commented 4 years ago

With iOS 13 I cannot get the audio to continue playing for more than 30 seconds. Has anyone found a solution to this?

I could not find a way around this. I ended up switching to using the Cordova Media plugin

jerodfritz commented 4 years ago

@nickh364 thanks for the reply. I figured I would have to convert to something. With Cordova Media are you able to load a remote file for playback? Would you mind sharing a snippet of how you are loading the audio file for playback?

nickh364 commented 4 years ago

Yes. I use it for our podcasts and Icecast streams.

You should be able to get a file playing like this

this.player = this.media.create(url);
this.player.play();

Here are the Docs https://ionicframework.com/docs/native/media https://github.com/apache/cordova-plugin-media

For the Icecast streams to work on iOS I had to make a change. Here is that post https://github.com/apache/cordova-plugin-media/issues/256