Skip to content

Commit

Permalink
Updated to 0.8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
qalandarov committed Feb 26, 2023
1 parent b635e5e commit 7f1c829
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 40 deletions.
41 changes: 13 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@

Embed and control YouTube videos in your iOS applications! Neato, right? Let's see how it works.

**0.7.0 Update:** [`WKWebView` breaking changes](#breaking-changes)
**0.8.0 Update:** Multiple breaking changes

This version has multiple breaking changes:
1. Changed delegate-based pattern to publisher based
2. #1 required min iOS to be updated to 13 (from 8)
3. Changed `open` to `public`

## Installation

Expand All @@ -11,7 +16,7 @@ Embed and control YouTube videos in your iOS applications! Neato, right? Let's s
Add this to your Cartfile:

```
github "gilesvangruisen/Swift-YouTube-Player"
github "qalandarov/Swift-YouTube-Player"
```

…and then run `carthage update`
Expand Down Expand Up @@ -52,20 +57,20 @@ var videoPlayer = YouTubePlayerView(frame: playerFrame)
Give the player a video to load, whether from ID or URL.
```Swift
// Load video from YouTube ID
videoPlayer.loadVideoID("nfWlot6h_JM")
videoPlayer.loadVideoID("UF8uR6Z6KLc")
```
```Swift
// Load video from YouTube URL
let myVideoURL = NSURL(string: "https://www.youtube.com/watch?v=wQg3bXrVLtg")
videoPlayer.loadVideoURL(myVideoURL!)
let myVideoURL = URL(string: "https://www.youtube.com/watch?v=UF8uR6Z6KLc")!
videoPlayer.loadVideoURL(myVideoURL)
```

## Controlling YouTubePlayerView

Each `YouTubePlayerView` has methods for controlling the player (play, pause, seek, change video, etc.) They are:

* `func loadVideoURL(videoURL: NSURL)`
* `func loadVideoID(videoID: String)`
* `func loadVideoURL(_ videoURL: URL)`
* `func loadVideoID(_ videoID: String)`
* `func loadPlaylistID(playlistID: String)`
* `func play()`
* `func pause()`
Expand All @@ -77,26 +82,6 @@ Each `YouTubePlayerView` has methods for controlling the player (play, pause, se
* `func getCurrentTime(completion: ((Double?) -> Void)?)`
* `func getDuration(completion: ((Double?) -> Void)?))`

Please note that calls to all but the first two methods will result in a JavaScript runtime error if they are called before the player is ready. The player will not be ready until shortly after a call to either `loadVideoURL(videoURL: NSURL)` or `loadVideoID(videoID: String)`. You can check the readiness of the player at any time by checking its `ready: Bool` property. These functions run asynchronously, so it is not guaranteed that a call to a play function will be safe if it immediately follows a call to a load function. I plan to update the library soon to add completion handlers to be called when the player is ready.

In the meantime, you can also the `YouTubePlayerDelegate` method `playerReady(videoPlayer: YouTubePlayerView)` to ensure code is executed immediately when the player becomes ready.

## Responding to events

[YouTube's iFrame player](https://developers.google.com/youtube/iframe_api_reference) emits certain events based on the lifecycle of the player. The `YouTubePlayerDelegate` outlines these methods that get called during a player's lifecycle. They are:

* `func playerReady(videoPlayer: YouTubePlayerView)`
* `func playerStateChanged(videoPlayer: YouTubePlayerView, playerState: YouTubePlayerState)`
* `func playerQualityChanged(videoPlayer: YouTubePlayerView, playbackQuality: YouTubePlaybackQuality)`

*Side note:* All these delegate methods are optional which means that you can implement none, all, or some of them in your delegate class.

## Breaking Changes

**0.7.0**
Transitioning from `UIWebView` (deprecated) to `WKWebView` required changing
player calls which return values to be asynchronous. If you upgrade to 0.7.0,
you will need to replace any call to either `getCurrentTime()` and
`getDuration()` with its asynchronous equivalent, [documented
above](#controlling-youtubeplayerview).

[YouTube's iFrame player](https://developers.google.com/youtube/iframe_api_reference) emits certain events based on the lifecycle of the player. Those events can be observed using the `@Published var state` property
19 changes: 9 additions & 10 deletions YouTubePlayer.podspec
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
Pod::Spec.new do |s|
s.name = "YouTubePlayer"
s.version = "0.7.2"
s.summary = "Swift library for embedding and controlling YouTube videos in your iOS applications"
s.homepage = "https://github.com/gilesvangruisen/Swift-YouTube-Player"
s.license = { :type => "MIT", :file => "LICENSE" }
s.author = { "Giles Van Gruisen" => "[email protected]" }
s.social_media_url = "http://twitter.com/gilesvangruisen"
s.platform = :ios, "8.0"
s.name = "YouTubePlayer"
s.version = "0.8.0"
s.summary = "Swift library for embedding and controlling YouTube videos in your iOS applications"
s.homepage = "https://github.com/qalandarov/Swift-YouTube-Player"
s.license = { :type => "MIT", :file => "LICENSE" }
s.author = { "Giles Van Gruisen" => "[email protected]" }
s.platform = :ios, "13.0"
s.swift_version = '5.0'
s.source = { :git => "https://github.com/gilesvangruisen/Swift-YouTube-Player.git", :tag => "v#{s.version}" }
s.source = { :git => "https://github.com/qalandarov/Swift-YouTube-Player.git", :tag => "v#{s.version}" }
s.source_files = "YouTubePlayer/**/*.{swift,h,m}"
s.exclude_files = "Classes/Exclude"
s.resources = 'YouTubePlayer/**/*.html'
s.resources = 'YouTubePlayer/**/*.html'
end
2 changes: 1 addition & 1 deletion YouTubePlayer/YouTubePlayer/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<string>0.8.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
Expand Down
2 changes: 1 addition & 1 deletion YouTubePlayerExample/YouTubePlayerExample/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<string>0.8.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
Expand Down

0 comments on commit 7f1c829

Please sign in to comment.