Skip to content

Commit

Permalink
Merge pull request #17 from gilesvangruisen/swift-1.2
Browse files Browse the repository at this point in the history
Swift 1.2
  • Loading branch information
gilesvangruisen committed Jun 20, 2015
2 parents 0e23e1d + 55ef6c3 commit 2fa00ad
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 115 deletions.
75 changes: 1 addition & 74 deletions YouTubePlayer.podspec
Original file line number Diff line number Diff line change
@@ -1,86 +1,13 @@
Pod::Spec.new do |s|

s.name = "YouTubePlayer"
s.version = "0.1"
s.version = "0.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" => "giles@vangruisen.com" }
s.social_media_url = "http://twitter.com/gilesvangruisen"

# ――― Platform Specifics ――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# If this Pod runs only on iOS or OS X, then specify the platform and
# the deployment target. You can optionally include the target after the platform.
#

# s.platform = :ios
s.platform = :ios, "8.0"

# When using multiple platforms
# s.ios.deployment_target = "5.0"
# s.osx.deployment_target = "10.7"


# ――― Source Location ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# Specify the location from where the source should be retrieved.
# Supports git, hg, bzr, svn and HTTP.
#

s.source = { :git => "https://github.com/gilesvangruisen/Swift-YouTube-Player.git", :tag => "v#{s.version}" }


# ――― Source Code ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# CocoaPods is smart about how it includes source code. For source files
# giving a folder will include any swift, h, m, mm, c & cpp files.
# For header files it will include any header in the folder.
# Not including the public_header_files will make all headers public.
#

s.source_files = "YouTubePlayer/**/*.{swift,h,m}"
s.exclude_files = "Classes/Exclude"

# s.public_header_files = "Classes/**/*.h"


# ――― Resources ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# A list of resources included with the Pod. These are copied into the
# target bundle with a build phase script. Anything else will be cleaned.
# You can preserve files from being cleaned, please don't preserve
# non-essential files like tests, examples and documentation.
#

# s.resource = "icon.png"
# s.resources = "Resources/*.png"

# s.preserve_paths = "FilesToSave", "MoreFilesToSave"


# ――― Project Linking ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# Link your library with frameworks, or libraries. Libraries do not include
# the lib prefix of their name.
#

# s.framework = "SomeFramework"
# s.frameworks = "SomeFramework", "AnotherFramework"

# s.library = "iconv"
# s.libraries = "iconv", "xml2"


# ――― Project Settings ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# If your library depends on compiler flags you can set them in the xcconfig hash
# where they will only apply to your library. If you depend on other Podspecs
# you can include multiple dependencies to ensure it works.

# s.requires_arc = true

# s.xcconfig = { "HEADER_SEARCH_PATHS" => "$(SDKROOT)/usr/include/libxml2" }
# s.dependency "JSONKit", "~> 1.4"

end
8 changes: 4 additions & 4 deletions YouTubePlayer/YouTubePlayer.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@

/* Begin PBXBuildFile section */
50E5B9C91A4CAA050099BF69 /* YTPlayer.html in Resources */ = {isa = PBXBuildFile; fileRef = 50E5B9C81A4CAA050099BF69 /* YTPlayer.html */; };
50E5B9CB1A4CAA150099BF69 /* VideoPlayerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50E5B9CA1A4CAA150099BF69 /* VideoPlayerView.swift */; };
50E5B9CB1A4CAA150099BF69 /* YouTubePlayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50E5B9CA1A4CAA150099BF69 /* YouTubePlayer.swift */; };
/* End PBXBuildFile section */

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

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -48,7 +48,7 @@
502AE8611A475FD500306AD1 /* YouTubePlayer */ = {
isa = PBXGroup;
children = (
50E5B9CA1A4CAA150099BF69 /* VideoPlayerView.swift */,
50E5B9CA1A4CAA150099BF69 /* YouTubePlayer.swift */,
50E5B9C81A4CAA050099BF69 /* YTPlayer.html */,
502AE8621A475FD500306AD1 /* Supporting Files */,
);
Expand Down Expand Up @@ -142,7 +142,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
50E5B9CB1A4CAA150099BF69 /* VideoPlayerView.swift in Sources */,
50E5B9CB1A4CAA150099BF69 /* YouTubePlayer.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
2 changes: 1 addition & 1 deletion YouTubePlayer/YouTubePlayer/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>0.1</string>
<string>0.2</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private extension NSURL {
}

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

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

// MARK: Various methods for initialization

override public init() {
super.init()
buildWebView(playerParameters())
}
// MARK: Various methods for initialization

override public init(frame: CGRect) {
super.init(frame: frame)

printLog("initframe")
buildWebView(playerParameters())
}

Expand Down Expand Up @@ -217,10 +215,10 @@ public class YouTubePlayerView: UIView, UIWebViewDelegate {

// Check for error
if let error = error {
println("Lookup error: no HTML file found for path, \(path)")
printLog("Lookup error: no HTML file found for path, \(path)")
}

return htmlString!
return htmlString! as String
}


Expand Down Expand Up @@ -255,12 +253,12 @@ public class YouTubePlayerView: UIView, UIWebViewDelegate {

// Check for error and return nil
if let error = error {
println("Error parsing JSON")
printLog("Error parsing JSON")
return nil
}

// Success, return JSON string
return NSString(data: jsonData!, encoding: NSUTF8StringEncoding)
return NSString(data: jsonData!, encoding: NSUTF8StringEncoding) as? String
}


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

if let host = eventURL.host {
if let event = YouTubePlayerEvents(rawValue: host) {
// Check event type and handle accordingly
switch event {
case .YouTubeIframeAPIReady:
ready = true
break
if let host = eventURL.host, let event = YouTubePlayerEvents(rawValue: host) {

// Check event type and handle accordingly
switch event {
case .YouTubeIframeAPIReady:
ready = true
break

case .Ready:
delegate?.playerReady(self)
case .Ready:
delegate?.playerReady(self)

break
break

case .StateChange:
if let newState = YouTubePlayerState(rawValue: data!) {
playerState = newState
delegate?.playerStateChanged(self, playerState: newState)
}
case .StateChange:
if let newState = YouTubePlayerState(rawValue: data!) {
playerState = newState
delegate?.playerStateChanged(self, playerState: newState)
}

break
break

case .PlaybackQualityChange:
if let newQuality = YouTubePlaybackQuality(rawValue: data!) {
playbackQuality = newQuality
delegate?.playerQualityChanged(self, playbackQuality: newQuality)
}
case .PlaybackQualityChange:
if let newQuality = YouTubePlaybackQuality(rawValue: data!) {
playbackQuality = newQuality
delegate?.playerQualityChanged(self, playbackQuality: newQuality)
}

break
break

default:
break
}
default:
break
}
}
}
Expand All @@ -315,8 +312,12 @@ public class YouTubePlayerView: UIView, UIWebViewDelegate {
let url = request.URL

// Check if ytplayer event and, if so, pass to handleJSEvent
if url.scheme == "ytplayer" { handleJSEvent(url) }
if let url = url where url.scheme == "ytplayer" { handleJSEvent(url) }

return true
}
}

private func printLog(str: String) {
println("[YouTubePlayer] \(str)")
}

0 comments on commit 2fa00ad

Please sign in to comment.