From 0468ad942294590d49609d538c7a6c08fc50b15e Mon Sep 17 00:00:00 2001 From: Matteo Matassoni <4108197+matax87@users.noreply.github.com> Date: Thu, 1 Feb 2024 17:11:33 +0100 Subject: [PATCH] Fixes problems with suspended audio when the app starts and shows the intro video --- .../IntroFeature/IntroViewController.swift | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/NOICommunity/IntroFeature/IntroViewController.swift b/NOICommunity/IntroFeature/IntroViewController.swift index 8d01bed..99573c7 100644 --- a/NOICommunity/IntroFeature/IntroViewController.swift +++ b/NOICommunity/IntroFeature/IntroViewController.swift @@ -56,6 +56,7 @@ final class IntroViewController: UIViewController { ) // Play video + enableAudioMix() player.play() } @@ -85,5 +86,32 @@ final class IntroViewController: UIViewController { private extension IntroViewController { @objc func playerDidFinishPlaying(_ notification: NSNotification) { didFinishHandler?() + disableAudioMix() + } + + func enableAudioMix() { + let session = AVAudioSession.sharedInstance() + do { + try session.setCategory(.playback, + mode: .default, + options: [.mixWithOthers] + ) + try session.setActive(true) + } catch { + print(error) + } + } + + func disableAudioMix() { + let session = AVAudioSession.sharedInstance() + do { + try session.setCategory(.playback, + mode: .default, + options: [.mixWithOthers] + ) + try session.setActive(false, options: .notifyOthersOnDeactivation) + } catch { + print(error) + } } }