Insert add video before main video with YouTube API - javascript

I have a page that displays YouTube videos using the YouTube API. For each video I have a specific 30 second add video that I would like to play before the main video. Is there a way to do this through the YouTube API or plain javascript/jquery?

All you need to do is embed the ad first, then when it's done playing, hide it and show the main video.
First, detect when the ad is done playing with the Youtube API player.getPlayerState() function. This returns a zero when the video is ended.
Then, hide the embed with Javascript and show the main video.

Related

How to create a clickable timestamp link on an embedded youtube video with javascript?

I would really like to have clickable time links on my website that will jump to specific times within my embedded youtube video. I know that this is possible within youtube itself (built in function on youtube where you just put the time you want in the format (0:00) and users can click it to jump to that point).
I was wondering if it is possible to mimic this function somehow with embedded youtube videos and javascript?
You can use the Youtube iFrame API. There is a function to get the current timestamp:
player.getCurrentTime():Number
Returns the elapsed time in seconds since the video started playing.
player.getDuration():Number
Returns the duration in seconds of the currently playing video. Note
that getDuration() will return 0 until the video's metadata is loaded,
which normally happens just after the video starts playing.
Use them like so:
ytplayer = document.getElementById("youtube_player");
ytplayer.getCurrentTime();

Add my Youtube playlist on my website

I add videos to my site via the JavaScript YouTube API. It works well except that at the end of the video playback, there are several video choices that appear on my screen. I want to choose the video or videos that appear at the end of my video.
How can I do this?

Embedded youtube video restarts on resize

I have a Youtube video embedded on my site, and when the iframe that it is embedded in gets resized, the Youtube video restarts. Is this the expected behaviour? Is there any way around it? I have been trying to get the Youtube JS API working to no success, so I would prefer to not use it.
Any ideas?
How about you get the minute/second the video is at the moment of the resize so you reload it but with an auto starts on the same minute/second?
For example if you add this at the end of a youtube url it starts at minute 1 and 8 seconds:
#t=1m08s

Embedded youtube clicps - play next?

I have few youtube clips embedded on page. Is it possible to play second clip after first finishes?

Skip video in YouTube playlist using JavaScript

I've looked through the YouTube JS API, but can't find a way to jump to a video in a playlist. (Mimicking the built-in navigation)
And if you're wondering why I'd want both, it's because I have a menu set up with additional information, and want to let the user click these links to jump between the videos.
You can write your own YouTube player script or use this one -- YouTube JavaScript API Player plus Playlist.

Categories

Resources