YTPlayerView.h 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696
  1. // Copyright 2014 Google Inc. All rights reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #import <UIKit/UIKit.h>
  15. @class YTPlayerView;
  16. /** These enums represent the state of the current video in the player. */
  17. typedef NS_ENUM(NSInteger, YTPlayerState) {
  18. kYTPlayerStateUnstarted,
  19. kYTPlayerStateEnded,
  20. kYTPlayerStatePlaying,
  21. kYTPlayerStatePaused,
  22. kYTPlayerStateBuffering,
  23. kYTPlayerStateQueued,
  24. kYTPlayerStateUnknown
  25. };
  26. /** These enums represent the resolution of the currently loaded video. */
  27. typedef NS_ENUM(NSInteger, YTPlaybackQuality) {
  28. kYTPlaybackQualitySmall,
  29. kYTPlaybackQualityMedium,
  30. kYTPlaybackQualityLarge,
  31. kYTPlaybackQualityHD720,
  32. kYTPlaybackQualityHD1080,
  33. kYTPlaybackQualityHighRes,
  34. kYTPlaybackQualityAuto, /** Addition for YouTube Live Events. */
  35. kYTPlaybackQualityDefault,
  36. kYTPlaybackQualityUnknown /** This should never be returned. It is here for future proofing. */
  37. };
  38. /** These enums represent error codes thrown by the player. */
  39. typedef NS_ENUM(NSInteger, YTPlayerError) {
  40. kYTPlayerErrorInvalidParam,
  41. kYTPlayerErrorHTML5Error,
  42. kYTPlayerErrorVideoNotFound, // Functionally equivalent error codes 100 and
  43. // 105 have been collapsed into |kYTPlayerErrorVideoNotFound|.
  44. kYTPlayerErrorNotEmbeddable, // Functionally equivalent error codes 101 and
  45. // 150 have been collapsed into |kYTPlayerErrorNotEmbeddable|.
  46. kYTPlayerErrorUnknown
  47. };
  48. /**
  49. * A delegate for ViewControllers to respond to YouTube player events outside
  50. * of the view, such as changes to video playback state or playback errors.
  51. * The callback functions correlate to the events fired by the IFrame API.
  52. * For the full documentation, see the IFrame documentation here:
  53. * https://developers.google.com/youtube/iframe_api_reference#Events
  54. */
  55. @protocol YTPlayerViewDelegate<NSObject>
  56. @optional
  57. /**
  58. * Invoked when the player view is ready to receive API calls.
  59. *
  60. * @param playerView The YTPlayerView instance that has become ready.
  61. */
  62. - (void)playerViewDidBecomeReady:(nonnull YTPlayerView *)playerView;
  63. /**
  64. * Callback invoked when player state has changed, e.g. stopped or started playback.
  65. *
  66. * @param playerView The YTPlayerView instance where playback state has changed.
  67. * @param state YTPlayerState designating the new playback state.
  68. */
  69. - (void)playerView:(nonnull YTPlayerView *)playerView didChangeToState:(YTPlayerState)state;
  70. /**
  71. * Callback invoked when playback quality has changed.
  72. *
  73. * @param playerView The YTPlayerView instance where playback quality has changed.
  74. * @param quality YTPlaybackQuality designating the new playback quality.
  75. */
  76. - (void)playerView:(nonnull YTPlayerView *)playerView didChangeToQuality:(YTPlaybackQuality)quality;
  77. /**
  78. * Callback invoked when an error has occured.
  79. *
  80. * @param playerView The YTPlayerView instance where the error has occurred.
  81. * @param error YTPlayerError containing the error state.
  82. */
  83. - (void)playerView:(nonnull YTPlayerView *)playerView receivedError:(YTPlayerError)error;
  84. /**
  85. * Callback invoked frequently when playBack is plaing.
  86. *
  87. * @param playerView The YTPlayerView instance where the error has occurred.
  88. * @param playTime float containing curretn playback time.
  89. */
  90. - (void)playerView:(nonnull YTPlayerView *)playerView didPlayTime:(float)playTime;
  91. /**
  92. * Callback invoked when setting up the webview to allow custom colours so it fits in
  93. * with app color schemes. If a transparent view is required specify clearColor and
  94. * the code will handle the opacity etc.
  95. *
  96. * @param playerView The YTPlayerView instance where the error has occurred.
  97. * @return A color object that represents the background color of the webview.
  98. */
  99. - (nonnull UIColor *)playerViewPreferredWebViewBackgroundColor:(nonnull YTPlayerView *)playerView;
  100. /**
  101. * Callback invoked when initially loading the YouTube iframe to the webview to display a custom
  102. * loading view while the player view is not ready. This loading view will be dismissed just before
  103. * -playerViewDidBecomeReady: callback is invoked. The loading view will be automatically resized
  104. * to cover the entire player view.
  105. *
  106. * The default implementation does not display any custom loading views so the player will display
  107. * a blank view with a background color of (-playerViewPreferredWebViewBackgroundColor:).
  108. *
  109. * Note that the custom loading view WILL NOT be displayed after iframe is loaded. It will be
  110. * handled by YouTube iframe API. This callback is just intended to tell users the view is actually
  111. * doing something while iframe is being loaded, which will take some time if users are in poor networks.
  112. *
  113. * @param playerView The YTPlayerView instance where the error has occurred.
  114. * @return A view object that will be displayed while YouTube iframe API is being loaded.
  115. * Pass nil to display no custom loading view. Default implementation returns nil.
  116. */
  117. - (nullable UIView *)playerViewPreferredInitialLoadingView:(nonnull YTPlayerView *)playerView;
  118. @end
  119. /**
  120. * YTPlayerView is a custom UIView that client developers will use to include YouTube
  121. * videos in their iOS applications. It can be instantiated programmatically, or via
  122. * Interface Builder. Use the methods YTPlayerView::loadWithVideoId:,
  123. * YTPlayerView::loadWithPlaylistId: or their variants to set the video or playlist
  124. * to populate the view with.
  125. */
  126. @interface YTPlayerView : UIView<UIWebViewDelegate>
  127. @property(nonatomic, strong, nullable, readonly) UIWebView *webView;
  128. /** A delegate to be notified on playback events. */
  129. @property(nonatomic, weak, nullable) id<YTPlayerViewDelegate> delegate;
  130. /**
  131. * This method loads the player with the given video ID.
  132. * This is a convenience method for calling YTPlayerView::loadPlayerWithVideoId:withPlayerVars:
  133. * without player variables.
  134. *
  135. * This method reloads the entire contents of the UIWebView and regenerates its HTML contents.
  136. * To change the currently loaded video without reloading the entire UIWebView, use the
  137. * YTPlayerView::cueVideoById:startSeconds:suggestedQuality: family of methods.
  138. *
  139. * @param videoId The YouTube video ID of the video to load in the player view.
  140. * @return YES if player has been configured correctly, NO otherwise.
  141. */
  142. - (BOOL)loadWithVideoId:(nonnull NSString *)videoId;
  143. /**
  144. * This method loads the player with the given playlist ID.
  145. * This is a convenience method for calling YTPlayerView::loadWithPlaylistId:withPlayerVars:
  146. * without player variables.
  147. *
  148. * This method reloads the entire contents of the UIWebView and regenerates its HTML contents.
  149. * To change the currently loaded video without reloading the entire UIWebView, use the
  150. * YTPlayerView::cuePlaylistByPlaylistId:index:startSeconds:suggestedQuality:
  151. * family of methods.
  152. *
  153. * @param playlistId The YouTube playlist ID of the playlist to load in the player view.
  154. * @return YES if player has been configured correctly, NO otherwise.
  155. */
  156. - (BOOL)loadWithPlaylistId:(nonnull NSString *)playlistId;
  157. /**
  158. * This method loads the player with the given video ID and player variables. Player variables
  159. * specify optional parameters for video playback. For instance, to play a YouTube
  160. * video inline, the following playerVars dictionary would be used:
  161. *
  162. * @code
  163. * @{ @"playsinline" : @1 };
  164. * @endcode
  165. *
  166. * Note that when the documentation specifies a valid value as a number (typically 0, 1 or 2),
  167. * both strings and integers are valid values. The full list of parameters is defined at:
  168. * https://developers.google.com/youtube/player_parameters?playerVersion=HTML5.
  169. *
  170. * This method reloads the entire contents of the UIWebView and regenerates its HTML contents.
  171. * To change the currently loaded video without reloading the entire UIWebView, use the
  172. * YTPlayerView::cueVideoById:startSeconds:suggestedQuality: family of methods.
  173. *
  174. * @param videoId The YouTube video ID of the video to load in the player view.
  175. * @param playerVars An NSDictionary of player parameters.
  176. * @return YES if player has been configured correctly, NO otherwise.
  177. */
  178. - (BOOL)loadWithVideoId:(nonnull NSString *)videoId playerVars:(nullable NSDictionary *)playerVars;
  179. /**
  180. * This method loads the player with the given playlist ID and player variables. Player variables
  181. * specify optional parameters for video playback. For instance, to play a YouTube
  182. * video inline, the following playerVars dictionary would be used:
  183. *
  184. * @code
  185. * @{ @"playsinline" : @1 };
  186. * @endcode
  187. *
  188. * Note that when the documentation specifies a valid value as a number (typically 0, 1 or 2),
  189. * both strings and integers are valid values. The full list of parameters is defined at:
  190. * https://developers.google.com/youtube/player_parameters?playerVersion=HTML5.
  191. *
  192. * This method reloads the entire contents of the UIWebView and regenerates its HTML contents.
  193. * To change the currently loaded video without reloading the entire UIWebView, use the
  194. * YTPlayerView::cuePlaylistByPlaylistId:index:startSeconds:suggestedQuality:
  195. * family of methods.
  196. *
  197. * @param playlistId The YouTube playlist ID of the playlist to load in the player view.
  198. * @param playerVars An NSDictionary of player parameters.
  199. * @return YES if player has been configured correctly, NO otherwise.
  200. */
  201. - (BOOL)loadWithPlaylistId:(nonnull NSString *)playlistId playerVars:(nullable NSDictionary *)playerVars;
  202. /**
  203. * This method loads an iframe player with the given player parameters. Usually you may want to use
  204. * -loadWithVideoId:playerVars: or -loadWithPlaylistId:playerVars: instead of this method does not handle
  205. * video_id or playlist_id at all. The full list of parameters is defined at:
  206. * https://developers.google.com/youtube/player_parameters?playerVersion=HTML5.
  207. *
  208. * @param additionalPlayerParams An NSDictionary of parameters in addition to required parameters
  209. * to instantiate the HTML5 player with. This differs depending on
  210. * whether a single video or playlist is being loaded.
  211. * @return YES if successful, NO if not.
  212. */
  213. - (BOOL)loadWithPlayerParams:(nullable NSDictionary *)additionalPlayerParams;
  214. #pragma mark - Player controls
  215. // These methods correspond to their JavaScript equivalents as documented here:
  216. // https://developers.google.com/youtube/iframe_api_reference#Playback_controls
  217. /**
  218. * Starts or resumes playback on the loaded video. Corresponds to this method from
  219. * the JavaScript API:
  220. * https://developers.google.com/youtube/iframe_api_reference#playVideo
  221. */
  222. - (void)playVideo;
  223. /**
  224. * Pauses playback on a playing video. Corresponds to this method from
  225. * the JavaScript API:
  226. * https://developers.google.com/youtube/iframe_api_reference#pauseVideo
  227. */
  228. - (void)pauseVideo;
  229. /**
  230. * Stops playback on a playing video. Corresponds to this method from
  231. * the JavaScript API:
  232. * https://developers.google.com/youtube/iframe_api_reference#stopVideo
  233. */
  234. - (void)stopVideo;
  235. /**
  236. * Seek to a given time on a playing video. Corresponds to this method from
  237. * the JavaScript API:
  238. * https://developers.google.com/youtube/iframe_api_reference#seekTo
  239. *
  240. * @param seekToSeconds The time in seconds to seek to in the loaded video.
  241. * @param allowSeekAhead Whether to make a new request to the server if the time is
  242. * outside what is currently buffered. Recommended to set to YES.
  243. */
  244. - (void)seekToSeconds:(float)seekToSeconds allowSeekAhead:(BOOL)allowSeekAhead;
  245. #pragma mark - Queuing videos
  246. // Queueing functions for videos. These methods correspond to their JavaScript
  247. // equivalents as documented here:
  248. // https://developers.google.com/youtube/iframe_api_reference#Queueing_Functions
  249. /**
  250. * Cues a given video by its video ID for playback starting at the given time and with the
  251. * suggested quality. Cueing loads a video, but does not start video playback. This method
  252. * corresponds with its JavaScript API equivalent as documented here:
  253. * https://developers.google.com/youtube/iframe_api_reference#cueVideoById
  254. *
  255. * @param videoId A video ID to cue.
  256. * @param startSeconds Time in seconds to start the video when YTPlayerView::playVideo is called.
  257. * @param suggestedQuality YTPlaybackQuality value suggesting a playback quality.
  258. */
  259. - (void)cueVideoById:(nonnull NSString *)videoId
  260. startSeconds:(float)startSeconds
  261. suggestedQuality:(YTPlaybackQuality)suggestedQuality;
  262. /**
  263. * Cues a given video by its video ID for playback starting and ending at the given times
  264. * with the suggested quality. Cueing loads a video, but does not start video playback. This
  265. * method corresponds with its JavaScript API equivalent as documented here:
  266. * https://developers.google.com/youtube/iframe_api_reference#cueVideoById
  267. *
  268. * @param videoId A video ID to cue.
  269. * @param startSeconds Time in seconds to start the video when playVideo() is called.
  270. * @param endSeconds Time in seconds to end the video after it begins playing.
  271. * @param suggestedQuality YTPlaybackQuality value suggesting a playback quality.
  272. */
  273. - (void)cueVideoById:(nonnull NSString *)videoId
  274. startSeconds:(float)startSeconds
  275. endSeconds:(float)endSeconds
  276. suggestedQuality:(YTPlaybackQuality)suggestedQuality;
  277. /**
  278. * Loads a given video by its video ID for playback starting at the given time and with the
  279. * suggested quality. Loading a video both loads it and begins playback. This method
  280. * corresponds with its JavaScript API equivalent as documented here:
  281. * https://developers.google.com/youtube/iframe_api_reference#loadVideoById
  282. *
  283. * @param videoId A video ID to load and begin playing.
  284. * @param startSeconds Time in seconds to start the video when it has loaded.
  285. * @param suggestedQuality YTPlaybackQuality value suggesting a playback quality.
  286. */
  287. - (void)loadVideoById:(nonnull NSString *)videoId
  288. startSeconds:(float)startSeconds
  289. suggestedQuality:(YTPlaybackQuality)suggestedQuality;
  290. /**
  291. * Loads a given video by its video ID for playback starting and ending at the given times
  292. * with the suggested quality. Loading a video both loads it and begins playback. This method
  293. * corresponds with its JavaScript API equivalent as documented here:
  294. * https://developers.google.com/youtube/iframe_api_reference#loadVideoById
  295. *
  296. * @param videoId A video ID to load and begin playing.
  297. * @param startSeconds Time in seconds to start the video when it has loaded.
  298. * @param endSeconds Time in seconds to end the video after it begins playing.
  299. * @param suggestedQuality YTPlaybackQuality value suggesting a playback quality.
  300. */
  301. - (void)loadVideoById:(nonnull NSString *)videoId
  302. startSeconds:(float)startSeconds
  303. endSeconds:(float)endSeconds
  304. suggestedQuality:(YTPlaybackQuality)suggestedQuality;
  305. /**
  306. * Cues a given video by its URL on YouTube.com for playback starting at the given time
  307. * and with the suggested quality. Cueing loads a video, but does not start video playback.
  308. * This method corresponds with its JavaScript API equivalent as documented here:
  309. * https://developers.google.com/youtube/iframe_api_reference#cueVideoByUrl
  310. *
  311. * @param videoURL URL of a YouTube video to cue for playback.
  312. * @param startSeconds Time in seconds to start the video when YTPlayerView::playVideo is called.
  313. * @param suggestedQuality YTPlaybackQuality value suggesting a playback quality.
  314. */
  315. - (void)cueVideoByURL:(nonnull NSString *)videoURL
  316. startSeconds:(float)startSeconds
  317. suggestedQuality:(YTPlaybackQuality)suggestedQuality;
  318. /**
  319. * Cues a given video by its URL on YouTube.com for playback starting at the given time
  320. * and with the suggested quality. Cueing loads a video, but does not start video playback.
  321. * This method corresponds with its JavaScript API equivalent as documented here:
  322. * https://developers.google.com/youtube/iframe_api_reference#cueVideoByUrl
  323. *
  324. * @param videoURL URL of a YouTube video to cue for playback.
  325. * @param startSeconds Time in seconds to start the video when YTPlayerView::playVideo is called.
  326. * @param endSeconds Time in seconds to end the video after it begins playing.
  327. * @param suggestedQuality YTPlaybackQuality value suggesting a playback quality.
  328. */
  329. - (void)cueVideoByURL:(nonnull NSString *)videoURL
  330. startSeconds:(float)startSeconds
  331. endSeconds:(float)endSeconds
  332. suggestedQuality:(YTPlaybackQuality)suggestedQuality;
  333. /**
  334. * Loads a given video by its video ID for playback starting at the given time
  335. * with the suggested quality. Loading a video both loads it and begins playback. This method
  336. * corresponds with its JavaScript API equivalent as documented here:
  337. * https://developers.google.com/youtube/iframe_api_reference#loadVideoByUrl
  338. *
  339. * @param videoURL URL of a YouTube video to load and play.
  340. * @param startSeconds Time in seconds to start the video when it has loaded.
  341. * @param suggestedQuality YTPlaybackQuality value suggesting a playback quality.
  342. */
  343. - (void)loadVideoByURL:(nonnull NSString *)videoURL
  344. startSeconds:(float)startSeconds
  345. suggestedQuality:(YTPlaybackQuality)suggestedQuality;
  346. /**
  347. * Loads a given video by its video ID for playback starting and ending at the given times
  348. * with the suggested quality. Loading a video both loads it and begins playback. This method
  349. * corresponds with its JavaScript API equivalent as documented here:
  350. * https://developers.google.com/youtube/iframe_api_reference#loadVideoByUrl
  351. *
  352. * @param videoURL URL of a YouTube video to load and play.
  353. * @param startSeconds Time in seconds to start the video when it has loaded.
  354. * @param endSeconds Time in seconds to end the video after it begins playing.
  355. * @param suggestedQuality YTPlaybackQuality value suggesting a playback quality.
  356. */
  357. - (void)loadVideoByURL:(nonnull NSString *)videoURL
  358. startSeconds:(float)startSeconds
  359. endSeconds:(float)endSeconds
  360. suggestedQuality:(YTPlaybackQuality)suggestedQuality;
  361. #pragma mark - Queuing functions for playlists
  362. // Queueing functions for playlists. These methods correspond to
  363. // the JavaScript methods defined here:
  364. // https://developers.google.com/youtube/js_api_reference#Playlist_Queueing_Functions
  365. /**
  366. * Cues a given playlist with the given ID. The |index| parameter specifies the 0-indexed
  367. * position of the first video to play, starting at the given time and with the
  368. * suggested quality. Cueing loads a playlist, but does not start video playback. This method
  369. * corresponds with its JavaScript API equivalent as documented here:
  370. * https://developers.google.com/youtube/iframe_api_reference#cuePlaylist
  371. *
  372. * @param playlistId Playlist ID of a YouTube playlist to cue.
  373. * @param index A 0-indexed position specifying the first video to play.
  374. * @param startSeconds Time in seconds to start the video when YTPlayerView::playVideo is called.
  375. * @param suggestedQuality YTPlaybackQuality value suggesting a playback quality.
  376. */
  377. - (void)cuePlaylistByPlaylistId:(nonnull NSString *)playlistId
  378. index:(int)index
  379. startSeconds:(float)startSeconds
  380. suggestedQuality:(YTPlaybackQuality)suggestedQuality;
  381. /**
  382. * Cues a playlist of videos with the given video IDs. The |index| parameter specifies the
  383. * 0-indexed position of the first video to play, starting at the given time and with the
  384. * suggested quality. Cueing loads a playlist, but does not start video playback. This method
  385. * corresponds with its JavaScript API equivalent as documented here:
  386. * https://developers.google.com/youtube/iframe_api_reference#cuePlaylist
  387. *
  388. * @param videoIds An NSArray of video IDs to compose the playlist of.
  389. * @param index A 0-indexed position specifying the first video to play.
  390. * @param startSeconds Time in seconds to start the video when YTPlayerView::playVideo is called.
  391. * @param suggestedQuality YTPlaybackQuality value suggesting a playback quality.
  392. */
  393. - (void)cuePlaylistByVideos:(nonnull NSArray *)videoIds
  394. index:(int)index
  395. startSeconds:(float)startSeconds
  396. suggestedQuality:(YTPlaybackQuality)suggestedQuality;
  397. /**
  398. * Loads a given playlist with the given ID. The |index| parameter specifies the 0-indexed
  399. * position of the first video to play, starting at the given time and with the
  400. * suggested quality. Loading a playlist starts video playback. This method
  401. * corresponds with its JavaScript API equivalent as documented here:
  402. * https://developers.google.com/youtube/iframe_api_reference#loadPlaylist
  403. *
  404. * @param playlistId Playlist ID of a YouTube playlist to cue.
  405. * @param index A 0-indexed position specifying the first video to play.
  406. * @param startSeconds Time in seconds to start the video when YTPlayerView::playVideo is called.
  407. * @param suggestedQuality YTPlaybackQuality value suggesting a playback quality.
  408. */
  409. - (void)loadPlaylistByPlaylistId:(nonnull NSString *)playlistId
  410. index:(int)index
  411. startSeconds:(float)startSeconds
  412. suggestedQuality:(YTPlaybackQuality)suggestedQuality;
  413. /**
  414. * Loads a playlist of videos with the given video IDs. The |index| parameter specifies the
  415. * 0-indexed position of the first video to play, starting at the given time and with the
  416. * suggested quality. Loading a playlist starts video playback. This method
  417. * corresponds with its JavaScript API equivalent as documented here:
  418. * https://developers.google.com/youtube/iframe_api_reference#loadPlaylist
  419. *
  420. * @param videoIds An NSArray of video IDs to compose the playlist of.
  421. * @param index A 0-indexed position specifying the first video to play.
  422. * @param startSeconds Time in seconds to start the video when YTPlayerView::playVideo is called.
  423. * @param suggestedQuality YTPlaybackQuality value suggesting a playback quality.
  424. */
  425. - (void)loadPlaylistByVideos:(nonnull NSArray *)videoIds
  426. index:(int)index
  427. startSeconds:(float)startSeconds
  428. suggestedQuality:(YTPlaybackQuality)suggestedQuality;
  429. #pragma mark - Playing a video in a playlist
  430. // These methods correspond to the JavaScript API as defined under the
  431. // "Playing a video in a playlist" section here:
  432. // https://developers.google.com/youtube/iframe_api_reference#Playback_status
  433. /**
  434. * Loads and plays the next video in the playlist. Corresponds to this method from
  435. * the JavaScript API:
  436. * https://developers.google.com/youtube/iframe_api_reference#nextVideo
  437. */
  438. - (void)nextVideo;
  439. /**
  440. * Loads and plays the previous video in the playlist. Corresponds to this method from
  441. * the JavaScript API:
  442. * https://developers.google.com/youtube/iframe_api_reference#previousVideo
  443. */
  444. - (void)previousVideo;
  445. /**
  446. * Loads and plays the video at the given 0-indexed position in the playlist.
  447. * Corresponds to this method from the JavaScript API:
  448. * https://developers.google.com/youtube/iframe_api_reference#playVideoAt
  449. *
  450. * @param index The 0-indexed position of the video in the playlist to load and play.
  451. */
  452. - (void)playVideoAt:(int)index;
  453. #pragma mark - Setting the playback rate
  454. /**
  455. * Gets the playback rate. The default value is 1.0, which represents a video
  456. * playing at normal speed. Other values may include 0.25 or 0.5 for slower
  457. * speeds, and 1.5 or 2.0 for faster speeds. This method corresponds to the
  458. * JavaScript API defined here:
  459. * https://developers.google.com/youtube/iframe_api_reference#getPlaybackRate
  460. *
  461. * @return An integer value between 0 and 100 representing the current volume.
  462. */
  463. - (float)playbackRate;
  464. /**
  465. * Sets the playback rate. The default value is 1.0, which represents a video
  466. * playing at normal speed. Other values may include 0.25 or 0.5 for slower
  467. * speeds, and 1.5 or 2.0 for faster speeds. To fetch a list of valid values for
  468. * this method, call YTPlayerView::getAvailablePlaybackRates. This method does not
  469. * guarantee that the playback rate will change.
  470. * This method corresponds to the JavaScript API defined here:
  471. * https://developers.google.com/youtube/iframe_api_reference#setPlaybackRate
  472. *
  473. * @param suggestedRate A playback rate to suggest for the player.
  474. */
  475. - (void)setPlaybackRate:(float)suggestedRate;
  476. /**
  477. * Gets a list of the valid playback rates, useful in conjunction with
  478. * YTPlayerView::setPlaybackRate. This method corresponds to the
  479. * JavaScript API defined here:
  480. * https://developers.google.com/youtube/iframe_api_reference#getPlaybackRate
  481. *
  482. * @return An NSArray containing available playback rates. nil if there is an error.
  483. */
  484. - (nullable NSArray *)availablePlaybackRates;
  485. #pragma mark - Setting playback behavior for playlists
  486. /**
  487. * Sets whether the player should loop back to the first video in the playlist
  488. * after it has finished playing the last video. This method corresponds to the
  489. * JavaScript API defined here:
  490. * https://developers.google.com/youtube/iframe_api_reference#loopPlaylist
  491. *
  492. * @param loop A boolean representing whether the player should loop.
  493. */
  494. - (void)setLoop:(BOOL)loop;
  495. /**
  496. * Sets whether the player should shuffle through the playlist. This method
  497. * corresponds to the JavaScript API defined here:
  498. * https://developers.google.com/youtube/iframe_api_reference#shufflePlaylist
  499. *
  500. * @param shuffle A boolean representing whether the player should
  501. * shuffle through the playlist.
  502. */
  503. - (void)setShuffle:(BOOL)shuffle;
  504. #pragma mark - Playback status
  505. // These methods correspond to the JavaScript methods defined here:
  506. // https://developers.google.com/youtube/js_api_reference#Playback_status
  507. /**
  508. * Returns a number between 0 and 1 that specifies the percentage of the video
  509. * that the player shows as buffered. This method corresponds to the
  510. * JavaScript API defined here:
  511. * https://developers.google.com/youtube/iframe_api_reference#getVideoLoadedFraction
  512. *
  513. * @return A float value between 0 and 1 representing the percentage of the video
  514. * already loaded.
  515. */
  516. - (float)videoLoadedFraction;
  517. /**
  518. * Returns the state of the player. This method corresponds to the
  519. * JavaScript API defined here:
  520. * https://developers.google.com/youtube/iframe_api_reference#getPlayerState
  521. *
  522. * @return |YTPlayerState| representing the state of the player.
  523. */
  524. - (YTPlayerState)playerState;
  525. /**
  526. * Returns the elapsed time in seconds since the video started playing. This
  527. * method corresponds to the JavaScript API defined here:
  528. * https://developers.google.com/youtube/iframe_api_reference#getCurrentTime
  529. *
  530. * @return Time in seconds since the video started playing.
  531. */
  532. - (float)currentTime;
  533. #pragma mark - Playback quality
  534. // Playback quality. These methods correspond to the JavaScript
  535. // methods defined here:
  536. // https://developers.google.com/youtube/js_api_reference#Playback_quality
  537. /**
  538. * Returns the playback quality. This method corresponds to the
  539. * JavaScript API defined here:
  540. * https://developers.google.com/youtube/iframe_api_reference#getPlaybackQuality
  541. *
  542. * @return YTPlaybackQuality representing the current playback quality.
  543. */
  544. - (YTPlaybackQuality)playbackQuality;
  545. /**
  546. * Suggests playback quality for the video. It is recommended to leave this setting to
  547. * |default|. This method corresponds to the JavaScript API defined here:
  548. * https://developers.google.com/youtube/iframe_api_reference#setPlaybackQuality
  549. *
  550. * @param quality YTPlaybackQuality value to suggest for the player.
  551. */
  552. - (void)setPlaybackQuality:(YTPlaybackQuality)suggestedQuality;
  553. /**
  554. * Gets a list of the valid playback quality values, useful in conjunction with
  555. * YTPlayerView::setPlaybackQuality. This method corresponds to the
  556. * JavaScript API defined here:
  557. * https://developers.google.com/youtube/iframe_api_reference#getAvailableQualityLevels
  558. *
  559. * @return An NSArray containing available playback quality levels. Returns nil if there is an error.
  560. */
  561. - (nullable NSArray *)availableQualityLevels;
  562. #pragma mark - Retrieving video information
  563. // Retrieving video information. These methods correspond to the JavaScript
  564. // methods defined here:
  565. // https://developers.google.com/youtube/js_api_reference#Retrieving_video_information
  566. /**
  567. * Returns the duration in seconds since the video of the video. This
  568. * method corresponds to the JavaScript API defined here:
  569. * https://developers.google.com/youtube/iframe_api_reference#getDuration
  570. *
  571. * @return Length of the video in seconds.
  572. */
  573. - (NSTimeInterval)duration;
  574. /**
  575. * Returns the YouTube.com URL for the video. This method corresponds
  576. * to the JavaScript API defined here:
  577. * https://developers.google.com/youtube/iframe_api_reference#getVideoUrl
  578. *
  579. * @return The YouTube.com URL for the video. Returns nil if no video is loaded yet.
  580. */
  581. - (nullable NSURL *)videoUrl;
  582. /**
  583. * Returns the embed code for the current video. This method corresponds
  584. * to the JavaScript API defined here:
  585. * https://developers.google.com/youtube/iframe_api_reference#getVideoEmbedCode
  586. *
  587. * @return The embed code for the current video. Returns nil if no video is loaded yet.
  588. */
  589. - (nullable NSString *)videoEmbedCode;
  590. #pragma mark - Retrieving playlist information
  591. // Retrieving playlist information. These methods correspond to the
  592. // JavaScript defined here:
  593. // https://developers.google.com/youtube/js_api_reference#Retrieving_playlist_information
  594. /**
  595. * Returns an ordered array of video IDs in the playlist. This method corresponds
  596. * to the JavaScript API defined here:
  597. * https://developers.google.com/youtube/iframe_api_reference#getPlaylist
  598. *
  599. * @return An NSArray containing all the video IDs in the current playlist. |nil| on error.
  600. */
  601. - (nullable NSArray *)playlist;
  602. /**
  603. * Returns the 0-based index of the currently playing item in the playlist.
  604. * This method corresponds to the JavaScript API defined here:
  605. * https://developers.google.com/youtube/iframe_api_reference#getPlaylistIndex
  606. *
  607. * @return The 0-based index of the currently playing item in the playlist.
  608. */
  609. - (int)playlistIndex;
  610. #pragma mark - Exposed for Testing
  611. /**
  612. * Removes the internal web view from this player view.
  613. * Intended to use for testing, should not be used in production code.
  614. */
  615. - (void)removeWebView;
  616. -(NSString*) Embed2VID:(NSString*) iframe_embed;
  617. @end