From eac25effa3b2239a26778ea21b1c4bf9c7987544 Mon Sep 17 00:00:00 2001 From: Cosmic Flamingo Date: Sun, 19 May 2024 13:46:47 -0500 Subject: [PATCH 1/2] Update playerStateSubject in JavaScript .onStateChange event --- Sources/YouTubePlayer.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Sources/YouTubePlayer.swift b/Sources/YouTubePlayer.swift index b0c38c9..5383da4 100644 --- a/Sources/YouTubePlayer.swift +++ b/Sources/YouTubePlayer.swift @@ -239,6 +239,8 @@ private extension YouTubePlayer { // Otherwise return out of function return } + // Send PlayerState + self.playerStateSubject.send(.ready) // Send PlaybackState self.playbackStateSubject.send(playbackState) case .onPlaybackQualityChange: From 9592d522fb464970290dea714325313a98edba0b Mon Sep 17 00:00:00 2001 From: Cosmic Flamingo Date: Wed, 26 Jun 2024 21:34:08 -0500 Subject: [PATCH 2/2] Mark YouTubePlayer views and models with @MainActor --- Sources/HostingView/YouTubePlayerHostingView.swift | 5 ++++- Sources/ViewController/YouTubePlayerViewController.swift | 5 ++++- Sources/WebView/YouTubePlayerWebView.swift | 1 + Sources/YouTubePlayer.swift | 1 + 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Sources/HostingView/YouTubePlayerHostingView.swift b/Sources/HostingView/YouTubePlayerHostingView.swift index 3b0da1e..7c64a48 100644 --- a/Sources/HostingView/YouTubePlayerHostingView.swift +++ b/Sources/HostingView/YouTubePlayerHostingView.swift @@ -17,6 +17,7 @@ public class YouTubePlayerHostingBaseView: UIView {} // MARK: - YouTubePlayerHostingView /// The YouTubePlayer HostingView +@MainActor public final class YouTubePlayerHostingView: YouTubePlayerHostingBaseView { // MARK: Properties @@ -62,7 +63,9 @@ public final class YouTubePlayerHostingView: YouTubePlayerHostingBaseView { /// Deinit deinit { - self.player.pause() + MainActor.assumeIsolated { + self.player.pause() + } } } diff --git a/Sources/ViewController/YouTubePlayerViewController.swift b/Sources/ViewController/YouTubePlayerViewController.swift index c33a33f..8e89be7 100644 --- a/Sources/ViewController/YouTubePlayerViewController.swift +++ b/Sources/ViewController/YouTubePlayerViewController.swift @@ -17,6 +17,7 @@ public class YouTubePlayerBaseViewController: UIViewController {} // MARK: - YouTubePlayerViewController /// The YouTubePlayer ViewController +@MainActor public final class YouTubePlayerViewController: YouTubePlayerBaseViewController { // MARK: Properties @@ -61,7 +62,9 @@ public final class YouTubePlayerViewController: YouTubePlayerBaseViewController /// Deinit deinit { - self.player.pause() + MainActor.assumeIsolated { + self.player.pause() + } } // MARK: View-Lifecycle diff --git a/Sources/WebView/YouTubePlayerWebView.swift b/Sources/WebView/YouTubePlayerWebView.swift index 560e68e..cf7739f 100644 --- a/Sources/WebView/YouTubePlayerWebView.swift +++ b/Sources/WebView/YouTubePlayerWebView.swift @@ -5,6 +5,7 @@ import WebKit // MARK: - YouTubePlayerWebView /// The YouTubePlayer WebView +@MainActor final class YouTubePlayerWebView: WKWebView { // MARK: Properties diff --git a/Sources/YouTubePlayer.swift b/Sources/YouTubePlayer.swift index 5383da4..4227e23 100644 --- a/Sources/YouTubePlayer.swift +++ b/Sources/YouTubePlayer.swift @@ -4,6 +4,7 @@ import Foundation // MARK: - YouTubePlayer /// A YouTubePlayer +@MainActor public final class YouTubePlayer: ObservableObject { // MARK: Properties