Skip to content

Commit 4b494c3

Browse files
committed
Update README.md
1 parent 26d64bb commit 4b494c3

File tree

1 file changed

+34
-16
lines changed

1 file changed

+34
-16
lines changed

README.md

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,7 @@ struct ContentView: View {
105105

106106
var body: some View {
107107
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
110109
switch state {
111110
case .idle:
112111
ProgressView()
@@ -116,11 +115,24 @@ struct ContentView: View {
116115
Text(verbatim: "YouTube player couldn't be loaded")
117116
}
118117
}
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+
} else if playbackState == .ended {
125+
// ...
126+
}
127+
}
119128
}
120129

121130
}
122131
```
123132

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+
124136
When using `UIKit` or `AppKit` you can make use of the `YouTubePlayerViewController`
125137

126138
```swift
@@ -193,6 +205,25 @@ youTubePlayer.parameters.showControls = false
193205
> [!WARNING]
194206
> Updating the `YouTubePlayer.Parameters` during runtime will cause the `YouTubePlayer` to reload.
195207
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+
196227
### Source
197228

198229
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?
220251
> [!NOTE]
221252
> The URL parsing logic is designed to handle most known YouTube URL formats, but there may be some variations that it doesn't cover.
222253
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-
233254
### API
234255

235256
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.
@@ -340,10 +361,7 @@ try await youTubePlayer.getVolume()
340361

341362
```swift
342363
// Show Stats for Nerds which displays additional video information
343-
try await youTubePlayer.showStatsForNerds()
344-
345-
// Hide Stats for Nerds
346-
try await youTubePlayer.hideStatsForNerds()
364+
try await youTubePlayer.setStatsForNerds(isVisible: true)
347365

348366
// Returns a Boolean indicating whether Stats for Nerds is currently displayed.
349367
try await youTubePlayer.isStatsForNerdsVisible()

0 commit comments

Comments
 (0)