From 9242a859dfdb424ff93393db2030c4e19ff63012 Mon Sep 17 00:00:00 2001 From: CMK Date: Thu, 5 Aug 2021 18:16:50 +0800 Subject: [PATCH] fix: no audio when phone under Silence Mode issue. resolve #266 --- Mastodon/Scene/Share/ViewModel/VideoPlayerViewModel.swift | 4 ++-- Mastodon/Service/AudioPlaybackService.swift | 4 ++-- Mastodon/Service/VideoPlaybackService.swift | 1 - 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/Mastodon/Scene/Share/ViewModel/VideoPlayerViewModel.swift b/Mastodon/Scene/Share/ViewModel/VideoPlayerViewModel.swift index 64bde2e66..af8978c30 100644 --- a/Mastodon/Scene/Share/ViewModel/VideoPlayerViewModel.swift +++ b/Mastodon/Scene/Share/ViewModel/VideoPlayerViewModel.swift @@ -119,10 +119,10 @@ final class VideoPlayerViewModel { case .unknown, .buffering, .readyToPlay: break case .playing: - try? AVAudioSession.sharedInstance().setCategory(.soloAmbient) + try? AVAudioSession.sharedInstance().setCategory(.playback) try? AVAudioSession.sharedInstance().setActive(true) case .paused, .stopped, .failed: - try? AVAudioSession.sharedInstance().setCategory(.ambient) + try? AVAudioSession.sharedInstance().setCategory(.soloAmbient) // reset to default try? AVAudioSession.sharedInstance().setActive(false, options: .notifyOthersOnDeactivation) } } diff --git a/Mastodon/Service/AudioPlaybackService.swift b/Mastodon/Service/AudioPlaybackService.swift index 6fdac4bf3..5abb30c6c 100644 --- a/Mastodon/Service/AudioPlaybackService.swift +++ b/Mastodon/Service/AudioPlaybackService.swift @@ -39,10 +39,10 @@ final class AudioPlaybackService: NSObject { case .unknown, .buffering, .readyToPlay: break case .playing: - try? AVAudioSession.sharedInstance().setCategory(.soloAmbient) + try? AVAudioSession.sharedInstance().setCategory(.playback) try? AVAudioSession.sharedInstance().setActive(true) case .paused, .stopped, .failed: - try? AVAudioSession.sharedInstance().setCategory(.ambient) + try? AVAudioSession.sharedInstance().setCategory(.soloAmbient) // reset to default try? AVAudioSession.sharedInstance().setActive(false, options: .notifyOthersOnDeactivation) } } diff --git a/Mastodon/Service/VideoPlaybackService.swift b/Mastodon/Service/VideoPlaybackService.swift index e0ac5e6ff..f1e289926 100644 --- a/Mastodon/Service/VideoPlaybackService.swift +++ b/Mastodon/Service/VideoPlaybackService.swift @@ -40,7 +40,6 @@ extension VideoPlaybackService { } else { if latestPlayingVideoPlayerViewModel === playerViewModel { latestPlayingVideoPlayerViewModel = nil -// try? AVAudioSession.sharedInstance().setCategory(.soloAmbient, mode: .default) } } }