youtube-javascript-api

How to catch Youtube player's dragging/skipping/forwarding event with API in javascript

穿精又带淫゛_ 提交于 2019-12-06 04:28:01
I'm looking at the documentation for onStateChange, but I don't find anything the even when user will be dragging the player timer left or right. In fact, onStateChange doesn't catch anything when I do that. This is from the documentation: https://developers.google.com/youtube/iframe_api_reference 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)f 5

Using YouTube's PlayerAPI inside of a Google Chrome Extension under Manifest V2 — works, but generating lots of warnings

佐手、 提交于 2019-12-06 03:49:35
问题 I am receiving a couple of non-critical error messages when using YouTube's Player API inside of a Google Chrome Extension under v2. I have the following definitions in my content_security_policy: "content_security_policy": "script-src 'self' https://www.youtube.com/player_api https://s.ytimg.com/yt/jsbin/www-widgetapi-vfl9Ni0ki.js; object-src 'self'" The first reference, player_api, has a dependency on the widgetapi. This is clear if you navigate to the player_api url and look at its

Use YoutubeAPI to play youtube video until a particular time and pause

戏子无情 提交于 2019-12-06 03:20:50
问题 Is there a way to use the Youtube API to play a video until a certain point in the video and then pause it? 回答1: I've modified the code from the YouTube Player API Reference for iframe Embeds to pause play after a certain number of seconds. Demo The code works by waiting for the onPlayerStateChange event. When the event fires, it checks the event to see if it's a PLAYING event. If it is, it calculates the remaining time from the current time ( getCurrentTime() method) to the desired pause

YouTube IFrame API doesn't always load?

北战南征 提交于 2019-12-06 03:15:13
I've seen lots of similar questions to this, but I believe this is different. When I try to define onYouTubeIframeAPIReady in the global scope, the function only gets called about half the times I load the page (if I keep refreshing, sometimes I'll see the console message, and sometimes it isn't there). It's confusing to me that this only happens sometimes, and I don't call onYouTubeIframeAPIReady anywhere else in my code. Problem areas I've checked: I'm running it on Github Pages (so it's not local) The function is defined in the global scope My code is below: window.onYouTubeIframeAPIReady =

Dynamically change the video id on youtube

六眼飞鱼酱① 提交于 2019-12-06 02:20:48
I am trying to display youtube audio without video with the below code so I am changing the video id but it is playing the same id again and again. <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>About</title> <script type="text/javascript"> function val1(val) { document.getElementsByTagName("div")[0].setAttribute("data-video", val); alert(val); } </script> </head> <body onload="val1('WKV_z36pVAk')"> <h3 style="color:#0066dd">Hello</h3> <center> <div data-video="8IYzyTYucKQ" data-autoplay="0" data-loop="1" id="youtube-audio"> </div> </center> <button>change</button> </body>

Retrieve player state with multiple youtube players on a page

醉酒当歌 提交于 2019-12-06 00:12:56
I hava a single HTML with many youtube players. I'm suscribing to the onStateChange to get notified when the user plays a video. function onYouTubePlayerReady(playerid) { var player = document.getElementById("playerA"); player.addEventListener("onStateChange", "callback"); } Now the callback get the newState as parameter. function callback(newState) { ... } This works ok with only one player. But with many players, how can I know wich player raised the StateChange event? Callback just have one parameter. Is there a way to know which player raised the event form callback or i have to set uo a

How to get a thumbnail or snapshot of a youtube video at a specific “second” with Youtube javascript API?

微笑、不失礼 提交于 2019-12-05 15:56:09
问题 I want to take a thumbnail image of a youtube video, let's say http://www.youtube.com/watch?v=ffaTjpA1scI at 30s or 120s. How can I do that with youtube API? I do think this is possible, because when I watch a Youtube video, if I move my cursor to the timeline, I can immediately see snapshots at specific time. I just want to retrieve these snapshots programmatically. I also tried http://img.youtube.com/vi//0.jpg, actually this can get the thumbnail of course, but it cannot get a snapshots at

How to get a youtube playlist thumbnail?

馋奶兔 提交于 2019-12-05 03:59:42
Is there a way to get youtube playlist thumbnail like how you can get a thumbnail of a video, explained here: How do I get a YouTube video thumbnail from the YouTube API? With the YouTube API v3, you can get the playlist thumbnail using their v3/playlists endpoint and drilling down to items.snippet.thumbnails.high.url For the following playlist: https://www.youtube.com/playlist?list=PL50C17441DA8A565D YouTube's API explorer has a playlist endpoint: https://developers.google.com/youtube/v3/docs/playlists/list This is the API call: GET https://www.googleapis.com/youtube/v3/playlists?part=snippet

Fetching YouTube video title from known video id

走远了吗. 提交于 2019-12-05 00:38:25
问题 I want to fetch a YouTube video title when the video id is known, using JavaScript only. Is it possible? 回答1: Yes, it is possible using Javascript and JSON. https://developers.google.com/youtube/2.0/developers_guide_protocol_video_entries See: https://developers.google.com/youtube/2.0/developers_guide_json So you do it like this: <script type="text/javascript" src="https://gdata.youtube.com/feeds/api/videos/videoid?v=2&alt=json-in-script&format=5&callback=getTitle"> </script> And then:

How to convert YouTube API duration (ISO 8601 duration in the format PT#M#S) to seconds

我与影子孤独终老i 提交于 2019-12-04 23:48:28
How can I manipulate a date time in the format PT#M#S with JavaScript? for example: PT5M33S I'd like to output as hh:mm:ss . Here's the basic code to get total number of seconds and other parts. I feel uneasy doing this, as the rule says that any time you want to date logic you shouldn't :) But anyways, here it goes - Google made it not easy, providing total seconds in the getduration player API, and providing totally different format in the gdata api. var reptms = /^PT(?:(\d+)H)?(?:(\d+)M)?(?:(\d+)S)?$/; var hours = 0, minutes = 0, seconds = 0, totalseconds; if (reptms.test(input)) { var