Skip to content
YouTube video player for iOS, tvOS and macOS
Objective-C Swift Other
Branch: master
Clone or download

Latest commit


Type Name Latest commit message Commit time
Failed to load latest commit information.
.circleci First attempt to Upload to CodeCov May 6, 2019
.swiftpm/xcode/xcuserdata/soneejohn.xcuserdatad/xcschemes Add .swiftpm hidden folder Nov 15, 2019
Screenshots Update screenshot with iOS 7 player Oct 7, 2013
Scripts Fix static analyzer script for Xcode 10 Oct 11, 2018
XCDYouTubeKit Demo.xcworkspace Delete IDEWorkspaceChecks.plist Apr 27, 2020
XCDYouTubeKit Demo Update version to 2.14.0 May 12, 2020
XCDYouTubeKit Tests Report error instead of throwing assertion (closes #479) May 12, 2020
XCDYouTubeKit.xcodeproj Update version to 2.14.0 May 12, 2020
XCDYouTubeKit Report error instead of throwing assertion (closes #479) May 12, 2020
.cocoadocs.yml Use explicit cross references in documentation Jun 5, 2015
.codecov.yml Change the default branch on codecov to develop Oct 16, 2016
.gitignore Ignore release script in root directory Jan 31, 2020
.jazzy.yaml Update version to 2.14.0 May 12, 2020 Update CHANGELOG for version 2.14.0 May 12, 2020 Add CONTRIBUTING file Jan 11, 2015
LICENSE Update copyrights Jan 4, 2016
Makefile Don't align Makefile command lines with spaces Oct 11, 2018
Package.swift Revert “Set library type to dynamic” Apr 28, 2020 Point badges to the develop branch May 12, 2020 Update guide Feb 5, 2020
XCDYouTubeKit.podspec Update version to 2.14.0 May 12, 2020


Build Status Coverage Status Platform Pod Version Carthage Compatibility Swift Package Manager Compatibility License

XCDYouTubeKit is a YouTube video player for iOS, tvOS and macOS.

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

Donate button


  • Runs on iOS 8.0 and later
  • Runs on macOS 10.9 and later
  • Runs on tvOS 9.0 and later


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.


XCDYouTubeKit is available through CocoaPods, Carthage and Swift Package Manager.


pod "XCDYouTubeKit", "~> 2.14"


github "0xced/XCDYouTubeKit" ~> 2.14

Swift Package Manager:

Add XCDYouTubeKit to the dependencies value of your Package.swift

dependencies: [
	.package(url: "", from: "2.14.0")

Alternatively, you can manually use the provided static library or dynamic framework. In order to use the 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.


XCDYouTubeKit is fully documented.

iOS 8.0+ & tvOS (AVPlayerViewController)

AVPlayerViewController *playerViewController = [AVPlayerViewController new];
[self presentViewController:playerViewController animated:YES completion:nil];

__weak AVPlayerViewController *weakPlayerViewController = playerViewController;
[[XCDYouTubeClient defaultClient] getVideoWithIdentifier:videoIdentifier completionHandler:^(XCDYouTubeVideo * _Nullable video, NSError * _Nullable error) {
    if (video)
        NSDictionary *streamURLs = video.streamURLs;
        NSURL *streamURL = streamURLs[XCDYouTubeVideoQualityHTTPLiveStreaming] ?: streamURLs[@(XCDYouTubeVideoQualityHD720)] ?: streamURLs[@(XCDYouTubeVideoQualityMedium360)] ?: streamURLs[@(XCDYouTubeVideoQualitySmall240)];
        weakPlayerViewController.player = [AVPlayer playerWithURL:streamURL];
        [weakPlayerViewController.player play];
        [self dismissViewControllerAnimated:YES completion:nil];

iOS, tvOS and macOS

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

iOS 8.0

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

- (void) playVideo
	XCDYouTubeVideoPlayerViewController *videoPlayerViewController = [[XCDYouTubeVideoPlayerViewController alloc] initWithVideoIdentifier:@"9bZkp7q19f0"];
	[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerPlaybackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:videoPlayerViewController.moviePlayer];
	[self presentMoviePlayerViewControllerAnimated:videoPlayerViewController];

- (void) moviePlayerPlaybackDidFinish:(NSNotification *)notification
	[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:notification.object];
	MPMovieFinishReason finishReason = [notification.userInfo[MPMoviePlayerPlaybackDidFinishReasonUserInfoKey] integerValue];
	if (finishReason == MPMovieFinishReasonPlaybackError)
		NSError *error = notification.userInfo[XCDMoviePlayerPlaybackDidFinishErrorUserInfoKey];
		// Handle error

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.


Since version 2.2.0, XCDYouTubeKit produces logs. XCDYouTubeKit supports CocoaLumberjack but does not require it.

See the XCDYouTubeLogger class documentation for more information.


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


Cédric Luthi


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

You can’t perform that action at this time.