Fix audio session

This commit is contained in:
Thomas Ricouard 2024-01-07 17:52:28 +01:00
parent 2c7ca2ca81
commit c4c86e1434
2 changed files with 10 additions and 11 deletions

View File

@ -83,7 +83,8 @@ class AppDelegate: NSObject, UIApplicationDelegate {
func application(_: UIApplication,
didFinishLaunchingWithOptions _: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool
{
try? AVAudioSession.sharedInstance().setCategory(.ambient)
try? AVAudioSession.sharedInstance().setCategory(.ambient, options: .mixWithOthers)
try? AVAudioSession.sharedInstance().setActive(true)
PushNotificationsService.shared.setAccounts(accounts: AppAccountsManager.shared.pushAccounts)
return true
}

View File

@ -78,19 +78,9 @@ public struct MediaUIAttachmentVideoView: View {
viewModel.preparePlayer(autoPlay: isFullScreen ? true : preferences.autoPlayVideo,
isCompact: isCompact)
viewModel.mute(preferences.muteVideo)
DispatchQueue.global().async {
try? AVAudioSession.sharedInstance().setCategory(.playback, options: .duckOthers)
try? AVAudioSession.sharedInstance().setActive(true)
}
}
.onDisappear {
viewModel.pause()
DispatchQueue.global().async {
try? AVAudioSession.sharedInstance().setCategory(.ambient, options: .mixWithOthers)
try? AVAudioSession.sharedInstance().setActive(true)
}
}
.onTapGesture {
if !preferences.autoPlayVideo && !viewModel.isPlaying {
@ -111,6 +101,11 @@ public struct MediaUIAttachmentVideoView: View {
}
}
.onAppear {
DispatchQueue.global().async {
try? AVAudioSession.sharedInstance().setActive(false, options: .notifyOthersOnDeactivation)
try? AVAudioSession.sharedInstance().setCategory(.playback, options: .duckOthers)
try? AVAudioSession.sharedInstance().setActive(true)
}
if isCompact || !preferences.autoPlayVideo {
viewModel.play()
}
@ -121,6 +116,9 @@ public struct MediaUIAttachmentVideoView: View {
viewModel.pause()
}
viewModel.mute(preferences.muteVideo)
try? AVAudioSession.sharedInstance().setActive(false, options: .notifyOthersOnDeactivation)
try? AVAudioSession.sharedInstance().setCategory(.ambient, options: .mixWithOthers)
try? AVAudioSession.sharedInstance().setActive(true)
}
}
.cornerRadius(4)