Skip to content

YouTube video player for iOS and OS X

License

Notifications You must be signed in to change notification settings

gomera/XCDYouTubeKit

 
 

Repository files navigation

About

Build Status Coverage Status Platform Pod Version Carthage Compatibility License

XCDYouTubeKit is a YouTube video player for iOS and OS X.

Are you enjoying XCDYouTubeKit? You can say thank you with a tweet. I am also accepting donations. ;-)

Donate button

Requirements

  • Runs on iOS 7.0 and later
  • Runs on OS X 10.9 and later

Warning

XCDYouTubeKit is against the YouTube Terms of Service. The only official way of playing a YouTube video inside an app is with a web view and the iframe player API. Unfortunately, this is very slow and quite ugly, so I wrote this player to give users a better viewing experience.

Installation

XCDYouTubeKit is available through CocoaPods and Carthage.

CocoaPods:

pod "XCDYouTubeKit", "~> 2.3.0"

Carthage:

github "0xced/XCDYouTubeKit" ~> 2.3.0

Alternatively, you can manually use the provided static library on iOS or dynamic framework on OS X. In order to use the iOS static library, you must:

  1. Create a workspace (File → New → Workspace…)
  2. Add your project to the workspace
  3. Add the XCDYouTubeKit project to the workspace
  4. Drag and drop the libXCDYouTubeKit.a file referenced from XCDYouTubeKit → Products → libXCDYouTubeKit.a into the Link Binary With Libraries build phase of your app’s target.

These steps will ensure that #import <XCDYouTubeKit/XCDYouTubeKit.h> will work properly in your project.

Usage

XCDYouTubeKit is fully documented.

iOS and OS X

NSString *videoIdentifier = @"EdeVaT-zZt4"; // A 11 characters YouTube video identifier
[[XCDYouTubeClient defaultClient] getVideoWithIdentifier:videoIdentifier completionHandler:^(XCDYouTubeVideo *video, NSError *error) {
	if (video)
	{
		// Do something with the `video` object
	}
	else
	{
		// Handle error
	}
}];

iOS only

On iOS, you can use the class XCDYouTubeVideoPlayerViewController the same way you use a MPMoviePlayerViewController, except you initialize it with a YouTube video identifier instead of a content URL.

Present the video in full-screen

XCDYouTubeVideoPlayerViewController *videoPlayerViewController = [[XCDYouTubeVideoPlayerViewController alloc] initWithVideoIdentifier:@"9bZkp7q19f0"];
[self presentMoviePlayerViewControllerAnimated:videoPlayerViewController];

Present the video in a non full-screen view

XCDYouTubeVideoPlayerViewController *videoPlayerViewController = [[XCDYouTubeVideoPlayerViewController alloc] initWithVideoIdentifier:@"9bZkp7q19f0"];
[videoPlayerViewController presentInView:self.videoContainerView];
[videoPlayerViewController.moviePlayer play];

See the demo project for more sample code.

Logging

Since version 2.2.0, XCDYouTubeKit produces logs. XCDYouTubeKit supports CocoaLumberjack but does not require it. If your project includes CocoaLumberjack, all logs will be routed through CocoaLumberjack, else logs will be emitted with NSLog.

The context for identifying all XCDYouTubeKit logs in CocoaLumberjack is the number (NSInteger)0xced70676. Beware, CocoaLumberjack contexts are NSIntegers, don’t forget the cast.

Controlling log levels

If you are using CocoaLumberjack, you are responsible for controlling the log levels with the CocoaLumberjack APIs.

If you are not using CocoaLumberjack, you can control the log levels with the XCDYouTubeKitLogLevel environment variable. The log levels are the same as CocoaLumberjack, with the addition of the trace level.

Level Value
Error 0x01
Warning 0x02
Info 0x04
Debug 0x08
Verbose 0x10
Trace 0x20

The levels are bitmasks, so you can combine them. For example, if you want to log error, warning and info levels, set the XCDYouTubeKitLogLevel environment variable to 0x7.

If you do not set the XCDYouTubeKitLogLevel environment variable, only warning and error levels are logged.

Credits

The URL extraction algorithms in XCDYouTubeKit are inspired by the YouTube extractor module of the youtube-dl project.

Contact

Cédric Luthi

License

XCDYouTubeKit is available under the MIT license. See the LICENSE file for more information.

About

YouTube video player for iOS and OS X

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Objective-C 95.6%
  • Shell 1.7%
  • C++ 1.0%
  • Swift 0.7%
  • C 0.5%
  • Ruby 0.3%
  • Other 0.2%