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:
Bryan Montz
2023-09-06 11:16:14 -05:00
committed by William Casarin
parent b18a0c573e
commit 53734ea483
2 changed files with 35 additions and 0 deletions

View 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
}
}