Prevent video sleep in full screen

This commit is contained in:
Thomas Ricouard 2024-01-09 10:32:50 +01:00
parent a4cdc6fc18
commit b2be3778c1
2 changed files with 10 additions and 2 deletions

View file

@ -60,6 +60,12 @@ import SwiftUI
isPlaying = true
player?.play()
}
func preventSleep(_ preventSleep: Bool) {
#if !os(visionOS)
player?.preventsDisplaySleepDuringVideoPlayback = preventSleep
#endif
}
deinit {
NotificationCenter.default.removeObserver(self, name: .AVPlayerItemDidPlayToEndTime, object: nil)
@ -114,6 +120,7 @@ public struct MediaUIAttachmentVideoView: View {
try? AVAudioSession.sharedInstance().setCategory(.playback, options: .duckOthers)
try? AVAudioSession.sharedInstance().setActive(true)
}
viewModel.preventSleep(true)
viewModel.mute(false)
DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
if isCompact || !preferences.autoPlayVideo {
@ -127,6 +134,7 @@ public struct MediaUIAttachmentVideoView: View {
if isCompact || !preferences.autoPlayVideo {
viewModel.pause()
}
viewModel.preventSleep(false)
viewModel.mute(preferences.muteVideo)
DispatchQueue.global().async {
try? AVAudioSession.sharedInstance().setActive(false, options: .notifyOthersOnDeactivation)

View file

@ -213,8 +213,7 @@ struct StatusRowActionsView: View {
if !isNarrow,
let count = action.count(dataController: statusDataController,
isFocused: isFocused,
theme: theme), !viewModel.isRemote,
count > 0
theme: theme), !viewModel.isRemote
{
Text(count, format: .number.notation(.compactName))
.lineLimit(1)
@ -223,6 +222,7 @@ struct StatusRowActionsView: View {
.foregroundColor(Color(UIColor.secondaryLabel))
.font(.scaledFootnote)
.monospacedDigit()
.opacity(count > 0 ? 1 : 0)
}
}
.padding(.vertical, 6)