1
0
mirror of git://jb55.com/damus synced 2024-09-30 00:40:45 +00:00

video: add VideoController, which hold cached metadata and mute states

Closes: https://github.com/damus-io/damus/pull/1539
Reviewed-by: William Casarin <jb55@jb55.com>
Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
Bryan Montz 2023-09-06 11:23:33 -05:00 committed by William Casarin
parent 53734ea483
commit dec07df2c1
4 changed files with 49 additions and 2 deletions

View File

@ -389,6 +389,7 @@
504323A92A3495B6006AE6DC /* RelayModelCache.swift in Sources */ = {isa = PBXBuildFile; fileRef = 504323A82A3495B6006AE6DC /* RelayModelCache.swift */; };
5053ACA72A56DF3B00851AE3 /* DeveloperSettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5053ACA62A56DF3B00851AE3 /* DeveloperSettingsView.swift */; };
50A16FFB2AA6C06600DFEC1F /* AVPlayerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50A16FFA2AA6C06600DFEC1F /* AVPlayerView.swift */; };
50A16FFF2AA76A0900DFEC1F /* VideoController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50A16FFE2AA76A0900DFEC1F /* VideoController.swift */; };
50A50A8D29A09E1C00C01BE7 /* RequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50A50A8C29A09E1C00C01BE7 /* RequestTests.swift */; };
50A60D142A28BEEE00186190 /* RelayLog.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50A60D132A28BEEE00186190 /* RelayLog.swift */; };
50B5685329F97CB400A23243 /* CredentialHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50B5685229F97CB400A23243 /* CredentialHandler.swift */; };
@ -1065,6 +1066,7 @@
504323A82A3495B6006AE6DC /* RelayModelCache.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RelayModelCache.swift; sourceTree = "<group>"; };
5053ACA62A56DF3B00851AE3 /* DeveloperSettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeveloperSettingsView.swift; sourceTree = "<group>"; };
50A16FFA2AA6C06600DFEC1F /* AVPlayerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AVPlayerView.swift; sourceTree = "<group>"; };
50A16FFE2AA76A0900DFEC1F /* VideoController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VideoController.swift; sourceTree = "<group>"; };
50A50A8C29A09E1C00C01BE7 /* RequestTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RequestTests.swift; sourceTree = "<group>"; };
50A60D132A28BEEE00186190 /* RelayLog.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RelayLog.swift; sourceTree = "<group>"; };
50B5685229F97CB400A23243 /* CredentialHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CredentialHandler.swift; sourceTree = "<group>"; };
@ -1360,6 +1362,7 @@
isa = PBXGroup;
children = (
4C1A9A2929DDF54400516EAC /* DamusVideoPlayer.swift */,
50A16FFE2AA76A0900DFEC1F /* VideoController.swift */,
4CCF9AAE2A1FDBDB00E03CFB /* VideoPlayer.swift */,
50A16FFA2AA6C06600DFEC1F /* AVPlayerView.swift */,
);
@ -2621,6 +2624,7 @@
4CEE2AF7280B2DEA00AB5EEF /* ProfileName.swift in Sources */,
4CC7AAEB297F0AEC00430951 /* BuilderEventView.swift in Sources */,
31D2E847295218AF006D67F8 /* Shimmer.swift in Sources */,
50A16FFF2AA76A0900DFEC1F /* VideoController.swift in Sources */,
F7908E97298B1FDF00AB113A /* NIPURLBuilder.swift in Sources */,
4C285C8228385570008A31F1 /* CarouselView.swift in Sources */,
3A3040F129A8FF97008A0F29 /* LocalizationUtil.swift in Sources */,

View File

@ -654,7 +654,8 @@ struct ContentView: View {
wallet: WalletModel(settings: settings),
nav: self.navigationCoordinator,
user_search_cache: user_search_cache,
music: MusicController(onChange: music_changed)
music: MusicController(onChange: music_changed),
video: VideoController()
)
home.damus_state = self.damus_state!

View File

@ -33,6 +33,7 @@ struct DamusState {
let nav: NavigationCoordinator
let user_search_cache: UserSearchCache
let music: MusicController?
let video: VideoController
@discardableResult
func add_zap(zap: Zapping) -> Bool {
@ -89,7 +90,8 @@ struct DamusState {
wallet: WalletModel(settings: UserSettingsStore()),
nav: NavigationCoordinator(),
user_search_cache: user_search_cache,
music: nil
music: nil,
video: VideoController()
)
}
}

View File

@ -0,0 +1,40 @@
//
// VideoController.swift
// damus
//
// Created by Bryan Montz on 9/3/23.
//
import Combine
import Foundation
struct VideoMetadata {
let has_audio: Bool
let size: CGSize
}
final class VideoController: ObservableObject {
private var mute_states: [URL: Bool] = [:]
private var metadatas: [URL: VideoMetadata] = [:]
@Published var focused_model_id: UUID?
func toggle_should_mute_video(url: URL) {
let state = mute_states[url] ?? true
mute_states[url] = !state
objectWillChange.send()
}
func should_mute_video(url: URL) -> Bool {
mute_states[url] ?? true
}
func set_metadata(_ metadata: VideoMetadata, url: URL) {
metadatas[url] = metadata
}
func metadata(for url: URL) -> VideoMetadata? {
metadatas[url]
}
}