

It contains a few extra features and has readable and modifiable source code. Now add the following method to ViewController.This library is a reworking of YouTube's default embedding iframe API. To make this change, add the following line to the viewDidLoad method The ViewController instance as the delegate of the YTPlayerView
#Youtube iframe api update#
To update ViewController.m to handle some of the events, you first need to set YTPlayerViewDelegate is a protocol for handling playback events in the player. ViewController.h’s interface declaration as follows: ViewController : UIViewController ViewController.h so the class conforms to the delegate protocol.
#Youtube iframe api how to#
The following code shows how to update the interface declaration in It can be useful to programmatically handle playback events, such as playback state changesĪnd playback errors. Play and stop the video using native controls in addition to the player controls. Once the video thumbnail loads, you should be able to Stop buttons to the playVideo: and stopVideo: methods. Open your storyboard or Interface Builder and control-drag to connect the Play and The phone hardware or with built in UIView instances designed for this purpose, NotableĮxceptions are methods controlling the volume of the video, since these are controlled by

Naming may differ slightly to more closely match Objective-C coding guidelines. Most of the IFrame Player API functions have Objective-C equivalents, though some of the Now open ViewController.m and define these two functions: Open ViewController.h and add these methods, which Drag two buttons onto your View, labeling them Open up the storyboard or Interface Builder. Replace the loadWithVideoId: call with this code: NSDictionary *playerVars = : playerVars:playerVars] When a video is playing inline, theĬontaining iOS application can programmatically control playback. The playsinline parameter enables the video to playĭirectly in the view rather than playing fullscreen. LoadWithVideoId:playerVars:, that allows developers to pass additional player The ViewController::loadWithVideoId: method has a variant,

When the video thumbnail loads, tap the video thumbnail to ViewDidLoad method: [ayerView and run your application. Now open ViewController.m and add the following code to the end of your Previous step to your View Controller's playerView property. In Interface Builder, create a connection from the View element that you defined in the Open ViewController.h and add the following header: #import “YTPlayerView.h”Īlso add the following property: strong) IBOutlet YTPlayerView *playerView Select the Identity Inspector and change the class of the view to To add a YTPlayerView via Interface Builder or the Storyboard:

Add a YTPlayerView via Interface Builder or the Storyboard Sure that the Create Folder References for any added folders option is Make sure the Copy items intoĭestination group’s folder option is checked. These are available in the project's root directory in the Classes andĭrag these files and folders into your project. Pods -> Development Pods -> YouTube-Player-iOS-Helper -> Resources. Under Pods -> Development Pods -> YouTube-Player-iOS-Helper and If you open the workspace in Xcode, these are available Select YTPlayerView.h, YTPlayerView.m, and theĪssets folder. Open the sample project in Xcode or Finder. Once you have a local copy of the code, follow these steps:
#Youtube iframe api install#
To install the helper library manually, either download the source viaĬlone the repository. Tip: Remember that when using CocoaPods, you must open the. pod "youtube-ios-player-helper", "~> x.y.z"Īt the command line prompt, type pod install to update your workspace with the In that line, replace x.y.z with the latest pod version, which will be If your project uses CocoaPods, add the line below to your Podfile to install the library. Alternatively, the library and sourceįiles are available via the project’s GitHub page and can be copied into an existing The library is available to install via CocoaPods.The latest version of iOS, and that you add the following files when creating the This article assumes you have created a new Single View Application iOS project targeting This article describes the steps to install the library and get started YouTube player’s JavaScript code, thereby allowing the iOS application to control the WebView and a bridge between your application’s Objective-C code and the YouTube iframe player into an iOS application. The youtube-ios-player-helper is an open source library that helps you embed a
