mirror of
https://github.com/Dimillian/IceCubesApp.git
synced 2024-09-27 06:00:05 +00:00
Prevent video sleep in full screen
This commit is contained in:
parent
a4cdc6fc18
commit
b2be3778c1
2 changed files with 10 additions and 2 deletions
|
@ -61,6 +61,12 @@ import SwiftUI
|
||||||
player?.play()
|
player?.play()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func preventSleep(_ preventSleep: Bool) {
|
||||||
|
#if !os(visionOS)
|
||||||
|
player?.preventsDisplaySleepDuringVideoPlayback = preventSleep
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
deinit {
|
deinit {
|
||||||
NotificationCenter.default.removeObserver(self, name: .AVPlayerItemDidPlayToEndTime, object: nil)
|
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().setCategory(.playback, options: .duckOthers)
|
||||||
try? AVAudioSession.sharedInstance().setActive(true)
|
try? AVAudioSession.sharedInstance().setActive(true)
|
||||||
}
|
}
|
||||||
|
viewModel.preventSleep(true)
|
||||||
viewModel.mute(false)
|
viewModel.mute(false)
|
||||||
DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
|
DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
|
||||||
if isCompact || !preferences.autoPlayVideo {
|
if isCompact || !preferences.autoPlayVideo {
|
||||||
|
@ -127,6 +134,7 @@ public struct MediaUIAttachmentVideoView: View {
|
||||||
if isCompact || !preferences.autoPlayVideo {
|
if isCompact || !preferences.autoPlayVideo {
|
||||||
viewModel.pause()
|
viewModel.pause()
|
||||||
}
|
}
|
||||||
|
viewModel.preventSleep(false)
|
||||||
viewModel.mute(preferences.muteVideo)
|
viewModel.mute(preferences.muteVideo)
|
||||||
DispatchQueue.global().async {
|
DispatchQueue.global().async {
|
||||||
try? AVAudioSession.sharedInstance().setActive(false, options: .notifyOthersOnDeactivation)
|
try? AVAudioSession.sharedInstance().setActive(false, options: .notifyOthersOnDeactivation)
|
||||||
|
|
|
@ -213,8 +213,7 @@ struct StatusRowActionsView: View {
|
||||||
if !isNarrow,
|
if !isNarrow,
|
||||||
let count = action.count(dataController: statusDataController,
|
let count = action.count(dataController: statusDataController,
|
||||||
isFocused: isFocused,
|
isFocused: isFocused,
|
||||||
theme: theme), !viewModel.isRemote,
|
theme: theme), !viewModel.isRemote
|
||||||
count > 0
|
|
||||||
{
|
{
|
||||||
Text(count, format: .number.notation(.compactName))
|
Text(count, format: .number.notation(.compactName))
|
||||||
.lineLimit(1)
|
.lineLimit(1)
|
||||||
|
@ -223,6 +222,7 @@ struct StatusRowActionsView: View {
|
||||||
.foregroundColor(Color(UIColor.secondaryLabel))
|
.foregroundColor(Color(UIColor.secondaryLabel))
|
||||||
.font(.scaledFootnote)
|
.font(.scaledFootnote)
|
||||||
.monospacedDigit()
|
.monospacedDigit()
|
||||||
|
.opacity(count > 0 ? 1 : 0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.padding(.vertical, 6)
|
.padding(.vertical, 6)
|
||||||
|
|
Loading…
Reference in a new issue