Skip to content

Commit 2fa00ad

Browse files
Merge pull request #17 from gilesvangruisen/swift-1.2
Swift 1.2
2 parents 0e23e1d + 55ef6c3 commit 2fa00ad

File tree

4 files changed

+43
-115
lines changed

4 files changed

+43
-115
lines changed

YouTubePlayer.podspec

Lines changed: 1 addition & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,13 @@
11
Pod::Spec.new do |s|
2-
32
s.name = "YouTubePlayer"
4-
s.version = "0.1"
3+
s.version = "0.2"
54
s.summary = "Swift library for embedding and controlling YouTube videos in your iOS applications"
65
s.homepage = "https://github.com/gilesvangruisen/Swift-YouTube-Player"
76
s.license = { :type => "MIT", :file => "LICENSE" }
87
s.author = { "Giles Van Gruisen" => "giles@vangruisen.com" }
98
s.social_media_url = "http://twitter.com/gilesvangruisen"
10-
11-
# ――― Platform Specifics ――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
12-
#
13-
# If this Pod runs only on iOS or OS X, then specify the platform and
14-
# the deployment target. You can optionally include the target after the platform.
15-
#
16-
17-
# s.platform = :ios
189
s.platform = :ios, "8.0"
19-
20-
# When using multiple platforms
21-
# s.ios.deployment_target = "5.0"
22-
# s.osx.deployment_target = "10.7"
23-
24-
25-
# ――― Source Location ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
26-
#
27-
# Specify the location from where the source should be retrieved.
28-
# Supports git, hg, bzr, svn and HTTP.
29-
#
30-
3110
s.source = { :git => "https://github.com/gilesvangruisen/Swift-YouTube-Player.git", :tag => "v#{s.version}" }
32-
33-
34-
# ――― Source Code ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
35-
#
36-
# CocoaPods is smart about how it includes source code. For source files
37-
# giving a folder will include any swift, h, m, mm, c & cpp files.
38-
# For header files it will include any header in the folder.
39-
# Not including the public_header_files will make all headers public.
40-
#
41-
4211
s.source_files = "YouTubePlayer/**/*.{swift,h,m}"
4312
s.exclude_files = "Classes/Exclude"
44-
45-
# s.public_header_files = "Classes/**/*.h"
46-
47-
48-
# ――― Resources ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
49-
#
50-
# A list of resources included with the Pod. These are copied into the
51-
# target bundle with a build phase script. Anything else will be cleaned.
52-
# You can preserve files from being cleaned, please don't preserve
53-
# non-essential files like tests, examples and documentation.
54-
#
55-
56-
# s.resource = "icon.png"
57-
# s.resources = "Resources/*.png"
58-
59-
# s.preserve_paths = "FilesToSave", "MoreFilesToSave"
60-
61-
62-
# ――― Project Linking ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
63-
#
64-
# Link your library with frameworks, or libraries. Libraries do not include
65-
# the lib prefix of their name.
66-
#
67-
68-
# s.framework = "SomeFramework"
69-
# s.frameworks = "SomeFramework", "AnotherFramework"
70-
71-
# s.library = "iconv"
72-
# s.libraries = "iconv", "xml2"
73-
74-
75-
# ――― Project Settings ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
76-
#
77-
# If your library depends on compiler flags you can set them in the xcconfig hash
78-
# where they will only apply to your library. If you depend on other Podspecs
79-
# you can include multiple dependencies to ensure it works.
80-
81-
# s.requires_arc = true
82-
83-
# s.xcconfig = { "HEADER_SEARCH_PATHS" => "$(SDKROOT)/usr/include/libxml2" }
84-
# s.dependency "JSONKit", "~> 1.4"
85-
8613
end

YouTubePlayer/YouTubePlayer.xcodeproj/project.pbxproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88

99
/* Begin PBXBuildFile section */
1010
50E5B9C91A4CAA050099BF69 /* YTPlayer.html in Resources */ = {isa = PBXBuildFile; fileRef = 50E5B9C81A4CAA050099BF69 /* YTPlayer.html */; };
11-
50E5B9CB1A4CAA150099BF69 /* VideoPlayerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50E5B9CA1A4CAA150099BF69 /* VideoPlayerView.swift */; };
11+
50E5B9CB1A4CAA150099BF69 /* YouTubePlayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50E5B9CA1A4CAA150099BF69 /* YouTubePlayer.swift */; };
1212
/* End PBXBuildFile section */
1313

1414
/* Begin PBXFileReference section */
1515
502AE85F1A475FD500306AD1 /* YouTubePlayer.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = YouTubePlayer.framework; sourceTree = BUILT_PRODUCTS_DIR; };
1616
502AE8631A475FD500306AD1 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; name = Info.plist; path = YouTubePlayer/Info.plist; sourceTree = "<group>"; };
1717
50E5B9C81A4CAA050099BF69 /* YTPlayer.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; name = YTPlayer.html; path = YouTubePlayer/YTPlayer.html; sourceTree = SOURCE_ROOT; };
18-
50E5B9CA1A4CAA150099BF69 /* VideoPlayerView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = VideoPlayerView.swift; path = YouTubePlayer/VideoPlayerView.swift; sourceTree = SOURCE_ROOT; };
18+
50E5B9CA1A4CAA150099BF69 /* YouTubePlayer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = YouTubePlayer.swift; path = YouTubePlayer/YouTubePlayer.swift; sourceTree = SOURCE_ROOT; };
1919
/* End PBXFileReference section */
2020

2121
/* Begin PBXFrameworksBuildPhase section */
@@ -48,7 +48,7 @@
4848
502AE8611A475FD500306AD1 /* YouTubePlayer */ = {
4949
isa = PBXGroup;
5050
children = (
51-
50E5B9CA1A4CAA150099BF69 /* VideoPlayerView.swift */,
51+
50E5B9CA1A4CAA150099BF69 /* YouTubePlayer.swift */,
5252
50E5B9C81A4CAA050099BF69 /* YTPlayer.html */,
5353
502AE8621A475FD500306AD1 /* Supporting Files */,
5454
);
@@ -142,7 +142,7 @@
142142
isa = PBXSourcesBuildPhase;
143143
buildActionMask = 2147483647;
144144
files = (
145-
50E5B9CB1A4CAA150099BF69 /* VideoPlayerView.swift in Sources */,
145+
50E5B9CB1A4CAA150099BF69 /* YouTubePlayer.swift in Sources */,
146146
);
147147
runOnlyForDeploymentPostprocessing = 0;
148148
};

YouTubePlayer/YouTubePlayer/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<key>CFBundlePackageType</key>
1616
<string>FMWK</string>
1717
<key>CFBundleShortVersionString</key>
18-
<string>0.1</string>
18+
<string>0.2</string>
1919
<key>CFBundleSignature</key>
2020
<string>????</string>
2121
<key>CFBundleVersion</key>

YouTubePlayer/YouTubePlayer/VideoPlayerView.swift renamed to YouTubePlayer/YouTubePlayer/YouTubePlayer.swift

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ private extension NSURL {
6262
}
6363

6464
public func videoIDFromYouTubeURL(videoURL: NSURL) -> String? {
65-
return videoURL.queryStringComponents()["v"] as String?
65+
return videoURL.queryStringComponents()["v"] as? String
6666
}
6767

6868
/** Embed and control YouTube videos */
@@ -87,15 +87,13 @@ public class YouTubePlayerView: UIView, UIWebViewDelegate {
8787
/** Used to respond to player events */
8888
public var delegate: YouTubePlayerDelegate?
8989

90-
// MARK: Various methods for initialization
9190

92-
override public init() {
93-
super.init()
94-
buildWebView(playerParameters())
95-
}
91+
// MARK: Various methods for initialization
9692

9793
override public init(frame: CGRect) {
9894
super.init(frame: frame)
95+
96+
printLog("initframe")
9997
buildWebView(playerParameters())
10098
}
10199

@@ -217,10 +215,10 @@ public class YouTubePlayerView: UIView, UIWebViewDelegate {
217215

218216
// Check for error
219217
if let error = error {
220-
println("Lookup error: no HTML file found for path, \(path)")
218+
printLog("Lookup error: no HTML file found for path, \(path)")
221219
}
222220

223-
return htmlString!
221+
return htmlString! as String
224222
}
225223

226224

@@ -255,12 +253,12 @@ public class YouTubePlayerView: UIView, UIWebViewDelegate {
255253

256254
// Check for error and return nil
257255
if let error = error {
258-
println("Error parsing JSON")
256+
printLog("Error parsing JSON")
259257
return nil
260258
}
261259

262260
// Success, return JSON string
263-
return NSString(data: jsonData!, encoding: NSUTF8StringEncoding)
261+
return NSString(data: jsonData!, encoding: NSUTF8StringEncoding) as? String
264262
}
265263

266264

@@ -271,38 +269,37 @@ public class YouTubePlayerView: UIView, UIWebViewDelegate {
271269
// Grab the last component of the queryString as string
272270
let data: String? = eventURL.queryStringComponents()["data"] as? String
273271

274-
if let host = eventURL.host {
275-
if let event = YouTubePlayerEvents(rawValue: host) {
276-
// Check event type and handle accordingly
277-
switch event {
278-
case .YouTubeIframeAPIReady:
279-
ready = true
280-
break
272+
if let host = eventURL.host, let event = YouTubePlayerEvents(rawValue: host) {
273+
274+
// Check event type and handle accordingly
275+
switch event {
276+
case .YouTubeIframeAPIReady:
277+
ready = true
278+
break
281279

282-
case .Ready:
283-
delegate?.playerReady(self)
280+
case .Ready:
281+
delegate?.playerReady(self)
284282

285-
break
283+
break
286284

287-
case .StateChange:
288-
if let newState = YouTubePlayerState(rawValue: data!) {
289-
playerState = newState
290-
delegate?.playerStateChanged(self, playerState: newState)
291-
}
285+
case .StateChange:
286+
if let newState = YouTubePlayerState(rawValue: data!) {
287+
playerState = newState
288+
delegate?.playerStateChanged(self, playerState: newState)
289+
}
292290

293-
break
291+
break
294292

295-
case .PlaybackQualityChange:
296-
if let newQuality = YouTubePlaybackQuality(rawValue: data!) {
297-
playbackQuality = newQuality
298-
delegate?.playerQualityChanged(self, playbackQuality: newQuality)
299-
}
293+
case .PlaybackQualityChange:
294+
if let newQuality = YouTubePlaybackQuality(rawValue: data!) {
295+
playbackQuality = newQuality
296+
delegate?.playerQualityChanged(self, playbackQuality: newQuality)
297+
}
300298

301-
break
299+
break
302300

303-
default:
304-
break
305-
}
301+
default:
302+
break
306303
}
307304
}
308305
}
@@ -315,8 +312,12 @@ public class YouTubePlayerView: UIView, UIWebViewDelegate {
315312
let url = request.URL
316313

317314
// Check if ytplayer event and, if so, pass to handleJSEvent
318-
if url.scheme == "ytplayer" { handleJSEvent(url) }
315+
if let url = url where url.scheme == "ytplayer" { handleJSEvent(url) }
319316

320317
return true
321318
}
322319
}
320+
321+
private func printLog(str: String) {
322+
println("[YouTubePlayer] \(str)")
323+
}

0 commit comments

Comments
 (0)