Do you know when the YouTube video ends in the Player?
A thumbnail of videos is displayed to watch. These are the recommended videos for you according to what you've been watching.
But how can you leave only those videos on a certain channel using the YouTube API in Javascript?
I'm looking at the documentation, but for now I have not found anything.
In this code below I could almost do what I need.
I added two parameters in playerVars
:
listType
- here I define a value in the parameter: user_uploads
, playlist
or search
. In this case I selected playlist
, since I want you to show the videos of the playlist that I created on Youtube. This parameter is COMBINED with the parameter below, list
.
list
- I created a playlist on the channel with all the videos and put his URL in the value of the parameter, as the documentation says.
function onYouTubePlayerAPIReady(){
player = new YT.Player('video-estoria-animada', {
videoId: document.getElementById('video-id').value,
playerVars: {
modestbranding: 1,
version: 3,
controls: 2,
wmode: 'opaque',
theme: 'light',
rel: 1,
showinfo: 1,
html5: 1,
listType: 'playlist',
list: "PLA8fGhdnBVrGSjEYeCPozWTXGhRX2rdJ7",
},
events: {
'onReady' : onPlayerReady,
'onStateChange': onPlayerStateChange
}
});
});
OBJECTIVE
I want the user to persist in watching the channel videos and not other videos. Myself, sometimes I'm watching a video of a channel, then the video ends and shows the related videos and I click on another channel that has nothing to do with the initial theme. That is, the user shifts the focus and leaves the site.
So when I finish the video, I want it to show the videos of the same channel that it is watching, so you can continue to watch the videos of it.
I said I almost got why when the video ends, it automatically jumps to the next one in the list instead of displaying the related videos in the playlist.