I was able to solve using the google API, which shows the time if the user gives play, pause or if the video ends:
<script type="text/javascript" src="https://www.youtube.com/iframe_api"></script>
<script type="text/javascript">
var player;
function onYouTubeIframeAPIReady() {
player = new YT.Player( 'player', {
events: { 'onStateChange': onPlayerStateChange }
});
}
function onPlayerStateChange(event) {
switch(event.data) {
case 0:
alert('vídeo acabou');
break;
case 1:
alert('começou em '+player.getCurrentTime());
break;
case 2:
alert('pausado em '+player.getCurrentTime());
break;
}
}
</script>
And just pass the url inside an iframe:
<iframe id="player" src="https://www.youtube.com/embed/DjB1OvEYMhY?enablejsapi=1"></iframe>
Did you ever read in the API if that’s possible for her? If not for her, it’s hardly possible externally.
– user28595
Read through these Soen questions, they apparently answer your two questions. Is it possible to determine if a user finished to see an Embedded youtube video with the api? and Identify if user has Watched a video
– user28595
It will never be possible to determine if he watched the video. He can let the video run and go to the bakery to get a loaf of bread and on arrival close his website. Do not make any decision based on the player being watched as the person may not be in front of the screen.
– durtto
@durtto not necessarily if he "watched the video", but if he gave the play and ran the video to the end (even if he did go to the bakery during that run)
– Bia
Do you want to know if a human watched all the video from your site even not being in front of the pc?
– durtto
When it comes to Youtube API I usually use Javascript. In the API has a function called
onytplayerStateChange
. Thereturn
of that function always brings the status current video. If it is paused, if it is running or if it was finished being viewed, which in case would be the status0
. https://developers.google.com/youtube/js_api_reference#Subscribingevents– Diego Souza
This LINK https://developers.google.com/youtube/youtube_player_demo shows you the video parameters on the right. Note that when it is finished, you can skip to the end to see, it changes the
Player state
forended
, and if you see the report below, it shows that it is null, or0
.– Diego Souza