fix: no audio when phone under Silence Mode issue. resolve #266

This commit is contained in:
CMK 2021-08-05 18:16:50 +08:00
parent d134178032
commit 9242a859df
3 changed files with 4 additions and 5 deletions

View File

@ -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)
}
}

View File

@ -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)
}
}

View File

@ -40,7 +40,6 @@ extension VideoPlaybackService {
} else {
if latestPlayingVideoPlayerViewModel === playerViewModel {
latestPlayingVideoPlayerViewModel = nil
// try? AVAudioSession.sharedInstance().setCategory(.soloAmbient, mode: .default)
}
}
}