You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+34-16Lines changed: 34 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -105,8 +105,7 @@ struct ContentView: View {
105
105
106
106
var body: some View {
107
107
YouTubePlayerView(self.youTubePlayer) { state in
108
-
// Overlay ViewBuilder closure to place an overlay View
109
-
// for the current `YouTubePlayer.State`
108
+
// An optional overlay view for the current state of the player
110
109
switch state {
111
110
case .idle:
112
111
ProgressView()
@@ -116,11 +115,24 @@ struct ContentView: View {
116
115
Text(verbatim: "YouTube player couldn't be loaded")
117
116
}
118
117
}
118
+
// Optionally react to specific updates such as the playback state
119
+
.onReceive(
120
+
self.youTubePlayer.playbackStatePublisher
121
+
) { playbackState in
122
+
if playbackState == .playing {
123
+
// ...
124
+
} elseif playbackState == .ended {
125
+
// ...
126
+
}
127
+
}
119
128
}
120
129
121
130
}
122
131
```
123
132
133
+
> [!TIP]
134
+
> You can optionally mark the YouTubePlayer with `@StateObject` or `@ObservedObject` to automatically update your view whenever the source, parameters, or configuration change.
135
+
124
136
When using `UIKit` or `AppKit` you can make use of the `YouTubePlayerViewController`
> Updating the `YouTubePlayer.Parameters` during runtime will cause the `YouTubePlayer` to reload.
195
207
208
+
If you wish to gain more insights into the underlying communication of the YouTube Player iFrame JavaScript API, you can enable the logging of a player via the `isLogginEnabled` parameter.
209
+
210
+
The `YouTubePlayer` utilizes the [unified logging system (OSLog)](https://developer.apple.com/documentation/os/logging) to log information about the player options, JavaScript events and evaluations.
211
+
212
+
```swift
213
+
// Enable or disable logging during initialization
214
+
let youTubePlayer =YouTubePlayer(
215
+
source: [
216
+
"w87fOAG8fjk",
217
+
"RXeOiIDNNek",
218
+
"psL_5RIBqnY"
219
+
],
220
+
isLoggingEnabled: true
221
+
)
222
+
223
+
// To update during runtime update the isLoggingEnabled property
224
+
youTubePlayer.isLoggingEnabled=false
225
+
```
226
+
196
227
### Source
197
228
198
229
The `YouTubePlayer.Source` is an enum which allows you to specify which YouTube source should be loaded.
@@ -220,16 +251,6 @@ let source: YouTubePlayer.Source? = .init(urlString: "https://youtube.com/watch?
220
251
> [!NOTE]
221
252
> The URL parsing logic is designed to handle most known YouTube URL formats, but there may be some variations that it doesn't cover.
222
253
223
-
### Logging
224
-
225
-
To gain more insights into the underlying communication of the YouTube Player iFrame JavaScript API, you can enable logging by:
226
-
227
-
```swift
228
-
YouTubePlayer.isLoggingEnabled=true
229
-
```
230
-
231
-
The YouTubePlayerKit utilizes the [unified logging system (OSLog)](https://developer.apple.com/documentation/os/logging) to log information about the player options, JavaScript events and evaluations.
232
-
233
254
### API
234
255
235
256
A `YouTubePlayer` allows you to access the underlying YouTube player iFrame API in order to play, pause, seek or retrieve information like the current playback quality or title of the video that is currently playing.
0 commit comments