![post-title](https://i.ytimg.com/vi/_RsaNzZFuUU/hqdefault.jpg)
youtube iframe api 在 コバにゃんチャンネル Youtube 的最讚貼文
![post-title](https://i.ytimg.com/vi/_RsaNzZFuUU/hqdefault.jpg)
Severity: Notice
Message: Trying to get property 'plaintext' of non-object
Filename: models/Crawler_model.php
Line Number: 228
Backtrace:
File: /var/www/html/KOL/voice/application/models/Crawler_model.php
Line: 228
Function: _error_handler
File: /var/www/html/KOL/voice/application/controllers/Pages.php
Line: 336
Function: get_dev_google_article
File: /var/www/html/KOL/voice/public/index.php
Line: 319
Function: require_once
Severity: Notice
Message: Trying to get property 'plaintext' of non-object
Filename: models/Crawler_model.php
Line Number: 229
Backtrace:
File: /var/www/html/KOL/voice/application/models/Crawler_model.php
Line: 229
Function: _error_handler
File: /var/www/html/KOL/voice/application/controllers/Pages.php
Line: 336
Function: get_dev_google_article
File: /var/www/html/KOL/voice/public/index.php
Line: 319
Function: require_once
Search
本篇要筆記的就是Youtube iframe API 的一些常用功能,比方嵌入、自動播放、監聽影片狀態、做一個自己的控制器等。 再配合之前寫過的二篇,就可以滿足上面 ... ... <看更多>
Youtube Iframe API Demo ; Demo1_1:一般使用影片的id寫在js裡 · <div id="player"></div>. </div> ; Demo1_2:一般使用影片的id寫在html裡 · <!-- enablejsapi:必為1-->. <! ... <看更多>
#1. YouTube Player API Reference for iframe Embeds
The IFrame player API lets you embed a YouTube video player on your website and control the player using JavaScript. Using the API's JavaScript functions, ...
#2. Youtube Iframe API 常用功能- Google - Let's Write
本篇要筆記的就是Youtube iframe API 的一些常用功能,比方嵌入、自動播放、監聽影片狀態、做一個自己的控制器等。 再配合之前寫過的二篇,就可以滿足上面 ...
#3. YouTube Iframe API: 打造全面的YT控制器component - iT 邦幫忙
今天要來打造影片標記系統的精隨之一,用YouTube Iframe API來建立一個播放器。或許有人會有疑問,為甚麼不用Iframe就好了呢? 因為為了能夠隨時抓取YouTube影片的撥放 ...
#4. 讓Yotube在嵌入網站時,有更多參數可設定(靜音、自動播放 ...
透過官方YouTube IFrame Player API ,讓Yotube在嵌入網站時,有更多參數可設定(靜音、自動播放、重覆播放) · Step1 首先,先將YouTube iFrame API引用到 ...
#5. Youtube Iframe API 常用功能- August - Let's Write
Youtube Iframe API Demo ; Demo1_1:一般使用影片的id寫在js裡 · <div id="player"></div>. </div> ; Demo1_2:一般使用影片的id寫在html裡 · <!-- enablejsapi:必為1-->. <!
#6. Youtube iframe API - HackMD
一、使用方式:. 1. 插入API. <script src="https://www.youtube.com/iframe_api"></script> · 二、單頁多個嵌入影片控制方式. 目前測試可行的方案為: 有一組youtube_id就 ...
#7. [YouTube API] 控制影片撥放. iframe embeds - Medium
網站嵌入的Youtube影片時,為了因應設計畫面,需要客製化按鈕或影片外觀, 或是需要偵測使用者觀看影片的行為等,就會需要使用Youtube Player API來自行控制撥放器。
#8. Javascript IFrame YouTube API Example to Embed Video ...
Buy the full source code of application here: https://freemediatools.com/iframeyoutube Visit my Online Free Media Tool Website ...
#9. jQuery簡單的應用YouTube IFrame Player API - UCAMC
YouTube 其實有提供一個很好用的工具,叫做IFrame Player API,可以利用這東西來做一些簡單的觸發或是監聽。 首先,我們必須創建具有特定ID 的 <div> (此 ...
#10. gajus/youtube-player: YouTube iframe API abstraction. - GitHub
YouTube iframe API abstraction. Contribute to gajus/youtube-player development by creating an account on GitHub.
#11. 「简单实战」YouTube Iframe API 的使用-腾讯云开发者社区
业务需求需要在自己的网页上嵌入油管( youtube )上的视频,所以去踩了油管IFrame Player API 的坑。其实和大多数国内视频网站的ifram Embed 方式是相似, ...
#12. using YouTube iFrame API within jQuery event - Stack Overflow
And most important, the function onYouTubeIframeAPIReady must be global (on window scope) to be detected by the youtube iFrame API (actually ...
#13. 「简单实战」YouTube IFrame Player API 的使用 - 稀土掘金
业务需求需要在自己的网页上嵌入油管( youtube )上的视频,所以去踩了油管IFrame Player API 的坑。其实和大多数国内视频网站的ifram Embed 方式是 ...
#14. JS / 使用Youtube Iframe API製作動態歌詞 - 莊生趣味
1.透過Youtube Iframe API 建立播放器與取得影片資訊 · 2.結合Jquery函示庫$.doTimeout 設定每100毫秒觸發一個擷取當前影片的播放時間秒數 ...
#15. YouTube IFrame Player API 的使用_巴啦啦小能量的博客
// 3. This function creates an <iframe> (and YouTube player). // after the API code downloads. var ...
#16. Youtube IFrame API Unable to post message Issue - 小惡魔
YouTube IFrame Player API 提供了簡單的介面及方法,讓網站可以快速整合Youtube 影片,但是不得不說Google 針對Youtube API 時常改版,所以就會常常 ...
#17. YouTube iframe API example - CodePen
Little experimentation with the JavaScript iframe API of YouTube. CodePen version of this example: http://www.opimedia.be/DS/webdev/YouTube/...
#18. 「简单实战」YouTube IFrame Player API 的使用- 前端曰
业务需求需要在自己的网页上嵌入油管( youtube )上的视频,所以去踩了油管IFrame Player API 的坑。其实和大多数国内视频网站的ifram Embed 方式是 ...
#19. How to Use the YouTube IFrame API in React - freeCodeCamp
Up to this point, we were embedding the YouTube player and not interacting with the API. This was going to be fun. Exploring the documentation.
#20. 「簡單實戰」YouTube IFrame Player API 的使用 - 台部落
前言業務需求需要在自己的網頁上嵌入油管( youtube )上的視頻,所以去踩了油管IFrame Player API 的坑。其實和大多數國內視頻網站的ifram Embed ...
#21. Youtube IFrame API: Controlling videos using JavaScript
The Youtube IFrame API allows you to embed a YouTube video player (using an IFrame to contain the video) on your website and control the ...
#22. YouTube IFrame Player API? How to? - TMS Support Center
Good day, How can I get the following code to work? It is sample code from the Youtube IFrame Player API documentation (Getting started).
#23. Youtube iFrame API: fire an event every 5 minutes - SitePoint
Hi all Im currently working with the youtube iframe API with jquery. Its important that the user can pick up where they last left off.
#24. YouTube player api deprecated - Google Help
Android YouTube player api will be fully deprecated on May, 1. What will happen if my app which is live on play store still using this api?
#25. Build a music player with YouTube IFrame Player API
I added a musicplayer based on YouTube IFrame Player API for my personal site music page to play my... Tagged with typescript, react, ...
#26. Youtube 互動- Webduino 實戰智慧插座教學
要使用Youtube 玩開關燈的話,首先要了解相關的控制方式,這時候一定要來官方網站看看,因為我們要在網頁裡面使用,就點選IFrame Player API 閱讀。
#27. YouTube | How to configure iFrame parameters
Check the blog YouTube API for more information about the color choices. Note: Setting the color parameter disables white modestbranding option.
#28. 透過YouTube IFrame Player API客製化影片播放介面的按鈕及 ...
透過YouTube IFrame Player API能夠客製化影片播放介面的按鈕及外觀或是可用於需要偵測使用者操作動作時。 官方reference. 於 下午3:59 ...
#29. Working with the YouTube Player API for iframe Embeds
We like the YouTube IFrame Player API for simplifying the process of embedding videos in web applications. There are various types of events ...
#30. youtube iframe api教學,大家都在找解答 旅遊日本住宿評價
youtube iframe api 教學,大家都在找解答第1頁。 本篇大綱:影片愈來愈重要的這時代,前端會遇到嵌Youtube的相關需求。基本使用:嵌入影片+自動播放。1 html中放 ...
#31. Integrate Youtube Iframe API in Angular & React - Time to Hack
Youtube iframe API is tricky to integrate when it is to be done with Component-based architecture. Here is the easiest way to integrate Youtube ...
#32. YouTube iframe API example
Embed code: <iframe width="400" height="300" src="https://www.youtube.com/embed/yG0oBPtyNb0" title="Mungo Jerry - In the summertime" frameborder="0" ...
#33. Medición de vídeos: YouTube iframe API | Blog - Merkle.com
La API de YouTube para iframe nos permite insertar y controlar un reproductor de vídeo de YouTube. Su finalidad más clara es funcional.
#34. Youtube IFrame Player API | PPT
Youtube IFrame Player API - Download as a PDF or view online for free.
#35. Making Youtube iframe API videos work in carousel / tab
Making Youtube iframe API videos work in carousel / tab ... Monday, February 18th, 2019. Well, I just spent decent amount of time trying to make ...
#36. Youtube Player iFrame API - JSFiddle - Code Playground
This function creates an <iframe> (and YouTube player). 9. // after the API code downloads. 10. var player;. 11. function onYouTubeIframeAPIReady() {.
#37. A Youtube Iframe API wrapper written in vue3
Supports Vue 3 · Uses the composition API · No dependencies other than Vue 3 · Supports all the methods and events provided by the YouTube iFrame ...
#38. YouTube iframe API loader - Custom Tag Template
The is an unofficial template for the YouTube Iframe API. A tag created with this template loads the YouTube Iframe API on the page.
#39. Solved: YouTube iFrame API - Marketing Nation
Hi there - I'm trying to use the YouTube iFrame API and I'm not having any luck. I've tried it on a Marketo page and on a JSFiddle and ...
#40. How to integrate Youtube Iframe API with WordPress ...
In this tutorial, I will show you how to integrate the Youtube Iframe API with the WordPress Shortcode API to create a shortcode which is ...
#41. Integrate YouTube's IFrame Player API in Angular
When it comes to integrating the YouTube IFrame Player API with component-based frameworks like Angular, it's a bit difficult and tricky.
#42. Controlling a Youtube video via URL parameters and the ...
Youtube Player API methods · player.playVideo() : Plays the video · player.pauseVideo() : Pauses the video · player.stopVideo() : Stops the video · player.nextVideo ...
#43. Implementing Custom Play/Pause Button for Embedded ...
Steps to Use YouTube IFrame Player API ; var tag = document.createElement('script'); ; tag.src = "https://www.youtube.com/iframe_api"; ; var ...
#44. The Ultimate YouTube Video Embed Setup - getButterfly
I've also written about using the YouTube API to embed a video Iframe. This time I needed a regular embed to integrate as seamlessly as ...
#45. Trigger Specific Actions on YouTube Video Player Events
unlike the Flash and JavaScript player APIs, which both involve embedding a Flash object on your web page, the IFrame API posts content to an < ...
#46. Https does not work with Youtube iframe API as an src - Drupal
After playing with the Youtube iframe API some and not having success, I found that under otherwise identical circumstances, an iframe src ...
#47. YouTube iFrame Player and API - New Plugin from Zeroqode
With YouTube iFrame Player and API you can: :desktop_computer: Embed a YouTube video player on your website and :toolbox: Control the player ...
#48. YouTube iframe API how do I control an iframe player that s ...
I want to have control over YouTube players that use iframes. I want to control these players using the ... I can use the API operations on ...
#49. How to Control YouTube's Video Player with JavaScript
Did you know that YouTube has a powerful JavaScript API for controlling its embedded videos? Learn how to use it by reading this short ...
#50. youtube iframe api - CodeSandbox
Explore this online youtube iframe api sandbox and experiment with it yourself using our interactive online playground. You can use it as a template to ...
#51. youtube_player_iframe | Flutter Package - Pub.dev
Flutter plugin for playing or streaming YouTube videos inline using the official iFrame Player API. The package exposes almost all the API provided by ...
#52. 「简单实战」YouTube IFrame Player API 的使用_安科网 - Ancii
业务需求需要在自己的网页上嵌入油管上的视频,所以去踩了油管IFrame Player API 的坑。其实和大多数国内视频网站的ifram Embed 方式是相似, ...
#53. Youtube Iframe Api play one video at a time
What could be the reason and i am using shortcode and below is my code in functions.php file. I have two iframe youtube videos in my page html.
#54. angular + youtube iframe api + images - Plunker
... rel="stylesheet" href="style.css" /> <script src="script.js"></script> </head> <body ng-app="desktopApp"> <h1>Angular + Youtube Iframe API + Images!
#55. Websites using YouTube IFrame API
Website Location Sales Revenue Tech Spend Social Employees indystar.com United States $2000+ 150,000+ fightoftheyear.sho.com United States $324k+ $5000+ 400,000+ 100+ vivint.com United States $232k+ $10000+ 10,000+ 10,000+
#56. YouTube IFrame Player API doesn't work in IE in a local ...
8 Go for Vimeo! Summary. As of Dec 1, 2017, SuperMemo 17 for Windows, version 17.3, uses the new YouTube API ...
#57. Embed a YouTube Player into a React App - Cloudinary
react-youtube provides a React component that acts as an abstraction layer over the traditional YouTube IFrame Player API. Let's get started!
#58. HTML YouTube Videos - W3Schools
To play your video on a web page, do the following: Upload the video to YouTube; Take a note of the video id; Define an <iframe> element in your web page; Let ...
#59. Best practices for using third-party embeds - web.dev
YouTube videos: To lazy-load a YouTube video player iframe, ... in the code for the iframe embed generated by the Google Maps Embed API.
#60. YouTube iframe integration problems - PlayCanvas Forum
Possible to use Youtube iFrame in 360 Video Player? ... at Css3Plane.disable (https://launch.playcanvas.com/api/assets/files/scripts/Shops/ ...
#61. Youtube iFrame Embed throws console errors - Forum | Webflow
I have two youtube iFrame custom code embeds using lazy loading on my ... a straight-up IFRAME embed or are you using the YouTube js api to ...
#62. How to read embed youtube iframe events - Ionic Angular
So there is code that works well when writing/controlling youtube iframe: HTML: < "div ... YouTube Player API Reference for iframe Embeds.
#63. Accelerating Angular Development with Ivy: A practical guide ...
This is a loader script for the initialization script, which sets up the YouTube API needed to embed YouTube videos. The Angular YouTube Player component is ...
#64. 知識擴散平台之設計與實作: 知識擴散平台之設計與實作_碩士論文
第二章技術與文獻探討本章節介紹知識擴散平台所使用到的主要技術,包括PHP&MySQL、Bootstrap、 Youtube Iframe Player API、Youtube DataAPI、歐付寶第三方支付平台。
#65. 「あのサイトみたいに!」を実現できる!職業デザイナーでなくてもWebの表現を豊かにできる本
3 ▷図1 APIの動作イメージ<script src="https://www.youtube.com/iframe_api"></script> 1APIを要求 var player; function onYouTubeIframeAPIReady() { player= ...
#66. How to Get a YouTube API Key [Tutorial + Examples]
The YouTube API is an application programming interface that allows you to embed videos, curate playlists, and offer other YouTube ...
#67. Video.js - Make your player yours | Video.js
The world's most popular open source HTML5 player framework. ... It supports HTML5 video and modern streaming formats, as well as YouTube and Vimeo.
#68. How To Hide Related Videos In YouTube Embeds (in 2023)
YouTube Player API Release Notes - August 23, 2018. This option was likely deprecated because it was not seeing a lot of use, but the sudden ...
#69. Embedded Videos - Social Plugins - Meta for Developers
With the embedded video player you can easily add Facebook videos and ... Load Facebook SDK for JavaScript --> <div id="fb-root"></div> <script async defer ...
#70. Github youtube app. Go to file. Curate this topic Add this topi
GitHub - youtube/api-samples: Code samples for YouTube APIs, including the ... Updated on Dec 24, 2022. android youtube video android-youtube-player Updated ...
#71. Youtube iframe api посылает тысячи неудачных запросов ...
Расскажу немного: в РФ немного всё же блокируется ютубчик. Но не все функции. Например у тебя не будет отображаться иконка канала.
#72. Настройка плеера YouTube iframe - Snipp.ru
<iframe src="https://www.youtube.com/embed/VIDEO_ID?controls=0" ... origin=1 – включает дополнительные меры безопасности для IFrame API.
#73. How to disable full screen on youtube Iframe - iTecNote
embed html5-videoiframeyoutubeyoutube-api. I have a div container and Iframe inside. I assigned width=200 and height=200. when I click on full screen, ...
#74. The Video Embed element - HTML - MDN Web Docs - Mozilla
The HTML element embeds a media player which supports video playback ... own custom controls using JavaScript and the HTMLMediaElement API.
#75. Youtube embed autoplay not working. Maybe in the future I ...
Learn more about Teams Bug description: Youtube embedded player not working correctly in webview. You will find the setting under Settings The API calls ...
#76. Jitsi iframe example
... that allows YouTube's iframe API to interact with them. You can use the Jitsi Meet API to embed Jitsi Meet in to your application.
#77. Add fullscreen button to iframe
The allowfullscreen HTML attribute can be used to embed YouTube videos. enabled ... Building on yesterday's post on the Fullscreen API, today we're going to ...
#78. Iframe vs embed
Jun 26, 2006 · embed vs. js by default as to the HTML code of API ... After clicking on 'Embed', YouTube will automatically generate a code for you to use.
#79. Jitsi iframe example
Using iframe API gives you the same even more Apr 16, 2020 · Como usar jitsi. ... How To Jitsi Meet Video Conference embed on iFrame - YouTube www.
#80. Html5 m3u8 player code
Youtube and Vimeo video embedding with video details fetched from the api. Test DRM protected streams with Bitmovin's Video Player using live code ...
#81. Html m3u8 player example. At the start of the streaming ...
How about support for VLC converted YouTube links by following: VLC ... JavaScript player. js which primarily means that the MediaSource API must be ...
#82. Iframe vs embed
The Wistia video player has a JavaScript API which supports a number of ways to interact ... Grab the embed code from YouTube, by clicking on Share > Embed.
#83. Why & How to Enable Privacy-Enhanced Mode in YouTube
Looking to embed a YouTube video? Want to secure the privacy of your users? Here is how you can enable privacy-enhanced mode in YouTube ...
#84. Plyr - A simple, customizable HTML5 Video, Audio, YouTube ...
A simple HTML5 media player with custom controls and WebVTT captions.
#85. Generate responsive embed codes - Iframely
Get responsive embed codes for your YouTube, Vimeo or over 1900 others. ... cards, GIFs, AMP, simple APIs — crafted to perfection with coffee and love.
#86. 搶先看!iPhone 15模型機流出「6大改變」一窺新機面貌
根據知名YouTube頻道「Unbox Therapy」日前所釋出的iPhone 15模型機開箱新影片,歸納 ... picture-in-picture; web-share" allowfullscreen></iframe>.
#87. Embed & connect other apps – Notion Help Center
You can embed virtually any online content within Notion pages — from video and ... YouTube. While pretty much any online content can be embedded on a page, ...
#88. Iframe not loading in chrome
The iframe element, by itself, is not a security risk to you or your site visitors ... recommend using the iframe method like the YouTube IFrame Player API.
#89. Iframe url refused to connect
I am practicing to build a website and want to put a video from youtube in tag but ... I used amazon-quicksight-embedding-sdk to embed dashboard in iframe, ...
#90. Autoplay policy in Chrome - Chrome Developers
For the Web Audio API, the autoplay policy launched in Chrome 71. ... <iframe src="https://cross-origin.com/myvideo.html" allow="autoplay">
#91. Security - Angular
Avoid Angular APIs marked in the documentation as "Security Risk" ... lets users enter a YouTube video ID and load the corresponding video in an <iframe> .
#92. Iframe content not showing
iFrame content not translated with language The code YouTube shows on the embed ... Page inside iFrame calls rest apis of Site B and loads other pages from ...
#93. Embedding Video and Clips - Twitch Developers
Embedding live streams and VODs in an interactive iframe. ... view count, and associated Twitch channel is available via the Get Videos API endpoint.
#94. A realsrv com iframe php
Learn more about TeamsUsing the iFrame API, Relatel can automatically open ... umum dari penggunaan iFrame adalah penyematan video YouTube. google workspace ...
#95. Two weeks ost korean drama - The Foil Printing Co.
3 weeks 3 Emin bayramov rt How to download mp3 files from youtube Free ... mobile appraiser Style taylor swift lyric video Youtube iframe api jquery!
#96. Play and pause a video - Flutter documentation
Display the video player. Play and pause the video. ... networkUrl( Uri.parse( 'https://flutter.github.io/assets-for-api-docs/assets/videos/butterfly.mp4', ) ...
#97. SDK vs. API: What's the Difference? - IBM Blog
Learn about software development kits (SDKs) and Application Programming Interfaces (APIs) and how they improve both software development cycles ...
#98. Add videos using picture-in-picture (PiP) - Android Developers
PiP leverages the multi-window APIs made available in Android 7.0 to ... into picture-in-picture—for example, the video view bounds in a video player.
youtube iframe api 在 YouTube Player API Reference for iframe Embeds 的推薦與評價
The IFrame player API lets you embed a YouTube video player on your website and control the player using JavaScript.
Using the API's JavaScript functions, you can queue videos for playback; play, pause, or stop those videos; adjust the player volume; or retrieve information about the video being played. You can also add event listeners that will execute in response to certain player events, such as a player state change.
This guide explains how to use the IFrame API. It identifies the different types of events that the API can send and explains how to write event listeners to respond to those events. It also details the different JavaScript functions that you can call to control the video player as well as the player parameters you can use to further customize the player.
RequirementsThe user's browser must support the HTML5
postMessage
feature. Most modern browsers supportpostMessage
.Embedded players must have a viewport that is at least 200px by 200px. If the player displays controls, it must be large enough to fully display the controls without shrinking the viewport below the minimum size. We recommend 16:9 players be at least 480 pixels wide and 270 pixels tall.
Any web page that uses the IFrame API must also implement the following JavaScript function:
onYouTubeIframeAPIReady
– The API will call this function when the page has finished downloading the JavaScript for the player API, which enables you to then use the API on your page. Thus, this function might create the player objects that you want to display when the page loads.Getting started
The sample HTML page below creates an embedded player that will load a video, play it for six seconds, and then stop the playback. The numbered comments in the HTML are explained in the list below the example.
The following list provides more details about the sample above:
The
<div>
tag in this section identifies the location on the page where the IFrame API will place the video player. The constructor for the player object, which is described in the Loading a video player section, identifies the<div>
tag by itsid
to ensure that the API places the<iframe>
in the proper location. Specifically, the IFrame API will replace the<div>
tag with the<iframe>
tag.As an alternative, you could also put the
<iframe>
element directly on the page. The Loading a video player section explains how to do so.The code in this section loads the IFrame Player API JavaScript code. The example uses DOM modification to download the API code to ensure that the code is retrieved asynchronously. (The
<script>
tag'sasync
attribute, which also enables asynchronous downloads, is not yet supported in all modern browsers as discussed in this Stack Overflow answer.The
onYouTubeIframeAPIReady
function will execute as soon as the player API code downloads. This portion of the code defines a global variable,player
, which refers to the video player you are embedding, and the function then constructs the video player object.The
onPlayerReady
function will execute when theonReady
event fires. In this example, the function indicates that when the video player is ready, it should begin to play.The API will call the
onPlayerStateChange
function when the player's state changes, which may indicate that the player is playing, paused, finished, and so forth. The function indicates that when the player state is1
(playing), the player should play for six seconds and then call thestopVideo
function to stop the video.Loading a video player
After the API's JavaScript code loads, the API will call the
onYouTubeIframeAPIReady
function, at which point you can construct aYT.Player
object to insert a video player on your page. The HTML excerpt below shows theonYouTubeIframeAPIReady
function from the example above:The constructor for the video player specifies the following parameters:
The first parameter specifies either the DOM element or the
id
of the HTML element where the API will insert the<iframe>
tag containing the player.The IFrame API will replace the specified element with the
<iframe>
element containing the player. This could affect the layout of your page if the element being replaced has a different display style than the inserted<iframe>
element. By default, an<iframe>
displays as aninline-block
element.The second parameter is an object that specifies player options. The object contains the following properties:
width
(number) – The width of the video player. The default value is640
.height
(number) – The height of the video player. The default value is390
.videoId
(string) – The YouTube video ID that identifies the video that the player will load.playerVars
(object) – The object's properties identify player parameters that can be used to customize the player.events
(object) – The object's properties identify the events that the API fires and the functions (event listeners) that the API will call when those events occur. In the example, the constructor indicates that theonPlayerReady
function will execute when theonReady
event fires and that theonPlayerStateChange
function will execute when theonStateChange
event fires.As mentioned in the Getting started section, instead of writing an empty
<div>
element on your page, which the player API's JavaScript code will then replace with an<iframe>
element, you could create the<iframe>
tag yourself. The first example in the Examples section shows how to do this.Note that if you do write the
<iframe>
tag, then when you construct theYT.Player
object, you do not need to specify values for thewidth
andheight
, which are specified as attributes of the<iframe>
tag, or thevideoId
and player parameters, which are are specified in thesrc
URL. As an extra security measure, you should also include theorigin
parameter to the URL, specifying the URL scheme (http://
orhttps://
) and full domain of your host page as the parameter value. Whileorigin
is optional, including it protects against malicious third-party JavaScript being injected into your page and hijacking control of your YouTube player.The Examples section also shows a couple other examples for constructing video player objects.
OperationsTo call the player API methods, you must first get a reference to the player object you wish to control. You obtain the reference by creating a
FunctionsQueueing functionsYT.Player
object as discussed in the Getting started and Loading a video player sections of this document.Queueing functions allow you to load and play a video, a playlist, or another list of videos. If you are using the object syntax described below to call these functions, then you can also queue or load a list of a user's uploaded videos.
The API supports two different syntaxes for calling the queueing functions.
The argument syntax requires function arguments to be listed in a prescribed order.
The object syntax lets you pass an object as a single parameter and to define object properties for the function arguments that you wish to set. In addition, the API may support additional functionality that the argument syntax does not support.
For example, the
loadVideoById
function can be called in either of the following ways. Note that the object syntax supports theendSeconds
property, which the argument syntax does not support.Argument syntax
Object syntax
Queueing functions for videos
cueVideoById
Argument syntax
Object syntax
This function loads the specified video's thumbnail and prepares the player to play the video. The player does not request the FLV until
playVideo()
orseekTo()
is called.The required
videoId
parameter specifies the YouTube Video ID of the video to be played. In the YouTube Data API, avideo
resource'sid
property specifies the ID.The optional
startSeconds
parameter accepts a float/integer and specifies the time from which the video should start playing whenplayVideo()
is called. If you specify astartSeconds
value and then callseekTo()
, then the player plays from the time specified in theseekTo()
call. When the video is cued and ready to play, the player will broadcast avideo cued
event (5
).The optional
endSeconds
parameter, which is only supported in object syntax, accepts a float/integer and specifies the time when the video should stop playing whenplayVideo()
is called. If you specify anendSeconds
value and then callseekTo()
, theendSeconds
value will no longer be in effect.loadVideoById
Argument syntax
Object syntax
This function loads and plays the specified video.
The required
videoId
parameter specifies the YouTube Video ID of the video to be played. In the YouTube Data API, avideo
resource'sid
property specifies the ID.The optional
startSeconds
parameter accepts a float/integer. If it is specified, then the video will start from the closest keyframe to the specified time.The optional
endSeconds
parameter accepts a float/integer. If it is specified, then the video will stop playing at the specified time.cueVideoByUrl
Argument syntax
Object syntax
This function loads the specified video's thumbnail and prepares the player to play the video. The player does not request the FLV until
playVideo()
orseekTo()
is called.The required
mediaContentUrl
parameter specifies a fully qualified YouTube player URL in the formathttp://www.youtube.com/v/VIDEO_ID?version=3
.The optional
startSeconds
parameter accepts a float/integer and specifies the time from which the video should start playing whenplayVideo()
is called. If you specifystartSeconds
and then callseekTo()
, then the player plays from the time specified in theseekTo()
call. When the video is cued and ready to play, the player will broadcast avideo cued
event (5).The optional
endSeconds
parameter, which is only supported in object syntax, accepts a float/integer and specifies the time when the video should stop playing whenplayVideo()
is called. If you specify anendSeconds
value and then callseekTo()
, theendSeconds
value will no longer be in effect.loadVideoByUrl
Argument syntax
Object syntax
This function loads and plays the specified video.
The required
mediaContentUrl
parameter specifies a fully qualified YouTube player URL in the formathttp://www.youtube.com/v/VIDEO_ID?version=3
.The optional
startSeconds
parameter accepts a float/integer and specifies the time from which the video should start playing. IfstartSeconds
(number can be a float) is specified, the video will start from the closest keyframe to the specified time.The optional
endSeconds
parameter, which is only supported in object syntax, accepts a float/integer and specifies the time when the video should stop playing.Queueing functions for lists
The
cuePlaylist
andloadPlaylist
functions allow you to load and play a playlist. If you are using object syntax to call these functions, you can also queue (or load) a list of a user's uploaded videos.Since the functions work differently depending on whether they are called using the argument syntax or the object syntax, both calling methods are documented below.
cuePlaylist
Argument syntax
Queues the specified playlist. When the playlist is cued and ready to play, the player will broadcast a
video cued
event (5
).The required
playlist
parameter specifies an array of YouTube video IDs. In the YouTube Data API, thevideo
resource'sid
property identifies that video's ID.The optional
index
parameter specifies the index of the first video in the playlist that will play. The parameter uses a zero-based index, and the default parameter value is0
, so the default behavior is to load and play the first video in the playlist.The optional
startSeconds
parameter accepts a float/integer and specifies the time from which the first video in the playlist should start playing when theplayVideo()
function is called. If you specify astartSeconds
value and then callseekTo()
, then the player plays from the time specified in theseekTo()
call. If you cue a playlist and then call theplayVideoAt()
function, the player will start playing at the beginning of the specified video.Object syntax
Queues the specified list of videos. The list can be a playlist or a user's uploaded videos feed. The ability to queue a list of search results is deprecated and will no longer be supported as of 15 November 2020.
When the list is cued and ready to play, the player will broadcast a
video cued
event (5
).The optional
listType
property specifies the type of results feed that you are retrieving. Valid values areplaylist
anduser_uploads
. A deprecated value,search
, will no longer be supported as of 15 November 2020. The default value isplaylist
.The required
list
property contains a key that identifies the particular list of videos that YouTube should return.If the
listType
property value isplaylist
, then thelist
property specifies the playlist ID or an array of video IDs. In the YouTube Data API, theplaylist
resource'sid
property identifies a playlist's ID, and thevideo
resource'sid
property specifies a video ID.If the
listType
property value isuser_uploads
, then thelist
property identifies the user whose uploaded videos will be returned.If the
listType
property value issearch
, then thelist
property specifies the search query. Note: This functionality is deprecated and will no longer be supported as of 15 November 2020.The optional
index
property specifies the index of the first video in the list that will play. The parameter uses a zero-based index, and the default parameter value is0
, so the default behavior is to load and play the first video in the list.The optional
startSeconds
property accepts a float/integer and specifies the time from which the first video in the list should start playing when theplayVideo()
function is called. If you specify astartSeconds
value and then callseekTo()
, then the player plays from the time specified in theseekTo()
call. If you cue a list and then call theplayVideoAt()
function, the player will start playing at the beginning of the specified video.loadPlaylist
Argument syntax
This function loads the specified playlist and plays it.
The required
playlist
parameter specifies an array of YouTube video IDs. In the YouTube Data API, thevideo
resource'sid
property specifies a video ID.The optional
index
parameter specifies the index of the first video in the playlist that will play. The parameter uses a zero-based index, and the default parameter value is0
, so the default behavior is to load and play the first video in the playlist.The optional
startSeconds
parameter accepts a float/integer and specifies the time from which the first video in the playlist should start playing.Object syntax
This function loads the specified list and plays it. The list can be a playlist or a user's uploaded videos feed. The ability to load a list of search results is deprecated and will no longer be supported as of 15 November 2020.
The optional
listType
property specifies the type of results feed that you are retrieving. Valid values areplaylist
anduser_uploads
. A deprecated value,search
, will no longer be supported as of 15 November 2020. The default value isplaylist
.The required
list
property contains a key that identifies the particular list of videos that YouTube should return.If the
listType
property value isplaylist
, then thelist
property specifies a playlist ID or an array of video IDs. In the YouTube Data API, theplaylist
resource'sid
property specifies a playlist's ID, and thevideo
resource'sid
property specifies a video ID.If the
listType
property value isuser_uploads
, then thelist
property identifies the user whose uploaded videos will be returned.If the
listType
property value issearch
, then thelist
property specifies the search query. Note: This functionality is deprecated and will no longer be supported as of 15 November 2020.The optional
index
property specifies the index of the first video in the list that will play. The parameter uses a zero-based index, and the default parameter value is0
, so the default behavior is to load and play the first video in the list.The optional
startSeconds
property accepts a float/integer and specifies the time from which the first video in the list should start playing.Playback controls and player settings
Playing a video
player.playVideo():Void
Plays the currently cued/loaded video. The final player state after this function executes will be
playing
(1).Note: A playback only counts toward a video's official view count if it is initiated via a native play button in the player.
player.pauseVideo():Void
Pauses the currently playing video. The final player state after this function executes will be
paused
(2
) unless the player is in theended
(0
) state when the function is called, in which case the player state will not change.player.stopVideo():Void
Stops and cancels loading of the current video. This function should be reserved for rare situations when you know that the user will not be watching additional video in the player. If your intent is to pause the video, you should just call the
pauseVideo
function. If you want to change the video that the player is playing, you can call one of the queueing functions without callingstopVideo
first.Important: Unlike the
pauseVideo
function, which leaves the player in thepaused
(2
) state, thestopVideo
function could put the player into any not-playing state, includingended
(0
),paused
(2
),video cued
(5
) orunstarted
(-1
).player.seekTo(seconds:Number, allowSeekAhead:Boolean):Void
Seeks to a specified time in the video. If the player is paused when the function is called, it will remain paused. If the function is called from another state (
playing
,video cued
, etc.), the player will play the video.The
seconds
parameter identifies the time to which the player should advance.The player will advance to the closest keyframe before that time unless the player has already downloaded the portion of the video to which the user is seeking.
The
allowSeekAhead
parameter determines whether the player will make a new request to the server if theseconds
parameter specifies a time outside of the currently buffered video data.We recommend that you set this parameter to
false
while the user drags the mouse along a video progress bar and then set it totrue
when the user releases the mouse. This approach lets a user scroll to different points of a video without requesting new video streams by scrolling past unbuffered points in the video. When the user releases the mouse button, the player advances to the desired point in the video and requests a new video stream if necessary.Controlling playback of 360° videos
Note: The 360° video playback experience has limited support on mobile devices. On unsupported devices, 360° videos appear distorted and there is no supported way to change the viewing perspective at all, including through the API, using orientation sensors, or responding to touch/drag actions on the device's screen.
player.getSphericalProperties():Object
Retrieves properties that describe the viewer's current perspective, or view, for a video playback. In addition:
This object is only populated for 360° videos, which are also called spherical videos.
If the current video is not a 360° video or if the function is called from a non-supported device, then the function returns an empty object.
On supported mobile devices, if the
enableOrientationSensor
property is set totrue
, then this function returns an object in which thefov
property contains the correct value and the other properties are set to0
.The object contains the following properties:
Properties
yaw
A number in the range [0, 360) that represents the horizontal angle of the view in degrees, which reflects the extent to which the user turns the view to face further left or right. The neutral position, facing the center of the video in its equirectangular projection, represents 0°, and this value increases as the viewer turns left.
pitch
A number in the range [-90, 90] that represents the vertical angle of the view in degrees, which reflects the extent to which the user adjusts the view to look up or down. The neutral position, facing the center of the video in its equirectangular projection, represents 0°, and this value increases as the viewer looks up.
roll
A number in the range [-180, 180] that represents the clockwise or counterclockwise rotational angle of the view in degrees. The neutral position, with the horizontal axis in the equirectangular projection being parallel to the horizontal axis of the view, represents 0°. The value increases as the view rotates clockwise and decreases as the view rotates counterclockwise.
Note that the embedded player does not present a user interface for adjusting the roll of the view. The roll can be adjusted in either of these mutually exclusive ways:
Use the orientation sensor in a mobile browser to provide roll for the view. If the orientation sensor is enabled, then the
getSphericalProperties
function always returns0
as the value of theroll
property.If the orientation sensor is disabled, set the roll to a nonzero value using this API.
fov
A number in the range [30, 120] that represents the field-of-view of the view in degrees as measured along the longer edge of the viewport. The shorter edge is automatically adjusted to be proportional to the aspect ratio of the view.
The default value is 100 degrees. Decreasing the value is like zooming in on the video content, and increasing the value is like zooming out. This value can be adjusted either by using the API or by using the mousewheel when the video is in fullscreen mode.
player.setSphericalProperties(properties:Object):Void
Sets the video orientation for playback of a 360° video. (If the current video is not spherical, the method is a no-op regardless of the input.)
The player view responds to calls to this method by updating to reflect the values of any known properties in the
properties
object. The view persists values for any other known properties not included in that object.In addition:
If the object contains unknown and/or unexpected properties, the player ignores them.
As noted at the beginning of this section, the 360° video playback experience is not supported on all mobile devices.
By default, on supported mobile devices, this function sets only sets the
fov
property and does not affect theyaw
,pitch
, androll
properties for 360° video playbacks. See theenableOrientationSensor
property below for more detail.The
properties
object passed to the function contains the following properties:Properties
yaw
See definition above.
pitch
See definition above.
roll
See definition above.
fov
See definition above.
enableOrientationSensor
Note: This property affects the 360° viewing experience on supported devices only.A boolean value that indicates whether the IFrame embed should respond to events that signal changes in a supported device's orientation, such as a mobile browser's
DeviceOrientationEvent
. The default parameter value istrue
.Supported mobile devices
When the value is
true
, an embedded player relies only on the device's movement to adjust theyaw
,pitch
, androll
properties for 360° video playbacks. However, thefov
property can still be changed via the API, and the API is, in fact, the only way to change thefov
property on a mobile device. This is the default behavior.When the value is
false
, then the device's movement does not affect the 360° viewing experience, and theyaw
,pitch
,roll
, andfov
properties must all be set via the API.Unsupported mobile devices
The
enableOrientationSensor
property value does not have any effect on the playback experience.Playing a video in a playlist
player.nextVideo():Void
This function loads and plays the next video in the playlist.
If
player.nextVideo()
is called while the last video in the playlist is being watched, and the playlist is set to play continuously (loop
), then the player will load and play the first video in the list.If
player.nextVideo()
is called while the last video in the playlist is being watched, and the playlist is not set to play continuously, then playback will end.player.previousVideo():Void
This function loads and plays the previous video in the playlist.
If
player.previousVideo()
is called while the first video in the playlist is being watched, and the playlist is set to play continuously (loop
), then the player will load and play the last video in the list.If
player.previousVideo()
is called while the first video in the playlist is being watched, and the playlist is not set to play continuously, then the player will restart the first playlist video from the beginning.player.playVideoAt(index:Number):Void
This function loads and plays the specified video in the playlist.
The required
index
parameter specifies the index of the video that you want to play in the playlist. The parameter uses a zero-based index, so a value of0
identifies the first video in the list. If you have shuffled the playlist, this function will play the video at the specified position in the shuffled playlist.Changing the player volume
player.mute():Void
Mutes the player.
player.unMute():Void
Unmutes the player.
player.isMuted():Boolean
Returns
true
if the player is muted,false
if not.player.setVolume(volume:Number):Void
Sets the volume. Accepts an integer between
0
and100
.player.getVolume():Number
Returns the player's current volume, an integer between
0
and100
. Note thatgetVolume()
will return the volume even if the player is muted.Setting the player size
player.setSize(width:Number, height:Number):Object
Sets the size in pixels of the
<iframe>
that contains the player.Setting the playback rate
player.getPlaybackRate():Number
This function retrieves the playback rate of the currently playing video. The default playback rate is
1
, which indicates that the video is playing at normal speed. Playback rates may include values like0.25
,0.5
,1
,1.5
, and2
.player.setPlaybackRate(suggestedRate:Number):Void
This function sets the suggested playback rate for the current video. If the playback rate changes, it will only change for the video that is already cued or being played. If you set the playback rate for a cued video, that rate will still be in effect when the
playVideo
function is called or the user initiates playback directly through the player controls. In addition, calling functions to cue or load videos or playlists (cueVideoById
,loadVideoById
, etc.) will reset the playback rate to1
.Calling this function does not guarantee that the playback rate will actually change. However, if the playback rate does change, the
onPlaybackRateChange
event will fire, and your code should respond to the event rather than the fact that it called thesetPlaybackRate
function.The
getAvailablePlaybackRates
method will return the possible playback rates for the currently playing video. However, if you set thesuggestedRate
parameter to a non-supported integer or float value, the player will round that value down to the nearest supported value in the direction of1
.player.getAvailablePlaybackRates():Array
This function returns the set of playback rates in which the current video is available. The default value is
1
, which indicates that the video is playing in normal speed.The function returns an array of numbers ordered from slowest to fastest playback speed. Even if the player does not support variable playback speeds, the array should always contain at least one value (
1
).Setting playback behavior for playlists
player.setLoop(loopPlaylists:Boolean):Void
This function indicates whether the video player should continuously play a playlist or if it should stop playing after the last video in the playlist ends. The default behavior is that playlists do not loop.
This setting will persist even if you load or cue a different playlist, which means that if you load a playlist, call the
setLoop
function with a value oftrue
, and then load a second playlist, the second playlist will also loop.The required
loopPlaylists
parameter identifies the looping behavior.If the parameter value is
true
, then the video player will continuously play playlists. After playing the last video in a playlist, the video player will go back to the beginning of the playlist and play it again.If the parameter value is
false
, then playbacks will end after the video player plays the last video in a playlist.player.setShuffle(shufflePlaylist:Boolean):Void
This function indicates whether a playlist's videos should be shuffled so that they play back in an order different from the one that the playlist creator designated. If you shuffle a playlist after it has already started playing, the list will be reordered while the video that is playing continues to play. The next video that plays will then be selected based on the reordered list.
This setting will not persist if you load or cue a different playlist, which means that if you load a playlist, call the
setShuffle
function, and then load a second playlist, the second playlist will not be shuffled.The required
shufflePlaylist
parameter indicates whether YouTube should shuffle the playlist.If the parameter value is
true
, then YouTube will shuffle the playlist order. If you instruct the function to shuffle a playlist that has already been shuffled, YouTube will shuffle the order again.If the parameter value is
false
, then YouTube will change the playlist order back to its original order.Playback status
player.getVideoLoadedFraction():Float
Returns a number between
0
and1
that specifies the percentage of the video that the player shows as buffered. This method returns a more reliable number than the now-deprecatedgetVideoBytesLoaded
andgetVideoBytesTotal
methods.player.getPlayerState():Number
Returns the state of the player. Possible values are:
-1
– unstarted0
– ended1
– playing2
– paused3
– buffering5
– video cuedplayer.getCurrentTime():Number
Returns the elapsed time in seconds since the video started playing.
player.getVideoStartBytes():Number
Deprecated as of October 31, 2012. Returns the number of bytes the video file started loading from. (This method now always returns a value of
0
.) Example scenario: the user seeks ahead to a point that hasn't loaded yet, and the player makes a new request to play a segment of the video that hasn't loaded yet.player.getVideoBytesLoaded():Number
Deprecated as of July 18, 2012. Instead, use the
getVideoLoadedFraction
method to determine the percentage of the video that has buffered.This method returns a value between
0
and1000
that approximates the amount of the video that has been loaded. You could calculate the fraction of the video that has been loaded by dividing thegetVideoBytesLoaded
value by thegetVideoBytesTotal
value.player.getVideoBytesTotal():Number
Deprecated as of July 18, 2012. Instead, use the
getVideoLoadedFraction
method to determine the percentage of the video that has buffered.Returns the size in bytes of the currently loaded/playing video or an approximation of the video's size.
This method always returns a value of
1000
. You could calculate the fraction of the video that has been loaded by dividing thegetVideoBytesLoaded
value by thegetVideoBytesTotal
value.Retrieving video information
player.getDuration():Number
Returns the duration in seconds of the currently playing video. Note that
getDuration()
will return0
until the video's metadata is loaded, which normally happens just after the video starts playing.If the currently playing video is a live event, the
getDuration()
function will return the elapsed time since the live video stream began. Specifically, this is the amount of time that the video has streamed without being reset or interrupted. In addition, this duration is commonly longer than the actual event time since streaming may begin before the event's start time.player.getVideoUrl():String
Returns the YouTube.com URL for the currently loaded/playing video.
player.getVideoEmbedCode():String
Returns the embed code for the currently loaded/playing video.
Retrieving playlist information
player.getPlaylist():Array
This function returns an array of the video IDs in the playlist as they are currently ordered. By default, this function will return video IDs in the order designated by the playlist owner. However, if you have called the
setShuffle
function to shuffle the playlist order, then thegetPlaylist()
function's return value will reflect the shuffled order.player.getPlaylistIndex():Number
This function returns the index of the playlist video that is currently playing.
If you have not shuffled the playlist, the return value will identify the position where the playlist creator placed the video. The return value uses a zero-based index, so a value of
0
identifies the first video in the playlist.If you have shuffled the playlist, the return value will identify the video's order within the shuffled playlist.
Adding or removing an event listener
player.addEventListener(event:String, listener:String):Void
Adds a listener function for the specified
event
. The Events section below identifies the different events that the player might fire. The listener is a string that specifies the function that will execute when the specified event fires.player.removeEventListener(event:String, listener:String):Void
Removes a listener function for the specified
event
. Thelistener
is a string that identifies the function that will no longer execute when the specified event fires.Accessing and modifying DOM nodes
player.getIframe():Object
This method returns the DOM node for the embedded
<iframe>
.player.destroy():Void
Removes the
<iframe>
containing the player.Events
The API fires events to notify your application of changes to the embedded player. As noted in the previous section, you can subscribe to events by adding an event listener when constructing the
YT.Player
object, and you can also use theaddEventListener
function.The API will pass an event object as the sole argument to each of those functions. The event object has the following properties:
The event's
target
identifies the video player that corresponds to the event.The event's
data
specifies a value relevant to the event. Note that theonReady
andonAutoplayBlocked
events do not specify adata
property.The following list defines the events that the API fires:
onReady
This event fires whenever a player has finished loading and is ready to begin receiving API calls. Your application should implement this function if you want to automatically execute certain operations, such as playing the video or displaying information about the video, as soon as the player is ready.
The example below shows a sample function for handling this event. The event object that the API passes to the function has a
target
property, which identifies the player. The function retrieves the embed code for the currently loaded video, starts to play the video, and displays the embed code in the page element that has anid
value ofembed-code
.onStateChange
This event fires whenever the player's state changes.
The
data
property of the event object that the API passes to your event listener function will specify an integer that corresponds to the new player state.Possible values are:
-1
(unstarted)0
(ended)1
(playing)2
(paused)3
(buffering)5
(video cued).When the player first loads a video, it will broadcast an
unstarted
(-1
) event. When a video is cued and ready to play, the player will broadcast avideo cued
(5
) event. In your code, you can specify the integer values or you can use one of the following namespaced variables:YT.PlayerState.ENDED
YT.PlayerState.PLAYING
YT.PlayerState.PAUSED
YT.PlayerState.BUFFERING
YT.PlayerState.CUED
onPlaybackQualityChange
This event fires whenever the video playback quality changes. It might signal a change in the viewer's playback
environment. See the YouTube Help Center for more
information about factors that affect playback conditions or that might cause the event to fire.
The
data
property value of the event object that the API passes to the event listener function will be a string that identifies the new playback quality.Possible values are:
small
medium
large
hd720
hd1080
highres
onPlaybackRateChange
This event fires whenever the video playback rate changes. For example, if you call the
setPlaybackRate(suggestedRate)
function, this event will fire if the playback rate actually changes. Your application should respond to the event and should not assume that the playback rate will automatically change when thesetPlaybackRate(suggestedRate)
function is called. Similarly, your code should not assume that the video playback rate will only change as a result of an explicit call tosetPlaybackRate
.The
data
property value of the event object that the API passes to the event listener function will be a number that identifies the new playback rate.The
getAvailablePlaybackRates
method returns a list of the valid playback rates for the currently cued or playing video.onError
This event fires if an error occurs in the player.
The API will pass an
event
object to the event listener function. That object'sdata
property will specify an integer that identifies the type of error that occurred.Possible values are:
2
– The request contains an invalid parameter value. For example, this error occurs if you specify a video ID that does not have 11 characters, or if the video ID contains invalid characters, such as exclamation points or asterisks.5
– The requested content cannot be played in an HTML5 player or another error related to the HTML5 player has occurred.100
– The video requested was not found. This error occurs when a video has been removed (for any reason) or has been marked as private.101
– The owner of the requested video does not allow it to be played in embedded players.150
– This error is the same as101
. It's just a101
error in disguise!onApiChange
This event is fired to indicate that the player has loaded (or unloaded) a module with exposed API methods. Your application can listen for this event and then poll the player to determine which options are exposed for the recently loaded module. Your application can then retrieve or update the existing settings for those options.
The following command retrieves an array of module names for which you can set player options:
Currently, the only module that you can set options for is the
captions
module, which handles closed captioning in the player. Upon receiving anonApiChange
event, your application can use the following command to determine which options can be set for thecaptions
module:By polling the player with this command, you can confirm that the options you want to access are, indeed, accessible. The following commands retrieve and update module options:
The table below lists the options that the API supports:
Module
Option
Description
captions
fontSize
This option adjusts the font size of the captions displayed in the player.
Valid values are
-1
,0
,1
,2
, and3
. The default size is0
, and the smallest size is-1
. Setting this option to an integer below-1
will cause the smallest caption size to display, while setting this option to an integer above3
will cause the largest caption size to display.captions
reload
This option reloads the closed caption data for the video that is playing. The value will be
null
if you retrieve the option's value. Set the value totrue
to reload the closed caption data.onAutoplayBlocked
This event fires any time the browser blocks autoplay or scripted video playback features,
collectively referred to as "autoplay". This includes playback attempted with any of the
following player APIs:
autoplay
parameterloadPlaylist
functionloadVideoById
functionloadVideoByUrl
functionplayVideo
functionMost browsers have policies that can block autoplay in desktop, mobile, and other
environments if certain conditions are true. Instances where this policy may be triggered
include unmuted playback without user
interaction, or when a Permissions Policy
to permit autoplay on a cross-origin iframe has not been set.
For complete details, refer to browser-specific policies
(Apple Safari / Webkit,
Google Chrome,
Mozilla Firefox)
and Mozilla's autoplay guide.
Examples
Creating
YT.Player
objectsExample 1: Use API with existing <iframe>
In this example, an
<iframe>
element on the page already defines the player with which the API will be used. Note that either the player'ssrc
URL must set theenablejsapi
parameter to1
or the<iframe>
element'senablejsapi
attribute must be set totrue
.The
onPlayerReady
function changes the color of the border around the player to orange when the player is ready. TheonPlayerStateChange
function then changes the color of the border around the player based on the current player status. For example, the color is green when the player is playing, red when paused, blue when buffering, and so forth.This example uses the following code:
Example 2: Loud playback
This example creates a 1280px by 720px video player. The event listener for the
onReady
event then calls thesetVolume
function to adjust the volume to the highest setting.Example 3: This example sets player parameters to automatically play the video when it loads and to hide the video player's controls. It also adds event listeners for several events that the API broadcasts.
Controlling 360° videos
This example uses the following code:
Android WebView Media Integrity API integration
YouTube has extended the
Android WebView Media Integrity API
to enable embedded media players, including YouTube player embeds in Android applications, to
verify the embedding app's authenticity. With this change, embedding apps automatically send an
attested app ID to YouTube. The data collected through usage of this API is the app metadata (the
package name, version number, and signing certificate) and a device attestation token generated by
Google Play services.
The data is used to verify the application and device integrity. It is encrypted, not shared with
third parties, and deleted following a fixed retention period. App developers can
configure their app identity
in the WebView Media Integrity API. The configuration supports an opt-out option.
Revision history
June 24, 2024
The documentation has been updated to note that YouTube has extended the
Android WebView Media Integrity API
to enable embedded media players, including YouTube player embeds in Android applications, to
verify the embedding app's authenticity. With this change, embedding apps automatically send an
attested app ID to YouTube.
November 20, 2023
The new
onAutoplayBlocked
event API is now available.This event notifies your application if the browser blocks autoplay or scripted playback.
Verification of autoplay success or failure is an
established paradigm
for HTMLMediaElements, and the
onAutoplayBlocked
event now provides similarfunctionality for the IFrame Player API.
April 27, 2021
The Getting Started and Loading a Video Player sections have been updated to include examples of using a
playerVars
object to customize the player.October 13, 2020
Note: This is a deprecation announcement for the embedded player
functionality that lets you configure the player to load search results. This announcement affects
the IFrame Player API's queueing functions for lists,
cuePlaylist
andloadPlaylist
.This change will become effective on or after 15 November 2020. After that time, calls to the
cuePlaylist
orloadPlaylist
functions that set thelistType
property to
search
will generate a4xx
response code, such as404
(Not Found
) or410
(Gone
). This changealso affects the
list
property for those functions as that property no longersupports the ability to specify a search query.
As an alternative, you can use the YouTube Data API's
search.list
method to retrieve searchresults and then load selected videos in the player.
October 24, 2019
The documentation has been updated to reflect the fact that the API no longer supports functions for setting or retrieving playback quality.
As explained in this YouTube Help Center article, to give you the best viewing
experience, YouTube adjusts the quality of your video stream based on your viewing conditions.
The changes explained below have been in effect for more than one year. This update merely aligns
the documentation with current functionality:
The
getPlaybackQuality
,setPlaybackQuality
, andgetAvailableQualityLevels
functionsare no longer supported. In particular, calls to
setPlaybackQuality
will be no-op functions, meaning they willnot actually have any impact on the viewer's playback experience.
The queueing functions for videos and playlists --
cueVideoById
,loadVideoById
, etc. -- no longer support thesuggestedQuality
argument.Similarly, if you call those functions using object syntax, the
suggestedQuality
field is no longer supported.If
suggestedQuality
is specified, it will be ignored when the request is handled. It will not generate anywarnings or errors.
The
onPlaybackQualityChange
event is still supported and might signal achange in the viewer's playback environment. See the Help Center article
referenced above for more information about factors that affect playback conditions or that might cause the event to fire.
May 16, 2018
The API now supports features that allow users (or embedders) to control the viewing perspective for 360° videos:
The
getSphericalProperties
function retrieves the current orientation for the video playback. The orientation includes the following data:yaw - represents the horizontal angle of the view in degrees, which reflects the extent to which the user turns the view to face further left or right
pitch - represents the vertical angle of the view in degrees, which reflects the extent to which the user adjusts the view to look up or down
roll - represents the rotational angle (clockwise or counterclockwise) of the view in degrees.
fov - represents the field-of-view of the view in degrees, which reflects the extent to which the user zooms in or out on the video.
The
setSphericalProperties
function modifies the view to match the submitted property values. In addition to the orientation values described above, this function supports a Boolean field that indicates whether the IFrame embed should respond toDeviceOrientationEvents
on supported mobile devices.This example demonstrates and lets you test these new features.
June 19, 2017
This update contains the following changes:
Documentation for the YouTube Flash Player API and YouTube JavaScript Player API has been removed and redirected to this document. The deprecation announcement for the Flash and JavaScript players was made on January 27, 2015. If you haven't done so already, please migrate your applications to use IFrame embeds and the IFrame Player API.
August 11, 2016
This update contains the following changes:
The newly published YouTube API Services Terms of Service ("the Updated Terms"), discussed in detail on the YouTube Engineering and Developers Blog, provides a rich set of updates to the current Terms of Service. In addition to the Updated Terms, which will go into effect as of February 10, 2017, this update includes several supporting documents to help explain the policies that developers must follow.
The full set of new documents is described in the revision history for the Updated Terms. In addition, future changes to the Updated Terms or to those supporting documents will also be explained in that revision history. You can subscribe to an RSS feed listing changes in that revision history from a link in that document.
June 29, 2016
This update contains the following changes:
The documentation has been corrected to note that the
onApiChange
method provides access to thecaptions
module and not thecc
module.June 24, 2016
The Examples section has been updated to include an example that demonstrates how to use the API with an existing
<iframe>
element.January 6, 2016
The
clearVideo
function has been deprecated and removed from the documentation. The function no longer has any effect in the YouTube player.December 18, 2015
European Union (EU) laws require that certain disclosures must be given to and consents obtained from end users in the EU. Therefore, for end users in the European Union, you must comply with the EU User Consent Policy. We have added a notice of this requirement in our YouTube API Terms of Service.
April 28, 2014
This update contains the following changes:
The new removeEventListener function lets you remove a listener for a specified event.
March 25, 2014
This update contains the following changes:
The Requirements section has been updated to note that embedded players must have a viewport that is at least 200px by 200px. If a player displays controls, it must be large enough to fully display the controls without shrinking the viewport below the minimum size. We recommend 16:9 players be at least 480 pixels wide and 270 pixels tall.
July 23, 2013
This update contains the following changes:
The Overview now includes a video of a 2011 Google I/O presentation that discusses the iframe player.
October 31, 2012
This update contains the following changes:
The Queueing functions section has been updated to explain that you can use either argument syntax or object syntax to call all of those functions. Note that the API may support additional functionality in object syntax that the argument syntax does not support.
In addition, the descriptions and examples for each of the video queueing functions have been updated to reflect the newly added support for object syntax. (The API's playlist queueing functions already supported object syntax.)
When called using object syntax, each of the video queueing functions supports an
endSeconds
property, which accepts a float/integer and specifies the time when the video should stop playing whenplayVideo()
is called.The
getVideoStartBytes
method has been deprecated. The method now always returns a value of0
.August 22, 2012
This update contains the following changes:
The example in the Loading a video player section that demonstrates how to manually create the
<iframe>
tag has been updated to include a closing</iframe>
tag since theonYouTubeIframeAPIReady
function is only called if the closing</iframe>
element is present.August 6, 2012
This update contains the following changes:
The Operations section has been expanded to list all of the supported API functions rather than linking to the JavaScript Player API Reference for that list.
The API supports several new functions and one new event that can be used to control the video playback speed:
Functions
getAvailablePlaybackRates
– Retrieve the supported playback rates for the cued or playing video. Note that variable playback rates are currently only supported in the HTML5 player.getPlaybackRate
– Retrieve the playback rate for the cued or playing video.setPlaybackRate
– Set the playback rate for the cued or playing video.Events
onPlaybackRateChange
– This event fires when the video's playback rate changes.July 19, 2012
This update contains the following changes:
The new
getVideoLoadedFraction
method replaces the now-deprecatedgetVideoBytesLoaded
andgetVideoBytesTotal
methods. The new method returns the percentage of the video that the player shows as buffered.The
onError
event may now return an error code of5
, which indicates that the requested content cannot be played in an HTML5 player or another error related to the HTML5 player has occurred.The Requirements section has been updated to indicate that any web page using the IFrame API must also implement the
onYouTubeIframeAPIReady
function. Previously, the section indicated that the required function was namedonYouTubePlayerAPIReady
. Code samples throughout the document have also been updated to use the new name.Note: To ensure that this change does not break existing implementations, both names will work. If, for some reason, your page has an
onYouTubeIframeAPIReady
function and anonYouTubePlayerAPIReady
function, both functions will be called, and theonYouTubeIframeAPIReady
function will be called first.The code sample in the Getting started section has been updated to reflect that the URL for the IFrame Player API code has changed to
http://www.youtube.com/iframe_api
. To ensure that this change does not affect existing implementations, the old URL (http://www.youtube.com/player_api
) will continue to work.July 16, 2012
This update contains the following changes:
The Operations section now explains that the API supports the
setSize()
anddestroy()
methods. ThesetSize()
method sets the size in pixels of the<iframe>
that contains the player and thedestroy()
method removes the<iframe>
.June 6, 2012
This update contains the following changes:
We have removed the
experimental
status from the IFrame Player API.The Loading a video player section has been updated to point out that when inserting the
<iframe>
element that will contain the YouTube player, the IFrame API replaces the element specified in the constructor for the YouTube player. This documentation change does not reflect a change in the API and is intended solely to clarify existing behavior.In addition, that section now notes that the insertion of the
<iframe>
element could affect the layout of your page if the element being replaced has a different display style than the inserted<iframe>
element. By default, an<iframe>
displays as aninline-block
element.March 30, 2012
This update contains the following changes:
The Operations section has been updated to explain that the IFrame API supports a new method,
getIframe()
, which returns the DOM node for the IFrame embed.March 26, 2012
This update contains the following changes:
The Requirements section has been updated to note the minimum player size.
... <看更多>
相關內容