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:
committed by
William Casarin
parent
53734ea483
commit
dec07df2c1
40
damus/Views/Video/VideoController.swift
Normal file
40
damus/Views/Video/VideoController.swift
Normal 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]
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user