@@ -15,14 +15,22 @@ import SwiftUI
1515public protocol LoopPlayerViewProtocol {
1616
1717 #if os(iOS) || os(tvOS)
18- associatedtype View : UIView
18+ associatedtype View : UIView
1919 #elseif os(macOS)
2020 associatedtype View : NSView
2121 #else
2222 associatedtype View : CustomView
2323 #endif
2424
2525 associatedtype ErrorView
26+
27+ #if os(iOS) || os(tvOS)
28+ associatedtype PlayerView : LoopingPlayerProtocol , UIView
29+ #elseif os(macOS)
30+ associatedtype PlayerView : LoopingPlayerProtocol , NSView
31+ #else
32+ associatedtype PlayerView : LoopingPlayerProtocol , CustomView
33+ #endif
2634
2735 /// Settings for configuring the video player.
2836 var settings : Settings { get }
@@ -58,62 +66,24 @@ public extension LoopPlayerViewProtocol{
5866 activateFullScreenConstraints ( for: errorView, in: view)
5967 }
6068 }
61-
62- /// Adds a subview to a given view and activates full-screen constraints on the subview within the parent view.
63- /// - Parameters:
64- /// - view: The parent view to which the subview will be added.
65- /// - subView: The subview that will be added to the parent view.
66- @MainActor
67- func compose( _ view: View , _ subView: View ) {
68- view. addSubview ( subView)
69- activateFullScreenConstraints ( for: subView, in: view)
70- }
71- }
72-
73- #if os(iOS) || os(tvOS)
74- @available ( iOS 14 , tvOS 14 , * )
75- public extension LoopPlayerViewProtocol where Self: UIViewRepresentable , Context == UIViewRepresentableContext < Self > {
7669
7770 /// Creates a player view for looping video content.
7871 /// - Parameters:
7972 /// - context: The UIViewRepresentable context providing environment data and coordinator.
8073 /// - asset: The AVURLAsset to be used for video playback.
8174 /// - Returns: A PlayerView instance conforming to LoopingPlayerProtocol.
8275 @MainActor
83- func createPlayerView < PlayerView : LoopingPlayerProtocol > (
84- context : Context ,
85- asset: AVURLAsset ) -> PlayerView {
76+ func makePlayerView (
77+ _ container : View ,
78+ asset: AVURLAsset ? ) -> PlayerView ? {
8679
80+ if let asset{
81+ let player = PlayerView ( asset: asset, gravity: settings. gravity)
82+ container. addSubview ( player)
83+ activateFullScreenConstraints ( for: player, in: container)
84+ return player
85+ }
8786
88- let player = PlayerView ( asset: asset, gravity: settings. gravity)
89-
90- player. delegate = context. coordinator as? PlayerErrorDelegate
91- return player
92- }
93- }
94-
95- #endif
96-
97- #if os(macOS)
98- @available ( macOS 11 , * )
99- public extension LoopPlayerViewProtocol where Self: NSViewRepresentable , Context == NSViewRepresentableContext < Self > {
100-
101- /// Creates a player view for looping video content.
102- /// - Parameters:
103- /// - context: The NSViewRepresentable context providing environment data and coordinator.
104- /// - asset: The AVURLAsset to be used for video playback.
105- /// - Returns: A PlayerView instance conforming to LoopingPlayerProtocol.
106- @MainActor
107- func createPlayerView< PlayerView: LoopingPlayerProtocol > (
108- context: Context ,
109- asset: AVURLAsset ) -> PlayerView {
110-
111- let player = PlayerView ( asset: asset, gravity: settings. gravity)
112-
113- player. delegate = context. coordinator as? PlayerErrorDelegate
114- return player
87+ return nil
11588 }
11689}
117- #endif
118-
119-
0 commit comments