video: add AVPlayerView, a simple wrapper for AVPlayerViewController
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
b18a0c573e
commit
53734ea483
31
damus/Views/Video/AVPlayerView.swift
Normal file
31
damus/Views/Video/AVPlayerView.swift
Normal file
@@ -0,0 +1,31 @@
|
||||
//
|
||||
// AVPlayerView.swift
|
||||
// damus
|
||||
//
|
||||
// Created by Bryan Montz on 9/4/23.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import AVKit
|
||||
import SwiftUI
|
||||
|
||||
struct AVPlayerView: UIViewControllerRepresentable {
|
||||
|
||||
let player: AVPlayer
|
||||
|
||||
func makeUIViewController(context: Context) -> AVPlayerViewController {
|
||||
AVPlayerViewController()
|
||||
}
|
||||
|
||||
func updateUIViewController(_ uiViewController: AVPlayerViewController, context: Context) {
|
||||
if uiViewController.player == nil {
|
||||
uiViewController.player = player
|
||||
player.play()
|
||||
}
|
||||
}
|
||||
|
||||
static func dismantleUIViewController(_ uiViewController: AVPlayerViewController, coordinator: ()) {
|
||||
uiViewController.player?.pause()
|
||||
uiViewController.player = nil
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user