From 6376e573b18d0c32fec876bfd9f58da96ce8b4a1 Mon Sep 17 00:00:00 2001 From: Arkadiusz Fal Date: Sun, 17 Apr 2022 11:34:26 +0200 Subject: [PATCH] Run play action async --- Shared/Videos/VideoCell.swift | 47 +++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/Shared/Videos/VideoCell.swift b/Shared/Videos/VideoCell.swift index 2b662642..32a77d23 100644 --- a/Shared/Videos/VideoCell.swift +++ b/Shared/Videos/VideoCell.swift @@ -1,3 +1,4 @@ +import CoreMedia import Defaults import SDWebImageSwiftUI import SwiftUI @@ -62,34 +63,36 @@ struct VideoCell: View { } private func playAction() { - guard video.videoID != Video.fixtureID else { - return - } - - if watchingNow { - if !player.playingInPictureInPicture { - player.show() + DispatchQueue.main.async { + guard video.videoID != Video.fixtureID else { + return } - if !playNowContinues { - player.backend.seek(to: .zero) + if watchingNow { + if !player.playingInPictureInPicture { + player.show() + } + + if !playNowContinues { + player.backend.seek(to: .zero) + } + + player.play() + + return } - player.play() + var playAt: CMTime? - return + if playNowContinues, + !watch.isNil, + !watch!.finished + { + playAt = .secondsInDefaultTimescale(watch!.stoppedAt) + } + + player.play(video, at: playAt, inNavigationView: inNavigationView) } - - var playAt: TimeInterval? - - if playNowContinues, - !watch.isNil, - !watch!.finished - { - playAt = watch!.stoppedAt - } - - player.play(video, at: playAt, inNavigationView: inNavigationView) } private var playNowContinues: Bool {