I'm using the YouTubeSDK to play YouTube videos in my app found here: https://github.com/gilesvangruisen/Swift-YouTube-Player
However, when the user presses home I want the sound to keep playing in the background. https://github.com/youtube/youtube-ios-player-helper/issues/38
I'm currently trying this in the App Delegate
(awful conversion) in the didFinishLaunchingWithOptions
:
let sessionEror:NSError?
do {
let playBG = try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback, withOptions: .DefaultToSpeaker)
} catch let error as NSError {
print("ERROR")
}
And this is in it's own function in the same file:
func playerView(YTPlayerView: YTPlayerState, didChangeToState: YTPlayerState) {
switch {
case YTPlayerState.Paused:
YTPlayerState.Playing,
break
}
}
Any idea how to keep playing the sound in the background using the YouTube SDK? Also, is it possible to just play the sound in the background and not the video?
Any and all help is appreciated.