ইউটিউব হেল্পার লাইব্রেরির সাথে iOS অ্যাপ্লিকেশনগুলিতে YouTube ভিডিওগুলি এম্বেড করুন৷
সেভ করা পৃষ্ঠা গুছিয়ে রাখতে 'সংগ্রহ' ব্যবহার করুন
আপনার পছন্দ অনুযায়ী কন্টেন্ট সেভ করুন ও সঠিক বিভাগে রাখুন।
youtube-ios-player-helper
হল একটি ওপেন সোর্স লাইব্রেরি যা আপনাকে একটি iOS অ্যাপ্লিকেশনে একটি YouTube iframe প্লেয়ার এম্বেড করতে সাহায্য করে৷ লাইব্রেরি একটি WebView
তৈরি করে এবং আপনার অ্যাপ্লিকেশনের অবজেক্টিভ-সি কোড এবং YouTube প্লেয়ারের জাভাস্ক্রিপ্ট কোডের মধ্যে একটি সেতু তৈরি করে, যার ফলে iOS অ্যাপ্লিকেশনটিকে YouTube প্লেয়ারকে নিয়ন্ত্রণ করার অনুমতি দেয়। এই নিবন্ধটি লাইব্রেরি ইনস্টল করার এবং আপনার iOS অ্যাপ্লিকেশন থেকে এটি ব্যবহার শুরু করার পদক্ষেপগুলি বর্ণনা করে৷
স্থাপন
এই নিবন্ধটি অনুমান করে যে আপনি iOS এর সর্বশেষ সংস্করণকে লক্ষ্য করে একটি নতুন একক দৃশ্য অ্যাপ্লিকেশন iOS প্রকল্প তৈরি করেছেন এবং প্রকল্পটি তৈরি করার সময় আপনি নিম্নলিখিত ফাইলগুলি যুক্ত করেছেন:
-
Main.storyboard
-
ViewController.h
-
ViewController.m
আপনি CocoaPods মাধ্যমে বা প্রকল্পের GitHub পৃষ্ঠা থেকে লাইব্রেরি এবং উত্স ফাইল অনুলিপি করে লাইব্রেরি ইনস্টল করতে পারেন।
- লাইব্রেরিটি CocoaPods এর মাধ্যমে ইনস্টল করার জন্য উপলব্ধ। বিকল্পভাবে, লাইব্রেরি এবং উত্স ফাইলগুলি প্রকল্পের GitHub পৃষ্ঠার মাধ্যমে উপলব্ধ এবং একটি বিদ্যমান প্রকল্পে অনুলিপি করা যেতে পারে।
কোকোপডসের মাধ্যমে লাইব্রেরি ইনস্টল করুন
যদি আপনার প্রকল্পটি CocoaPods ব্যবহার করে, তাহলে লাইব্রেরি ইনস্টল করতে আপনার পডফাইলে নীচের লাইনটি যোগ করুন। সেই লাইনে, xyz
সর্বশেষ পড সংস্করণ দিয়ে প্রতিস্থাপন করুন, যা প্রকল্পের গিটহাব পৃষ্ঠায় চিহ্নিত করা হবে।
pod "youtube-ios-player-helper", "~> x.y.z"
কমান্ড লাইন প্রম্পটে, নির্ভরশীলতার সাথে আপনার ওয়ার্কস্পেস আপডেট করতে pod install
টাইপ করুন।
টিপ: মনে রাখবেন যে CocoaPods ব্যবহার করার সময়, আপনাকে অবশ্যই .xcworkspace
ফাইলটি Xcode-এ খুলতে হবে, .xcodeproj
ফাইলে নয়৷
আরও জানতে CocoaPods টিউটোরিয়াল দেখুন।
লাইব্রেরিটি ম্যানুয়ালি ইনস্টল করুন
সাহায্যকারী লাইব্রেরিটি ম্যানুয়ালি ইনস্টল করতে, হয় গিটহাবের ডাউনলোড লিঙ্কের মাধ্যমে উত্সটি ডাউনলোড করুন বা সংগ্রহস্থলটি ক্লোন করুন। একবার আপনার কাছে কোডের একটি স্থানীয় অনুলিপি হয়ে গেলে, এই পদক্ষেপগুলি অনুসরণ করুন:
এক্সকোড বা ফাইন্ডারে নমুনা প্রকল্পটি খুলুন।
YTPlayerView.h
, YTPlayerView.m
, এবং সম্পদ ফোল্ডার নির্বাচন করুন। আপনি যদি Xcode-এ ওয়ার্কস্পেস খোলেন, তাহলে এগুলো Pods -> Development Pods -> YouTube-Player-iOS-Helper এবং Pods -> Development Pods -> YouTube-Player-iOS-Helper -> Resources-এর অধীনে পাওয়া যায়। ফাইন্ডারে, এগুলো ক্লাস এবং অ্যাসেট ডিরেক্টরিতে প্রোজেক্টের রুট ডিরেক্টরিতে পাওয়া যায়।
আপনার প্রকল্পে এই ফাইল এবং ফোল্ডার টেনে আনুন. নিশ্চিত করুন যে আইটেমগুলিকে গন্তব্য গোষ্ঠীর ফোল্ডারে অনুলিপি করুন বিকল্পটি চেক করা হয়েছে৷ সম্পদ ফোল্ডার টেনে আনার সময়, নিশ্চিত করুন যে কোনো যোগ করা ফোল্ডারের জন্য ফোল্ডার রেফারেন্স তৈরি করুন বিকল্পটি চেক করা আছে।
লাইব্রেরি এখন ইনস্টল করা উচিত।
ইন্টারফেস বিল্ডার বা স্টোরিবোর্ডের মাধ্যমে একটি YTPlayerView
যোগ করুন
ইন্টারফেস বিল্ডার বা স্টোরিবোর্ডের মাধ্যমে একটি YTPlayerView
যোগ করতে:
আপনার ভিউতে একটি UIView
দৃষ্টান্ত টেনে আনুন।
আইডেন্টিটি ইন্সপেক্টর নির্বাচন করুন এবং ভিউটির ক্লাস YTPlayerView
এ পরিবর্তন করুন।
ViewController.h
খুলুন এবং নিম্নলিখিত শিরোনাম যোগ করুন:
#import “YTPlayerView.h”
এছাড়াও নিম্নলিখিত সম্পত্তি যোগ করুন:
@property(nonatomic, strong) IBOutlet YTPlayerView *playerView;
ইন্টারফেস বিল্ডারে, আপনার ভিউ কন্ট্রোলারের playerView
সম্পত্তির সাথে পূর্ববর্তী ধাপে সংজ্ঞায়িত ভিউ উপাদান থেকে একটি সংযোগ তৈরি করুন।
এখন ViewController.m
খুলুন এবং আপনার viewDidLoad
পদ্ধতির শেষে নিম্নলিখিত কোডটি যোগ করুন:
[self.playerView loadWithVideoId:@"M7lc1UVf-VE"];
আপনার অ্যাপ্লিকেশন তৈরি করুন এবং চালান। ভিডিও থাম্বনেইল লোড হলে, পূর্ণস্ক্রীন ভিডিও প্লেয়ার চালু করতে ভিডিও থাম্বনেইলে আলতো চাপুন।
ভিডিও প্লেব্যাক নিয়ন্ত্রণ করুন
ViewController::loadWithVideoId:
পদ্ধতির একটি বৈকল্পিক আছে, loadWithVideoId:playerVars:
, যা বিকাশকারীদের ভিউতে অতিরিক্ত প্লেয়ার ভেরিয়েবল পাস করতে দেয়। এই প্লেয়ার ভেরিয়েবলগুলি IFrame Player API-এর প্লেয়ার প্যারামিটারগুলির সাথে মিলে যায়৷ playsinline
প্যারামিটার ভিডিওটিকে পূর্ণস্ক্রীনে খেলার পরিবর্তে সরাসরি ভিউতে প্লে করতে সক্ষম করে। যখন একটি ভিডিও ইনলাইনে চলছে, তখন iOS অ্যাপ্লিকেশনটি প্রোগ্রাম্যাটিকভাবে প্লেব্যাক নিয়ন্ত্রণ করতে পারে।
loadWithVideoId:
এই কোড দিয়ে কল করুন:
NSDictionary *playerVars = @{
@"playsinline" : @1,
};
[self.playerView loadWithVideoId:@"M7lc1UVf-VE" playerVars:playerVars];
স্টোরিবোর্ড বা ইন্টারফেস বিল্ডার খুলুন। আপনার ভিউতে দুটি বোতাম টেনে আনুন, তাদের প্লে এবং স্টপ লেবেল করুন। ViewController.h
খুলুন এবং এই পদ্ধতিগুলি যোগ করুন, যা বোতামগুলিতে ম্যাপ করা হবে:
- (IBAction)playVideo:(id)sender;
- (IBAction)stopVideo:(id)sender;
এখন ViewController.m
খুলুন এবং এই দুটি ফাংশন সংজ্ঞায়িত করুন:
- (IBAction)playVideo:(id)sender {
[self.playerView playVideo];
}
- (IBAction)stopVideo:(id)sender {
[self.playerView stopVideo];
}
আইফ্রেম প্লেয়ার এপিআই ফাংশনের বেশিরভাগেরই অবজেক্টিভ-সি সমতুল্য রয়েছে, যদিও কিছু নামকরণে কিছুটা ভিন্নতা থাকতে পারে যাতে অবজেক্টিভ-সি কোডিং নির্দেশিকা আরও ঘনিষ্ঠভাবে মেলে। উল্লেখযোগ্য ব্যতিক্রমগুলি হল ভিডিওর ভলিউম নিয়ন্ত্রণ করার পদ্ধতি, যেহেতু এগুলি ফোন হার্ডওয়্যার দ্বারা নিয়ন্ত্রিত হয় বা এই উদ্দেশ্যে ডিজাইন করা UIView
দৃষ্টান্তগুলির দ্বারা নিয়ন্ত্রিত হয়, যেমন MPVolumeView
।
আপনার স্টোরিবোর্ড বা ইন্টারফেস বিল্ডার খুলুন এবং প্লে এবং স্টপ বোতামগুলিকে playVideo:
এবং stopVideo:
পদ্ধতিতে সংযোগ করতে নিয়ন্ত্রণ-টেনে আনুন।
এখন অ্যাপ্লিকেশন তৈরি করুন এবং চালান। একবার ভিডিও থাম্বনেল লোড হয়ে গেলে, আপনি প্লেয়ার নিয়ন্ত্রণ ছাড়াও নেটিভ কন্ট্রোল ব্যবহার করে ভিডিও চালাতে এবং বন্ধ করতে সক্ষম হবেন।
প্লেয়ার কলব্যাকগুলি পরিচালনা করুন
প্লেব্যাক ইভেন্টগুলি যেমন প্লেব্যাক স্টেট পরিবর্তন এবং প্লেব্যাক ত্রুটিগুলি প্রোগ্রাম্যাটিকভাবে পরিচালনা করতে এটি কার্যকর হতে পারে। JavaScript API-এ, ইভেন্ট শ্রোতাদের সাথে এটি করা হয়। অবজেক্টিভ-সি-তে, এটি একটি প্রতিনিধির সাথে করা হয়।
নিম্নলিখিত কোডটি দেখায় কিভাবে ViewController.h
এ ইন্টারফেস ঘোষণা আপডেট করতে হয় যাতে ক্লাসটি প্রতিনিধি প্রোটোকলের সাথে সামঞ্জস্যপূর্ণ হয়। নিম্নরূপ ViewController.h
এর ইন্টারফেস ঘোষণা পরিবর্তন করুন:
@interface ViewController : UIViewController<YTPlayerViewDelegate>
YTPlayerViewDelegate
হল প্লেয়ারে প্লেব্যাক ইভেন্টগুলি পরিচালনা করার জন্য একটি প্রোটোকল৷ কিছু ইভেন্ট পরিচালনা করার জন্য ViewController.m
আপডেট করতে, আপনাকে প্রথমে YTPlayerView
উদাহরণের প্রতিনিধি হিসাবে ViewController
দৃষ্টান্ত সেট করতে হবে। এই পরিবর্তন করতে, ViewController.h
এ viewDidLoad
পদ্ধতিতে নিম্নলিখিত লাইনটি যোগ করুন।
self.playerView.delegate = self;
এখন ViewController.m
এ নিম্নলিখিত পদ্ধতি যোগ করুন:
- (void)playerView:(YTPlayerView *)playerView didChangeToState:(YTPlayerState)state {
switch (state) {
case kYTPlayerStatePlaying:
NSLog(@"Started playback");
break;
case kYTPlayerStatePaused:
NSLog(@"Paused playback");
break;
default:
break;
}
}
অ্যাপ্লিকেশনটি তৈরি করুন এবং চালান। প্লেয়ারের অবস্থার পরিবর্তনের সাথে সাথে Xcode-এ লগ আউটপুট দেখুন। ভিডিও চালানো বা বন্ধ হয়ে গেলে আপনার আপডেট দেখতে হবে।
লাইব্রেরি সুবিধা এবং পঠনযোগ্যতার জন্য kYT*
উপসর্গ দিয়ে শুরু হওয়া ধ্রুবক প্রদান করে। এই ধ্রুবকগুলির সম্পূর্ণ তালিকার জন্য, YTPlayerView.m
দেখুন।
সর্বোত্তম অনুশীলন এবং সীমাবদ্ধতা
একটি WebView
তৈরি করে এবং মৌলিক প্লেয়ারের জন্য প্রয়োজনীয় HTML এবং জাভাস্ক্রিপ্ট রেন্ডার করার মাধ্যমে লাইব্রেরিটি IFrame Player API-এর উপরে তৈরি করে। লাইব্রেরির লক্ষ্য হল যতটা সম্ভব সহজে ব্যবহার করা, বান্ডলিং পদ্ধতি যা ডেভেলপারদের প্রায়শই একটি প্যাকেজে লিখতে হয়। কয়েকটি সীমাবদ্ধতা রয়েছে যা লক্ষ করা উচিত:
- লাইব্রেরি একাধিক
YTPlayerView
দৃষ্টান্তে সমসাময়িক ভিডিও প্লেব্যাক সমর্থন করে না। আপনার অ্যাপ্লিকেশানে একাধিক YTPlayerView
দৃষ্টান্ত থাকলে, একটি প্রস্তাবিত সর্বোত্তম অভ্যাস হল একটি ভিন্ন দৃষ্টান্তে প্লেব্যাক শুরু করার আগে যেকোনো বিদ্যমান দৃষ্টান্তে প্লেব্যাক থামানো বা বন্ধ করা। প্রজেক্টের সাথে পাঠানো উদাহরণের অ্যাপ্লিকেশনে, প্লেব্যাক শুরু হতে চলেছে এমন বিজ্ঞপ্তি পাঠানোর জন্য ভিউ কন্ট্রোলাররা NSNotificationCenter
ব্যবহার করে। অন্যান্য ভিউ কন্ট্রোলারদের জানানো হয়েছে এবং তাদের YTPlayerView
দৃষ্টান্তে প্লেব্যাক থামিয়ে দেবে। - সম্ভব হলে আপনার বিদ্যমান, লোড করা
YTPlayerView
দৃষ্টান্তগুলি পুনরায় ব্যবহার করুন। যখন একটি ভিউতে একটি ভিডিও পরিবর্তন করতে হবে, তখন একটি নতুন UIView
ইনস্ট্যান্স বা একটি নতুন YTPlayerView
উদাহরণ তৈরি করবেন না এবং loadVideoId:
বা loadPlaylistId:
কল করবেন না। পরিবর্তে, cueVideoById:startSeconds:
ফাংশনের পরিবার ব্যবহার করুন, যা WebView
পুনরায় লোড করে না। সম্পূর্ণ IFrame প্লেয়ার লোড করার সময় একটি লক্ষণীয় বিলম্ব আছে। - এই প্লেয়ার ব্যক্তিগত ভিডিও চালাতে পারে না, তবে এটি তালিকাভুক্ত ভিডিওগুলি চালাতে পারে৷ যেহেতু এই লাইব্রেরিটি বিদ্যমান iframe প্লেয়ারকে মোড়ানো, তাই প্লেয়ারের আচরণ মোবাইল ব্রাউজারে একটি ওয়েবপেজে এমবেড করা প্লেয়ারের মতো প্রায় অভিন্ন হওয়া উচিত।
অন্য কিছু উল্লেখ না করা থাকলে, এই পৃষ্ঠার কন্টেন্ট Creative Commons Attribution 4.0 License-এর অধীনে এবং কোডের নমুনাগুলি Apache 2.0 License-এর অধীনে লাইসেন্স প্রাপ্ত। আরও জানতে, Google Developers সাইট নীতি দেখুন। Java হল Oracle এবং/অথবা তার অ্যাফিলিয়েট সংস্থার রেজিস্টার্ড ট্রেডমার্ক।
2023-02-22 UTC-তে শেষবার আপডেট করা হয়েছে।
[[["সহজে বোঝা যায়","easyToUnderstand","thumb-up"],["আমার সমস্যার সমাধান হয়েছে","solvedMyProblem","thumb-up"],["অন্যান্য","otherUp","thumb-up"]],[["এতে আমার প্রয়োজনীয় তথ্য নেই","missingTheInformationINeed","thumb-down"],["খুব জটিল / অনেক ধাপ","tooComplicatedTooManySteps","thumb-down"],["পুরনো","outOfDate","thumb-down"],["অনুবাদ সংক্রান্ত সমস্যা","translationIssue","thumb-down"],["নমুনা / কোড সংক্রান্ত সমস্যা","samplesCodeIssue","thumb-down"],["অন্যান্য","otherDown","thumb-down"]],["2023-02-22 UTC-তে শেষবার আপডেট করা হয়েছে।"],[[["\u003cp\u003eThis library, \u003ccode\u003eyoutube-ios-player-helper\u003c/code\u003e, facilitates embedding a YouTube iframe player within an iOS application by creating a \u003ccode\u003eWebView\u003c/code\u003e and bridging Objective-C code with the player's JavaScript.\u003c/p\u003e\n"],["\u003cp\u003eInstallation is possible via CocoaPods by adding a specific line to the Podfile, or manually by downloading the source code from the project's GitHub page and dragging specific files into your iOS project.\u003c/p\u003e\n"],["\u003cp\u003eA \u003ccode\u003eYTPlayerView\u003c/code\u003e can be added through Interface Builder or Storyboard by dragging a \u003ccode\u003eUIView\u003c/code\u003e, changing its class to \u003ccode\u003eYTPlayerView\u003c/code\u003e, and connecting it to a \u003ccode\u003eplayerView\u003c/code\u003e property in the \u003ccode\u003eViewController.h\u003c/code\u003e file.\u003c/p\u003e\n"],["\u003cp\u003eThe library allows for controlling video playback, enabling inline play and manipulation using the IFrame Player API through Objective-C equivalent methods.\u003c/p\u003e\n"],["\u003cp\u003eThe library allows the handling of playback events, such as start and stop, through a delegate protocol, \u003ccode\u003eYTPlayerViewDelegate\u003c/code\u003e, where the \u003ccode\u003eViewController\u003c/code\u003e conforms to this protocol to capture those events.\u003c/p\u003e\n"]]],["The `youtube-ios-player-helper` library enables embedding and controlling a YouTube iframe player within an iOS app. Installation is via CocoaPods or manual file copying from GitHub. To use, a `YTPlayerView` is added to the storyboard, connected to a `ViewController`, and initialized with a video ID. Playback is controlled through Objective-C methods (e.g., `playVideo`, `stopVideo`) linked to UI elements. Developers can pass player variables, and the library supports delegate-based event handling for playback states. The library is based on the iFrame Player API and includes a few limitations.\n"],null,["# Embed YouTube Videos in iOS Applications with the YouTube Helper Library\n\nThe `youtube-ios-player-helper` is an open source library that helps you embed a\nYouTube iframe player into an iOS application. The library creates a\n`WebView` and a bridge between your application's Objective-C code and the\nYouTube player's JavaScript code, thereby allowing the iOS application to control the\nYouTube player. This article describes the steps to install the library and get started\nusing it from your iOS application.\n\nInstallation\n------------\n\nThis article assumes you have created a new Single View Application iOS project targeting\nthe latest version of iOS, and that you add the following files when creating the\nproject:\n\n- `Main.storyboard`\n- `ViewController.h`\n- `ViewController.m`\n\nYou can install the library via\n[CocoaPods](https://cocoapods.org/) or by copying the library\nand source files from the\n[project's GitHub page](https://github.com/youtube/youtube-ios-player-helper).\n\n- The library is available to install via CocoaPods. Alternatively, the library and source files are available via the project's GitHub page and can be copied into an existing project.\n\n### Install the library via CocoaPods\n\nIf your project uses CocoaPods, add the line below to your Podfile to install the library.\nIn that line, replace `x.y.z` with the latest pod version, which will be\nidentified on the project's GitHub page. \n\n```text\npod \"youtube-ios-player-helper\", \"~\u003e x.y.z\"\n```\n\nAt the command line prompt, type `pod install` to update your workspace with the\ndependencies.\n\nTip: Remember that when using CocoaPods, you must open the `.xcworkspace` file\nin Xcode, not the `.xcodeproj` file.\n\nCheck out the [CocoaPods\ntutorial](https://guides.cocoapods.org/using/getting-started.html) to learn more.\n\n### Manually install the library\n\nTo install the helper library manually, either download the source via\n[GitHub's download link](https://github.com/youtube/youtube-ios-player-helper) or\nclone the repository. Once you have a local copy of the code, follow these steps:\n\n1. Open the sample project in Xcode or Finder.\n\n2. Select `YTPlayerView.h`, `YTPlayerView.m`, and the\n **Assets** folder. If you open the workspace in Xcode, these are available\n under **Pods -\\\u003e Development Pods -\\\u003e YouTube-Player-iOS-Helper** and\n **Pods -\\\u003e Development Pods -\\\u003e YouTube-Player-iOS-Helper -\\\u003e Resources** . In the Finder,\n these are available in the project's root directory in the **Classes** and\n **Assets** directories.\n\n3. Drag these files and folders into your project. Make sure the **Copy items into\n destination group's folder** option is checked. When dragging the Assets folder, make\n sure that the **Create Folder References for any added folders** option is\n checked.\n\nThe library should now be installed.\n\nAdd a `YTPlayerView` via Interface Builder or the Storyboard\n------------------------------------------------------------\n\nTo add a `YTPlayerView` via Interface Builder or the Storyboard:\n\n1. Drag a `UIView` instance onto your View.\n\n2. Select the Identity Inspector and change the class of the view to\n `YTPlayerView`.\n\n3. Open `ViewController.h` and add the following header:\n\n ```objective-c\n #import \"YTPlayerView.h\"\n ```\n\n Also add the following property: \n\n ```objective-c\n @property(nonatomic, strong) IBOutlet YTPlayerView *playerView;\n ```\n4. In Interface Builder, create a connection from the View element that you defined in the\n previous step to your View Controller's `playerView` property.\n\n5. Now open `ViewController.m` and add the following code to the end of your\n `viewDidLoad` method:\n\n ```objective-c\n [self.playerView loadWithVideoId:@\"M7lc1UVf-VE\"];\n ```\n\nBuild and run your application. When the video thumbnail loads, tap the video thumbnail to\nlaunch the fullscreen video player.\n\nControl video playback\n----------------------\n\nThe `ViewController::loadWithVideoId:` method has a variant,\n`loadWithVideoId:playerVars:`, that allows developers to pass additional player\nvariables to the view. These player variables correspond to the\n[player parameters in the\nIFrame Player API](https://developers.google.com/youtube/player_parameters). The `playsinline` parameter enables the video to play\ndirectly in the view rather than playing fullscreen. When a video is playing inline, the\ncontaining iOS application can programmatically control playback.\n\nReplace the `loadWithVideoId:` call with this code: \n\n```objective-c\nNSDictionary *playerVars = @{\n @\"playsinline\" : @1,\n};\n[self.playerView loadWithVideoId:@\"M7lc1UVf-VE\" playerVars:playerVars];\n```\n\nOpen up the storyboard or Interface Builder. Drag two buttons onto your View, labeling them\n**Play** and **Stop** . Open `ViewController.h` and add these methods, which\nwill be mapped to the buttons: \n\n```objective-c\n- (IBAction)playVideo:(id)sender;\n- (IBAction)stopVideo:(id)sender;\n```\n\nNow open `ViewController.m` and define these two functions: \n\n```objective-c\n- (IBAction)playVideo:(id)sender {\n [self.playerView playVideo];\n}\n\n- (IBAction)stopVideo:(id)sender {\n [self.playerView stopVideo];\n}\n```\n\nMost of the IFrame Player API functions have Objective-C equivalents, though some of the\nnaming may differ slightly to more closely match Objective-C coding guidelines. Notable\nexceptions are methods controlling the volume of the video, since these are controlled by\nthe phone hardware or with built in `UIView` instances designed for this purpose,\nsuch as [`MPVolumeView`](https://developer.apple.com/library/ios/documentation/mediaplayer/reference/MPVolumeView_Class/Reference/Reference.html).\n\nOpen your storyboard or Interface Builder and control-drag to connect the **Play** and\n**Stop** buttons to the `playVideo:` and `stopVideo:` methods.\n\nNow build and run the application. Once the video thumbnail loads, you should be able to\nplay and stop the video using native controls in addition to the player controls.\n\nHandle player callbacks\n-----------------------\n\nIt can be useful to programmatically handle playback events, such as playback state changes\nand playback errors. In the JavaScript API, this is done with\n[event listeners](https://developers.google.com/youtube/iframe_api_reference#Adding_event_listener).\nIn Objective-C,this is done with a\n[delegate](https://developer.apple.com/library/ios/documentation/general/conceptual/CocoaEncyclopedia/DelegatesandDataSources/DelegatesandDataSources.html).\n\n\nThe following code shows how to update the interface declaration in\n`ViewController.h` so the class conforms to the delegate protocol. Change\n`ViewController.h`'s interface declaration as follows: \n\n```objective-c\n@interface ViewController : UIViewController\u003cYTPlayerViewDelegate\u003e\n```\n\n`YTPlayerViewDelegate` is a protocol for handling playback events in the player.\nTo update `ViewController.m` to handle some of the events, you first need to set\nthe `ViewController` instance as the delegate of the `YTPlayerView`\ninstance. To make this change, add the following line to the `viewDidLoad` method\nin `ViewController.h`. \n\n```objective-c\nself.playerView.delegate = self;\n```\n\nNow add the following method to `ViewController.m`: \n\n```objective-c\n- (void)playerView:(YTPlayerView *)playerView didChangeToState:(YTPlayerState)state {\n switch (state) {\n case kYTPlayerStatePlaying:\n NSLog(@\"Started playback\");\n break;\n case kYTPlayerStatePaused:\n NSLog(@\"Paused playback\");\n break;\n default:\n break;\n }\n}\n```\n\nBuild and run the application. Watch the log output in Xcode as the player state changes.\nYou should see updates when the video is played or stopped.\n\nThe library provides the constants that begin with the `kYT*` prefix for\nconvenience and readability. For a full list of these constants, look at\n`YTPlayerView.m`.\n\nBest practices and limitations\n------------------------------\n\nThe library builds on top of the IFrame Player API by creating a `WebView` and\nrendering the HTML and JavaScript required for a basic player. The library's goal is to be\nas easy-to-use as possible, bundling methods that developers frequently have to write into a\npackage. There are a few limitations that should be noted:\n\n- The library does not support concurrent video playback in multiple `YTPlayerView` instances. If your application has multiple `YTPlayerView` instances, a recommended best practice is to pause or stop playback in any existing instances before starting playback in a different instance. In the example application that ships with the project, the ViewControllers make use of `NSNotificationCenter` to dispatch notifications that playback is about to begin. Other ViewControllers are notified and will pause playback in their `YTPlayerView` instances.\n- Reuse your existing, loaded `YTPlayerView` instances when possible. When a video needs to be changed in a View, don't create a new `UIView` instance or a new `YTPlayerView` instance, and don't call either `loadVideoId:` or `loadPlaylistId:`. Instead, use the `cueVideoById:startSeconds:` family of functions, which do not reload the `WebView`. There is a noticeable delay when loading the entire IFrame player.\n- This player cannot play private videos, but it can play [unlisted videos](https://support.google.com/youtube/answer/157177). Since this library wraps the existing iframe player, the player's behavior should be nearly identical to that of a player embedded on a webpage in a mobile browser.\n\nContributions\n-------------\n\nSince this is an open-source project, please submit fixes and improvements to the\n[master branch of the GitHub\nproject](https://github.com/youtube/youtube-ios-player-helper)."]]