Skip to content

Commit dc77289

Browse files
committed
Updated ReadMe
1 parent 3d191ab commit dc77289

File tree

1 file changed

+27
-14
lines changed

1 file changed

+27
-14
lines changed

README.md

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ To integrate using Apple's [Swift Package Manager](https://swift.org/package-man
6262

6363
```swift
6464
dependencies: [
65-
.package(url: "https://github.com/SvenTiigi/YouTubePlayerKit.git", from: "1.1.0")
65+
.package(url: "https://github.com/SvenTiigi/YouTubePlayerKit.git", from: "1.1.1")
6666
]
6767
```
6868

@@ -105,29 +105,42 @@ When using `UIKit` or `AppKit` you can make use of the `YouTubePlayerViewControl
105105
import UIKit
106106
import YouTubePlayerKit
107107

108-
// Initialize a YouTubePlayer
109-
let youTubePlayer = YouTubePlayer(
110-
source: .video(id: "psL_5RIBqnY")
111-
)
112108
// Initialize a YouTubePlayerViewController
113109
let youTubePlayerViewController = YouTubePlayerViewController(
114-
player: youTubePlayer
110+
player: "https://youtube.com/watch?v=psL_5RIBqnY"
115111
)
116112

117113
// Example: Access the underlying iFrame API via the `YouTubePlayer` instance
118-
youTubePlayer.getPlaybackMetadata { result in
119-
switch result {
120-
case .success(let metadata):
121-
print("Video title", metadata.title)
122-
case .failure(let error):
123-
print("Failed to retrieve metadata", error)
124-
}
125-
}
114+
youTubePlayerViewController.player.showStatsForNerds()
126115

127116
// Present YouTubePlayerViewController
128117
self.present(youTubePlayerViewController, animated: true)
129118
```
130119

120+
If you wish to change the video at runtime simply update the `source` of a `YouTubePlayer`.
121+
122+
```swift
123+
youTubePlayer.source = .video(id: "0TD96VTf0Xs")
124+
```
125+
126+
Additionally, you can update the `configuration` of a `YouTubePlayer` to update the current configuration.
127+
128+
```swift
129+
youTubePlayer.configuration = .init(
130+
isUserInteractionEnabled: true,
131+
autPlay: true
132+
)
133+
```
134+
> Note: Updating the `YouTubePlayer.Configuration` will result in a reload of the YouTubePlayer.
135+
136+
Since `YouTubePlayer` is conform to the [`ObservableObject`](https://developer.apple.com/documentation/combine/observableobject) protocol you can listen for changes whenever the `source` or `configuration` of a `YouTubePlayer` gets updated.
137+
138+
```swift
139+
youTubePlayer
140+
.objectWillChange
141+
.sink { }
142+
```
143+
131144
## YouTubePlayer
132145

133146
A `YouTubePlayer` is the central object which needs to be passed to every YouTubePlayerView or YouTubePlayerViewController in order to play a certain YouTube video and interact with the underlying YouTube iFrame API.

0 commit comments

Comments
 (0)