Add a new settings to disable video auto playing

This commit is contained in:
Thomas Ricouard 2023-01-29 10:19:59 +01:00
parent 127d3d65fd
commit 62c3f6e04a
17 changed files with 27 additions and 3 deletions

View file

@ -136,6 +136,9 @@ struct SettingsTabs: View {
Toggle(isOn: $preferences.isSocialKeyboardEnabled) {
Label("settings.other.social-keyboard", systemImage: "keyboard")
}
Toggle(isOn: $preferences.autoPlayVideo) {
Label("settings.other.autoplay-video", systemImage: "play.square.stack")
}
}
.listRowBackground(theme.primaryBackgroundColor)
}

View file

@ -127,6 +127,7 @@
"settings.push.duplicate.title" = "Solucionador de notificacions duplicades";
"settings.push.duplicate.footer" = "Rebeu les notificacions duplicades? Proveu aquest botó màgic per a solucionar-ho";
"settings.push.duplicate.button.fix" = "🪄 Soluciona-ho";
"settings.other.autoplay-video" = "Auto Play Videos";
// MARK: Tabs
"tab.explore" = "Explora";

View file

@ -125,6 +125,7 @@
"settings.push.duplicate.title" = "Doppelte-Benachrichtigungen-Korrigierer";
"settings.push.duplicate.footer" = "Bekommst du doppelte Benachrichtigungen? Probier diesen magischen Knopf aus";
"settings.push.duplicate.button.fix" = "🪄 Beheben";
"settings.other.autoplay-video" = "Auto Play Videos";
"enum.expand-media.show" = "Alle zeigen";
"enum.expand-media.hide" = "Alle verstecken";

View file

@ -128,6 +128,7 @@
"settings.push.duplicate.title" = "Duplicate notifications fixer";
"settings.push.duplicate.footer" = "Receiving duplicate notifications? Try this magic button in order to fix it";
"settings.push.duplicate.button.fix" = "🪄 Fix it";
"settings.other.autoplay-video" = "Auto Play Videos";
// MARK: Tabs
"tab.explore" = "Explore";

View file

@ -125,6 +125,8 @@
"settings.push.duplicate.title" = "Arreglar notificaciones duplicadas";
"settings.push.duplicate.footer" = "¿Recibes notificaciones por duplicado? Usa este botón mágico para arreglarlo";
"settings.push.duplicate.button.fix" = "🪄 Arréglalo";
"settings.other.autoplay-video" = "Auto Play Videos";
"enum.expand-media.show" = "Siempre";
"enum.expand-media.hide" = "Nunca";
"enum.expand-media.hide-sensitive" = "Ocultar contenido sensible";

View file

@ -128,6 +128,7 @@
"settings.push.duplicate.title" = "Correcteur de notifications en double";
"settings.push.duplicate.footer" = "Recevez-vous des notifications en double ? Essayez ce bouton magique pour résoudre le problème";
"settings.push.duplicate.button.fix" = "🪄 Résoudre";
"settings.other.autoplay-video" = "Auto Play Videos";
// MARK: Tabs
"tab.explore" = "Explorer";

View file

@ -128,6 +128,7 @@
"settings.push.duplicate.title" = "Sistema le notifiche duplicate";
"settings.push.duplicate.footer" = "Ricevi notifiche duplicate? Prova questo bottone magico per aggiustarle";
"settings.push.duplicate.button.fix" = "🪄 Aggiusta";
"settings.other.autoplay-video" = "Auto Play Videos";
// MARK: Tabs
"tab.explore" = "Esplora";

View file

@ -111,6 +111,7 @@
"settings.push.duplicate.title" = "重複通知修正ツール";
"settings.push.duplicate.footer" = "重複して通知を受け取っていませんか?それを修正するためにこの魔法のボタンを試してみて";
"settings.push.duplicate.button.fix" = "🪄 修正する";
"settings.other.autoplay-video" = "Auto Play Videos";
// MARK: Tabs
"tab.explore" = "エクスプローラー";

View file

@ -128,6 +128,7 @@
"settings.push.duplicate.title" = "중복 알림 해결사";
"settings.push.duplicate.footer" = "같은 알림이 여러 번 오나요? 여기 있는 버튼을 누르면 마법처럼 해결될 거에요.";
"settings.push.duplicate.button.fix" = "🪄 고치기";
"settings.other.autoplay-video" = "Auto Play Videos";
// MARK: Tabs
"tab.explore" = "둘러보기";

View file

@ -128,6 +128,7 @@
"settings.push.duplicate.title" = "Reparasjon av dupliserte varslinger";
"settings.push.duplicate.footer" = "Får du dupliserte varsler? Prøv denne magiske knappen for å fikse det.";
"settings.push.duplicate.button.fix" = "🪄 Fiks det";
"settings.other.autoplay-video" = "Auto Play Videos";
// MARK: Tabs
"tab.explore" = "Utforsk";

View file

@ -125,6 +125,7 @@
"settings.push.duplicate.title" = "Dubbele meldingen";
"settings.push.duplicate.footer" = "Ontvang je dubbele meldingen? Gebruik deze magische knop om dit probleem te verhelpen";
"settings.push.duplicate.button.fix" = "🪄 Los op";
"settings.other.autoplay-video" = "Auto Play Videos";
// MARK: Tabs
"tab.explore" = "Ontdekken";

View file

@ -128,6 +128,7 @@
"settings.push.duplicate.title" = "Korektor duplikatów powiadomień";
"settings.push.duplicate.footer" = "Otrzymujesz zduplikowane powiadomienia? Spróbuj tego magicznego przycisku, aby to naprawić";
"settings.push.duplicate.button.fix" = "🪄 Napraw to";
"settings.other.autoplay-video" = "Auto Play Videos";
// MARK: Tabs
"tab.explore" = "Odkrywaj";

View file

@ -128,6 +128,7 @@
"settings.push.duplicate.title" = "Corretor de notificações duplicadas";
"settings.push.duplicate.footer" = "Recebendo notificações duplicadas? Tente este botão mágico para tentar corrigir";
"settings.push.duplicate.button.fix" = "🪄 Corrigir";
"settings.other.autoplay-video" = "Auto Play Videos";
// MARK: Tabs
"tab.explore" = "Explorar";

View file

@ -114,6 +114,7 @@
"settings.push.duplicate.title" = "Duplicate notifications fixer";
"settings.push.duplicate.footer" = "Receiving duplicate notifications? Try this magic button in order to fix it";
"settings.push.duplicate.button.fix" = "🪄 Fix it";
"settings.other.autoplay-video" = "Auto Play Videos";
// MARK: Tabs
"tab.explore" = "Keşfet";

View file

@ -127,6 +127,7 @@
"settings.push.duplicate.title" = "重复推送通知修复器";
"settings.push.duplicate.footer" = "有收到重复的推送通知?试试用这个魔法按钮去修复吧";
"settings.push.duplicate.button.fix" = "🪄 修复";
"settings.other.autoplay-video" = "Auto Play Videos";
// MARK: Tabs
"tab.explore" = "探索";

View file

@ -25,6 +25,7 @@ public class UserPreferences: ObservableObject {
@AppStorage("app_auto_expand_media") public var appAutoExpandMedia: ServerPreferences.AutoExpandMedia = .hideSensitive
@AppStorage("app_default_post_visibility") public var appDefaultPostVisibility: Models.Visibility = .pub
@AppStorage("app_default_posts_sensitive") public var appDefaultPostsSensitive = false
@AppStorage("autoplay_video") public var autoPlayVideo = true
public var postVisibility: Models.Visibility {
if useInstanceContentSettings {

View file

@ -1,5 +1,6 @@
import AVKit
import SwiftUI
import Env
class VideoPlayerViewModel: ObservableObject {
@Published var player: AVPlayer?
@ -9,10 +10,12 @@ class VideoPlayerViewModel: ObservableObject {
self.url = url
}
func preparePlayer() {
func preparePlayer(autoPlay: Bool) {
player = .init(url: url)
player?.isMuted = true
player?.play()
if autoPlay {
player?.play()
}
guard let player else { return }
NotificationCenter.default.addObserver(forName: .AVPlayerItemDidPlayToEndTime,
object: player.currentItem, queue: .main) { [weak self] _ in
@ -36,13 +39,15 @@ class VideoPlayerViewModel: ObservableObject {
struct VideoPlayerView: View {
@Environment(\.scenePhase) private var scenePhase
@EnvironmentObject private var preferences: UserPreferences
@StateObject var viewModel: VideoPlayerViewModel
var body: some View {
VStack {
VideoPlayer(player: viewModel.player)
}.onAppear {
viewModel.preparePlayer()
viewModel.preparePlayer(autoPlay: preferences.autoPlayVideo)
}
.onChange(of: scenePhase, perform: { scenePhase in
switch scenePhase {