Play video on a separate window on macOS

This commit is contained in:
Thomas Ricouard 2024-01-22 22:04:28 +01:00
parent eeff60bf98
commit 621f0d0864
2 changed files with 17 additions and 0 deletions

View file

@ -3,6 +3,7 @@ import DesignSystem
import Env
import Observation
import SwiftUI
import Models
@MainActor
@Observable public class MediaUIAttachmentVideoViewModel {
@ -74,6 +75,7 @@ import SwiftUI
@MainActor
public struct MediaUIAttachmentVideoView: View {
@Environment(\.openWindow) private var openWindow
@Environment(\.scenePhase) private var scenePhase
@Environment(\.isMediaCompact) private var isCompact
@Environment(UserPreferences.self) private var preferences
@ -101,7 +103,13 @@ public struct MediaUIAttachmentVideoView: View {
viewModel.play()
return
}
#if targetEnvironment(macCatalyst)
viewModel.pause()
let attachement = MediaAttachment.videoWith(url: viewModel.url)
openWindow(value: WindowDestinationMedia.mediaViewer(attachments: [attachement], selectedAttachment: attachement))
#else
isFullScreen = true
#endif
}
.fullScreenCover(isPresented: $isFullScreen) {
NavigationStack {

View file

@ -53,6 +53,15 @@ public struct MediaAttachment: Codable, Identifiable, Hashable, Equatable {
description: "demo alt text here",
meta: nil)
}
public static func videoWith(url: URL) -> MediaAttachment {
.init(id: UUID().uuidString,
type: "video",
url: url,
previewUrl: url,
description: nil,
meta: nil)
}
}
extension MediaAttachment: Sendable {}