forked from zelo72/mastodon-ios
Merge pull request #286 from mastodon/fix/issue-283
Fix GIFV may interrupt music playback issue
This commit is contained in:
commit
7667d9ad3f
|
@ -113,6 +113,7 @@ final class VideoPlayerViewModel {
|
||||||
.sink { [weak self] status in
|
.sink { [weak self] status in
|
||||||
os_log(.info, log: .debug, "%{public}s[%{public}ld], %{public}s: %s status: %s", ((#file as NSString).lastPathComponent), #line, #function, sessionName, status.description)
|
os_log(.info, log: .debug, "%{public}s[%{public}ld], %{public}s: %s status: %s", ((#file as NSString).lastPathComponent), #line, #function, sessionName, status.description)
|
||||||
guard let self = self else { return }
|
guard let self = self else { return }
|
||||||
|
|
||||||
// only update audio session for video
|
// only update audio session for video
|
||||||
guard self.videoKind == .video else { return }
|
guard self.videoKind == .video else { return }
|
||||||
switch status {
|
switch status {
|
||||||
|
@ -122,7 +123,7 @@ final class VideoPlayerViewModel {
|
||||||
try? AVAudioSession.sharedInstance().setCategory(.playback)
|
try? AVAudioSession.sharedInstance().setCategory(.playback)
|
||||||
try? AVAudioSession.sharedInstance().setActive(true)
|
try? AVAudioSession.sharedInstance().setActive(true)
|
||||||
case .paused, .stopped, .failed:
|
case .paused, .stopped, .failed:
|
||||||
try? AVAudioSession.sharedInstance().setCategory(.soloAmbient) // reset to default
|
try? AVAudioSession.sharedInstance().setCategory(.ambient) // set to ambient to allow mixed (needed for GIFV)
|
||||||
try? AVAudioSession.sharedInstance().setActive(false, options: .notifyOthersOnDeactivation)
|
try? AVAudioSession.sharedInstance().setActive(false, options: .notifyOthersOnDeactivation)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -149,14 +150,6 @@ extension VideoPlayerViewModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
func play() {
|
func play() {
|
||||||
switch videoKind {
|
|
||||||
case .gif:
|
|
||||||
break
|
|
||||||
case .video:
|
|
||||||
break
|
|
||||||
// try? AVAudioSession.sharedInstance().setCategory(.soloAmbient, mode: .default)
|
|
||||||
}
|
|
||||||
|
|
||||||
player.play()
|
player.play()
|
||||||
updateDate = Date()
|
updateDate = Date()
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,7 @@ final class AudioPlaybackService: NSObject {
|
||||||
try? AVAudioSession.sharedInstance().setCategory(.playback)
|
try? AVAudioSession.sharedInstance().setCategory(.playback)
|
||||||
try? AVAudioSession.sharedInstance().setActive(true)
|
try? AVAudioSession.sharedInstance().setActive(true)
|
||||||
case .paused, .stopped, .failed:
|
case .paused, .stopped, .failed:
|
||||||
try? AVAudioSession.sharedInstance().setCategory(.soloAmbient) // reset to default
|
try? AVAudioSession.sharedInstance().setCategory(.ambient) // set to ambient to allow mixed (needed for GIFV)
|
||||||
try? AVAudioSession.sharedInstance().setActive(false, options: .notifyOthersOnDeactivation)
|
try? AVAudioSession.sharedInstance().setActive(false, options: .notifyOthersOnDeactivation)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue