Reputation: 127
I am looking for a solution to load a video for viewing before entering a website. While viewing the video, there will be a simple registration form with two fields that if submitted will allow skipping the video.
I can check a SESSION variable and redirect to the video page from any page if it was not viewed... the problem is I need somehow to detect a End of Video event or something like that and then set a SESSION variable at the end of the video.
The site is based on Joomla and I can also use a custom PHP solution.
Upvotes: 0
Views: 2538
Reputation: 170
this is quite simple, yo do need to provide more information as to where is the source of your video?
im guessing youtube is the way to go, so here are your instructions, which i recommend trying something before asking, because you posted homework here, and not a problem!
you just need to ping the service for the youtube API:
function onPlayerStateChange(evt) {
if (evt.data == 0){
alert (player.getDuration())
}
}
here you can set the session based on some rules, get more info on this api here https://developers.google.com/youtube/js_api_reference
if you are using your own html5 video with your own player
$('video#test-vid').bind("progress",function(e){
console.log(e.total + ' ' + e.loaded + ' ' + e.lengthComputable );
});
after this a seesion will be true for the particular user instance and you can then let people see the rest of the content.
you can try to store the ip of the user who seen the video before so you wont show it again..
as for the seession well is quite easy and hard to explain here:
basically before setting sessions make sure you have
session_start(); // before thinking of ending or setting sessions
$_SESSION['seen_video'] = $result;
Upvotes: 0
Reputation: 3464
If you are using youtube to show video, you can use youtube api to achieve that.
<div id="player"></div>
<script src="http://www.youtube.com/player_api"></script>
<script>
// create youtube player
var player;
function onYouTubePlayerAPIReady() {
player = new YT.Player('player', {
height: '390',
width: '640',
videoId: '0Bmhjf0rKe8',
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
}
});
}
// autoplay video
function onPlayerReady(event) {
event.target.playVideo();
}
// when video ends
function onPlayerStateChange(event) {
if(event.data === 0) {
alert('done');
}
}
</script>
After event.data === 0
you can tell that video is finished and could redirect back to your page or whatewer.
Upvotes: 1
Reputation: 21
check this out please...
Detect when an HTML5 video finishes
You just need to put a window.location = 'http://seusite.com';
in the END event ..
Upvotes: 0