Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //closing the popup
- var video_watched_count = 0;
- $(document).ready(function () {
- $(".closeBtn").click(function () {
- if (typeof player.stopVideo !== "undefined")
- player.stopVideo();
- //refresh the video feed if the user watches more than one video
- if (video_watched_count > 0) {
- showloader();
- window.location = "http://www.snuckls.com/video/ticketdetails";
- }
- $(".dialog_box_wrap").hide();
- });
- });
- var emoji_base_url = "https://s3-us-west-1.amazonaws.com/baymack/unicodeexpressions/large/";
- //function to get the perticuklar video details
- $('.videos-select').click(function (e) {
- e.preventDefault();
- //get the video index data
- var video_index = $(this).attr('video-index');
- video_session_index = video_index;
- load_video_by_index(video_index);
- });
- function load_video_by_index(video_index)
- {
- video_session_index = video_index;
- var options = {};
- $("#video_list").hide( );
- $("#video_details").hide( "drop", {direction: "left"}, 100 );
- $("#video_details").show( "drop", {direction: "top"}, 500 );
- //$( "#video_details" ).effect( 'drop', options, 500 );
- //alert(video_index);
- showloader();
- $.ajax({
- url: "http://www.snuckls.com/video/getthevideoindexdata/" + video_index,
- dataType: "JSON",
- success: function (response) {
- if (response.response == 'success') {
- //hide the divs
- $('#emojis').hide();
- $('#play-load-bar').show();
- $('#video_response_id').hide();
- $('.video-width').width($("#intImage").width());
- $('.video-width').height($("#intImage").height());
- $("#intImage").hide();
- //console.log(response.data);
- //console.log(player);
- video_id = response.data.videoId;
- $('#channel_image').attr('src', response.data.channelThumbUrl);
- $('#channel_description').html(response.data.description.substring(0, 25) + '....');
- $('#videoTitle').html(response.data.videoTitle.substring(0, 25) + '....');
- $('#channel_upload_date').html(response.data.uploadTime);
- $('#share_video').attr('href', 'https://www.facebook.com/dialog/feed?app_id=485175661693050&description=Check+this+awesome+video&e2e=%7B%7D&link=https://www.youtube.com/watch?v=' + response.data.videoId + '&locale=en_US&name=&next=http%3A%2F%2Fstaticxx.facebook.com%2Fconnect%2Fxd_arbiter%2Fr%2FP5DLcu0KGJB.js%3Fversion%3D42%23cb%3Df1cf7ac9d58984%26domain%3Dsnuckls.com%26origin%3Dhttp%253A%252F%252Fsnuckls.com%252Ff50881fd46c3c4%26relation%3Dopener%26frame%3Df1cad30e02a5bf4%26result%3D%2522xxRESULTTOKENxx%2522&sdk=joey&version=v2.7&_rdr"');
- if (typeof player.loadVideoById === "undefined")
- $('#video_player').attr('src', 'https://www.youtube.com/embed/' + response.data.videoId + '?enablejsapi=1&autoplay=false&controls=0&rel=0&showinfo=0&egm=0&showsearch=0&modestbranding=1&iv_load_policy=3&disablekb=1&loop=0&start=0');
- else
- player.loadVideoById(response.data.videoId, 0);
- callPlayer('video_player', 'stopVideo');
- $('#video_emoji_title').html(response.data.emojiTitle);
- //render the emojis
- // var emoji_html='';
- // response.data.emojiIds.forEach(function(entry) {
- //console.log(entry);
- var emoji_html = '<li><a href="javascript:" class="border-btn emojiclick" emojiid="' + 1 + '">Rock</a></li>'+'<li><a href="javascript:" class="border-btn emojiclick" emojiid="' + 2 + '">Pop</a></li>'+'<li><a href="javascript:" class="border-btn emojiclick" emojiid="' + 3 + '">Hip Hop</a></li>'+'<li><a href="javascript:" class="border-btn emojiclick" emojiid="' + 4 + '">Other</a></li>';
- // });
- //console.log(emoji_html);
- $("#video_guess_emoji").html(emoji_html);
- //rendering the emoji ends here
- //initialize the progressbar properties starts
- reset_values();
- var video_range = 0;
- var video_duration = Number(response.data.duration);
- var video_lowerLimit = Number(response.data.lowerLimit);
- var video_upperLimit = Number(response.data.upperLimit);
- if (video_duration <= video_lowerLimit)
- video_range = video_duration - 2;
- else if (video_duration <= response.data.upperLimit)
- video_range = randomIntFromInterval(video_lowerLimit, (video_duration - 2));
- else
- video_range = randomIntFromInterval(video_lowerLimit, video_upperLimit);
- range = video_range;
- $('#range').html(video_range);
- $('#progress-value').html('0/' + video_range);
- setBarWidth(".style-1 span", ".style-1 em", "width", 0);
- //ending the video properties
- closeloader();
- }
- else
- closeloader();
- },
- error: function (response) {
- //closeloader();
- }
- });
- $(".dialog_box_wrap").show();
- }
- //initilizing the youtube player and the youtube related functions
- var timer_error = 1;
- var currenttime = 0;
- var video_id = '';
- var timeout;
- var systemduration_timeout;
- var systemduration_timer = 0;
- var emoji_shown = 0;
- var range = 0;
- var video_session_index = 0;
- var user_watched_time = 0;
- // 2. This code loads the IFrame Player API code asynchronously.
- var tag = document.createElement('script');
- tag.src = "https://www.youtube.com/iframe_api";
- var firstScriptTag = document.getElementsByTagName('script')[0];
- firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
- // 3. This function creates an <iframe> (and YouTube player)
- // after the API code downloads.
- var player;
- window.onYouTubeIframeAPIReady = function () {
- console.log('onYouTubeIframeAPIReady');
- player = new YT.Player('video_player', {
- // playerVars: { 'enablejsapi':1,'autoplay':0,'controls':0,'rel':0,'showinfo':0,'egm':0,'showsearch':0,'modestbranding':1,'iv_load_policy':3,'disablekb':0,'loop':0},
- events: {
- 'onReady': onPlayerReady,
- 'onStateChange': onPlayerStateChange,
- 'onError': onPlayerError
- }
- });
- setTimeout(systemduration, 1000);
- }
- // 4. The API will call this function when the video player is ready.
- function onPlayerReady(event) {
- // console.log('player ready event'+event);
- // event.target.pauseVideo();
- //console.log('player ready');
- clearTimeout(timeout);
- clearTimeout(systemduration_timeout);
- currenttime = 0;
- systemduration_timer = 0;
- }
- // 5. The API calls this function when the player's state changes.
- // The function indicates that when playing a video (state=1),
- // the player should play for six seconds and then stop.
- var done = false;
- function onPlayerStateChange(event) {
- //console.log(Math.floor(player.getCurrentTime()));
- //console.log(player.getDuration()-1);
- console.log('playser state change');
- console.log(event);
- if (event.data == 1) {
- currenttime = Math.floor(player.getCurrentTime());
- timeout = setTimeout(timer, 1000);
- }
- else {
- console.log('paused');
- clearTimeout(timeout);
- }
- }
- function timer() {
- currenttime = currenttime + 1;
- if(currenttime<5) timer_error= 0;
- else{
- if(timer_error==1){
- // console.log("timer error sending to ga "+video_id +" "+ currenttime);
- ga('send', {
- hitType: 'event',
- eventCategory: 'Timer',
- eventAction: 'stopped-desktop',
- eventLabel: video_id,
- eventValue : currenttime
- });
- timer_error=0;
- }
- }
- console.log(currenttime);
- //console.log(Math.floor(((currenttime/(player.getDuration()-1))*100)));
- //change the timer value
- if (currenttime <= range)
- $('#progress-value').html(currenttime + '/' + range);
- //display the emojis if the range of the video matches
- if (currenttime == range || currenttime == (player.getDuration() - 1)) {
- //enable the controls
- //show the emojis
- if (emoji_shown == 0) {
- console.log('show emoji');
- $('#play-load-bar').hide();
- $('#emojis').show();
- emoji_shown = 1;
- }
- }
- //calculate the percentage for progrss bar
- var completeperc = Math.ceil(((currenttime / range) * 100));
- //console.log('perc:'+completeperc);
- if (completeperc <= 100)
- setBarWidth(".style-1 span", ".style-1 em", "width", completeperc);
- timeout = setTimeout(timer, 1000);
- }
- function onPlayerError(event) {
- console.log(event);
- skip_video_a(0);
- window.location = "http://www.snuckls.com/video/ticketdetails";
- //console.log('jadfa');
- }
- function stopVideo() {
- player.stopVideo();
- }
- //functio to record the system durtion
- function systemduration() {
- systemduration_timer = systemduration_timer + 1;
- //console.log(systemduration_timer);
- systemduration_timeout = setTimeout(systemduration, 1000);
- }
- //after clickng on emojis
- $('body').on('click', 'a.emojiclick', function (e) {
- //$('.emojiclick').click(function(e){
- e.preventDefault();
- //clearTimeout(systemduration_timeout);
- var emojiid = $(this).attr('emojiid');
- user_watched_time = Math.floor(player.getCurrentTime());
- var total_video_duration = Math.floor(player.getDuration());
- var progress_value = range;
- if (systemduration_timer < user_watched_time)
- systemduration_timer = user_watched_time + 3;
- $('#emojis').hide();
- $('#emojiSendning').show();
- //console.log(emojiid+'/'+user_watched_time+'/'+total_video_duration+'/'+progress_value+'/'+systemduration_timer+'/'+video_session_index);
- //alert(emojiid);
- //send the data to
- $.ajax({
- url: "http://www.snuckls.com/video/videofeedback",
- type: 'POST',
- dataType: 'json',
- data: {
- emojiid: emojiid,
- user_watched_time: user_watched_time,
- total_video_duration: total_video_duration,
- progress_value: progress_value,
- systemduration_timer: systemduration_timer,
- video_session_index: video_session_index
- },
- success: function (response) {
- $('#emojis').hide();
- $('#emojiSendning').hide();
- video_watched_count = video_watched_count + 1;
- if (response.response == "fail") {
- //ShowDialogBox('Video Feedback Error', 'Something went wrong', 'OK', '', '', '');
- $('#emojis').show();
- }
- else {
- if (response.direct_redirect == 1)
- window.location = response.next_video_url;
- else {
- $('#footer_id').show();
- $('#footer_url').attr('href', response.next_video_url);
- var next_video_url_array = response.next_video_url.split('/');
- $('#nextvideo').attr('video-index', next_video_url_array[next_video_url_array.length - 1]);
- if (response.response_ep.hasOwnProperty("feedbackMsg")) {
- $('#video_response_id').show();
- var pattern = /wrong/;
- if (pattern.test(response.response_ep.feedbackMsg))
- $('#video_response_h2').css('color', 'red');
- $('#video_response_h2').html(response.response_ep.feedbackMsg);
- $('#notification-txt').html(response.response_ep.feedbackSubMsg);
- $("#video_response_ul").html('');
- response.response_ep.progressList.forEach(function (entry) {
- var cssclass = '';
- if (entry == 1)
- cssclass = "selected";
- if (entry == 0)
- cssclass = "";
- $("#video_response_ul").append('<li class="' + cssclass + '"></li>');
- });
- }
- //if(response.response_ep.)
- }
- }
- },
- error: function (response) {
- $('#emojis').show();
- }
- });
- });
- $(".more-btn").on('click', function () {
- //console.log($(".more-options"));
- $(".more-options").toggle();
- });
- ///functio to skip the video
- $('#skipvideo_a').click(function (e) {
- e.preventDefault();
- skip_video_a(1);
- window.location = "http://www.snuckls.com/video/ticketdetails";
- });
- //function to skip the video
- function skip_video_a() {
- $.ajax({
- url: "http://www.snuckls.com/video/skipvideo",
- type: 'POST',
- dataType: 'json',
- data: {video_session_index: video_session_index, flag: flag},
- success: function (response) {
- console.log(response);
- },
- error: function (response) {
- }
- });
- }
- //function to set the all initial values to zero
- function reset_values() {
- currenttime = 0;
- timeout;
- systemduration_timeout;
- systemduration_timer = 0;
- emoji_shown = 0;
- range = 0;
- //video_session_index=0;
- user_watched_time = 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment