Skip to content

Commit 765ab32

Browse files
committed
Added playlist parameter when loop is enabled
#68
1 parent b2cf1e0 commit 765ab32

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

Sources/Options/YouTubePlayer+Options.swift

+15-9
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ extension YouTubePlayer.Options {
4545
originURL: URL?
4646
) throws {
4747
// Retrieve Player Configuration as JSON
48-
var playerConfiguration = try playerConfiguration.json()
48+
var playerConfigurationJSON = try playerConfiguration.json()
4949
// Initialize Configuration
5050
var configuration: [String: Any] = [
5151
CodingKeys.width.rawValue: "100%",
@@ -72,26 +72,32 @@ extension YouTubePlayer.Options {
7272
// Check if a start seconds are available
7373
if let startSeconds = startSeconds {
7474
// Set start time on player configuration
75-
playerConfiguration[
75+
playerConfigurationJSON[
7676
YouTubePlayer.Configuration.CodingKeys.startTime.rawValue
7777
] = startSeconds
7878
}
79+
// Check if loop is enabled
80+
if playerConfiguration.loopEnabled == true {
81+
// Add playlist parameter with video id
82+
// as this parameter is required to make looping work
83+
playerConfigurationJSON[YouTubePlayer.Configuration.ListType.playlist.rawValue] = id
84+
}
7985
case .playlist(let id, _, _):
8086
// Set playlist
81-
playerConfiguration[
87+
playerConfigurationJSON[
8288
YouTubePlayer.Configuration.CodingKeys.listType.rawValue
8389
] = YouTubePlayer.Configuration.ListType.playlist.rawValue
8490
// Set playlist id
85-
playerConfiguration[
91+
playerConfigurationJSON[
8692
YouTubePlayer.Configuration.CodingKeys.list.rawValue
8793
] = id
8894
case .channel(let name, _, _):
8995
// Set user uploads
90-
playerConfiguration[
96+
playerConfigurationJSON[
9197
YouTubePlayer.Configuration.CodingKeys.listType.rawValue
9298
] = YouTubePlayer.Configuration.ListType.userUploads.rawValue
9399
// Set channel id
94-
playerConfiguration[
100+
playerConfigurationJSON[
95101
YouTubePlayer.Configuration.CodingKeys.list.rawValue
96102
] = name
97103
case nil:
@@ -101,14 +107,14 @@ extension YouTubePlayer.Options {
101107
// Check if an origin URL is available
102108
// and the player configuration doesn't contain an origin
103109
if let originURL = originURL,
104-
playerConfiguration[YouTubePlayer.Configuration.CodingKeys.origin.rawValue] == nil {
110+
playerConfigurationJSON[YouTubePlayer.Configuration.CodingKeys.origin.rawValue] == nil {
105111
// Set origin URL
106-
playerConfiguration[
112+
playerConfigurationJSON[
107113
YouTubePlayer.Configuration.CodingKeys.origin.rawValue
108114
] = originURL.absoluteString
109115
}
110116
// Set Player Configuration
111-
configuration[CodingKeys.playerVars.rawValue] = playerConfiguration
117+
configuration[CodingKeys.playerVars.rawValue] = playerConfigurationJSON
112118
// Make JSON string from Configuration
113119
self.json = try configuration.jsonString()
114120
}

0 commit comments

Comments
 (0)