damus

nostr ios client
git clone git://jb55.com/damus
Log | Files | Refs | README | LICENSE

commit 0ee360f2fad34296d3e6aefe3829a10960391aa2
parent c59d2a96afb060c32598b60cc0e3f611e6faf6a4
Author: William Casarin <jb55@jb55.com>
Date:   Sat, 10 Jun 2023 11:33:35 +0200

Fix video player hangs

Changelog-Fixed: Fix hangs due to video player

Diffstat:
Mdamus/Views/Video/VideoPlayer.swift | 13+++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/damus/Views/Video/VideoPlayer.swift b/damus/Views/Video/VideoPlayer.swift @@ -170,9 +170,14 @@ public extension VideoPlayer { } -func get_video_size(player: AVPlayer) -> CGSize? { - // TODO: make this async? - return player.currentImage?.size +func get_video_size(player: AVPlayer) async -> CGSize? { + let res = await withCheckedContinuation { continuation in + DispatchQueue.global().async { + let size = player.currentImage?.size + continuation.resume(returning: size) + } + } + return res } func video_has_audio(player: AVPlayer) async -> Bool { @@ -220,7 +225,7 @@ extension VideoPlayer: UIViewRepresentable { if let player = uiView.player { Task { let has_audio = await video_has_audio(player: player) - let size = get_video_size(player: player) + let size = await get_video_size(player: player) Task { @MainActor in if let size { self.model.size = size