File tree Expand file tree Collapse file tree 1 file changed +10
-8
lines changed
Expand file tree Collapse file tree 1 file changed +10
-8
lines changed Original file line number Diff line number Diff line change @@ -44,10 +44,20 @@ public extension YouTubePlayer.OpenURLAction {
4444 /// - Parameters:
4545 /// - url: The URL to open.
4646 /// - player: The ``YouTubePlayer`` instance.
47+ @MainActor
4748 func callAsFunction(
4849 url: URL ,
4950 player: YouTubePlayer
5051 ) async {
52+ // Check if the url is a YouTube video url and can be loaded
53+ if let source = YouTubePlayer . Source ( url: url) ,
54+ source. videoID != player. source? . videoID,
55+ ( try ? await player. load ( source: source) ) != nil {
56+ // Return out of function as the url is a video
57+ // which is now loaded in the player
58+ return
59+ }
60+ // Invoke the handler
5161 await self . handler ( url, player)
5262 }
5363
@@ -88,14 +98,6 @@ public extension YouTubePlayer.OpenURLAction {
8898
8999 /// The default OpenURLAction
90100 static let `default` = Self { url, player in
91- // Check if YouTube player source can be initialize from url
92- // and it was successfully loaded
93- if let source = YouTubePlayer . Source ( url: url) ,
94- source. videoID != player. source? . videoID,
95- ( try ? await player. load ( source: source) ) != nil {
96- // Return out of function
97- return
98- }
99101 // Open url externally
100102 #if os(macOS)
101103 _ = try ? await NSWorkspace
You can’t perform that action at this time.
0 commit comments