I'm using YouTube iOS Helper Library to play a video inside a WKWebView
and I want the audio to continue playing even when HOME is pressed or lock key.
Capabilities tab looks like this:
I have also imported import AVFoundation
inside AppDelegate
and inside func applicationDidBecomeActive(_ application: UIApplication)
I have this code:
func applicationDidBecomeActive(_ application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
do {
try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback)
} catch {
// Handle setCategory failure
print(error)
}
}
When app enters background audio stops and I can not even resume it from control center.
For those who are searching for the similar solutions, want to tell, that play YouTube audio without displaying the video violates the terms of services of YouTube And your app will be rejected from App Store because of this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With