forked from shadowfacts/Tusker
Play back videos in focused attachment view
This commit is contained in:
parent
a37423a119
commit
ad55851090
|
@ -7,17 +7,27 @@
|
||||||
|
|
||||||
import SwiftUI
|
import SwiftUI
|
||||||
import MatchedGeometryPresentation
|
import MatchedGeometryPresentation
|
||||||
|
import AVKit
|
||||||
|
|
||||||
class FocusedAttachmentController: ViewController {
|
class FocusedAttachmentController: ViewController {
|
||||||
|
|
||||||
unowned let parent: ComposeController
|
unowned let parent: ComposeController
|
||||||
let attachment: DraftAttachment
|
let attachment: DraftAttachment
|
||||||
let thumbnailController: AttachmentThumbnailController
|
let thumbnailController: AttachmentThumbnailController
|
||||||
|
private let player: AVPlayer?
|
||||||
|
|
||||||
init(parent: ComposeController, attachment: DraftAttachment, thumbnailController: AttachmentThumbnailController) {
|
init(parent: ComposeController, attachment: DraftAttachment, thumbnailController: AttachmentThumbnailController) {
|
||||||
self.parent = parent
|
self.parent = parent
|
||||||
self.attachment = attachment
|
self.attachment = attachment
|
||||||
self.thumbnailController = thumbnailController
|
self.thumbnailController = thumbnailController
|
||||||
|
|
||||||
|
if case let .file(url, type) = attachment.data,
|
||||||
|
type.conforms(to: .movie) {
|
||||||
|
self.player = AVPlayer(url: url)
|
||||||
|
self.player!.isMuted = true
|
||||||
|
} else {
|
||||||
|
self.player = nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var view: some View {
|
var view: some View {
|
||||||
|
@ -35,16 +45,20 @@ class FocusedAttachmentController: ViewController {
|
||||||
VStack(spacing: 0) {
|
VStack(spacing: 0) {
|
||||||
Spacer(minLength: 0)
|
Spacer(minLength: 0)
|
||||||
|
|
||||||
let attachmentView =
|
if let player = controller.player {
|
||||||
ControllerView(controller: { controller.thumbnailController })
|
VideoPlayer(player: player)
|
||||||
.environment(\.attachmentThumbnailConfiguration, .init(contentMode: .fit, fullSize: true))
|
|
||||||
.matchedGeometryDestination(id: attachment.id)
|
.matchedGeometryDestination(id: attachment.id)
|
||||||
if #available(iOS 16.0, *) {
|
.onAppear {
|
||||||
|
player.play()
|
||||||
|
}
|
||||||
|
} else if #available(iOS 16.0, *) {
|
||||||
ZoomableScrollView {
|
ZoomableScrollView {
|
||||||
attachmentView
|
attachmentView
|
||||||
|
.matchedGeometryDestination(id: attachment.id)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
attachmentView
|
attachmentView
|
||||||
|
.matchedGeometryDestination(id: attachment.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
Spacer(minLength: 0)
|
Spacer(minLength: 0)
|
||||||
|
@ -71,6 +85,11 @@ class FocusedAttachmentController: ViewController {
|
||||||
.padding([.top, .leading], 4)
|
.padding([.top, .leading], 4)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private var attachmentView: some View {
|
||||||
|
ControllerView(controller: { controller.thumbnailController })
|
||||||
|
.environment(\.attachmentThumbnailConfiguration, .init(contentMode: .fit, fullSize: true))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue