function getTime() { return new Date().getTime(); } var poll_failed = 0; var poll_url = "/api/v1/videos/73z9w0yn/status.json"; var poll_start_time = getTime(); var poll_start_queue = null; var video_duration = "478.31"; var video_source = "https://videos2.sendvid.com/42/63/73z9w0yn.mp4?validfrom=1716825723&validto=1716840123&rate=160k&ip=91.90.42.154&hash=LFeRZ6Mq0FT1%2BpSiVlkankwOpM8%3D"; var video_poster = "https://thumbs2.sendvid.com/42/63/73z9w0yn.jpg"; var video_container_padding = "60%"; var video_poster_ready = false; var video_storyboard = "https://thumbs2.sendvid.com/42/63/73z9w0yn-storyboard.jpg"; var video_storyboard_interval = 23; var video_storyboard_width = 95; var video_storyboard_height = 200; function poll() { $.ajax({ url: poll_url, type: "GET", success: function (data) { console.log(data); poll_failed = 0; process_poll(data); }, error: function (jqXHR, textStatus, errorThrown) { poll_failed++; if (poll_failed < 5) { setTimeout(function () { poll() }, 1200 * poll_failed); } else { console.log("giving up.."); } }, dataType: "json", timeout: 2000 }); }; function setPosterReady(v) { if (video_poster_ready == false && v == true) { $('#image-bg').attr("src", video_poster); } video_poster_ready = v; } function process_poll(data) { switch (data.state) { case "preparing": setTimeout(function () { poll() }, 1200); break; case "failed": $('#processing_state_text').text("could not be processed."); break; case "waiting": if (poll_start_queue == null) poll_start_queue = data.place_in_queue; $('#processing_state_text').text("is queued for conversion (" + data.place_in_queue + ")"); setTimeout(function () { poll() }, 1200); break; case "encoding": $('.cubespinner').hide(); $('.showprocess-encoding').show(); $('#processing_state_text').text("is being converted"); $('#processing_conversion_percent').css("width", data.progress + "%"); setTimeout(function () { poll() }, 1200); break; case "transferring": $('#processing_conversion_percent').css("width", "100%"); $('#processing_state_text').text("is being prepared for playback"); setTimeout(function () { poll() }, 1200); break; case "done": video_container_padding = data.padding_ratio + "%"; video_duration = data.duration; video_storyboard_interval = data.storyboard_interval; video_storyboard_width = data.storyboard_resolution.width; video_storyboard_height = data.storyboard_resolution.height; $('#processing_state_text').text("is being prepared for done!"); $('.showprocess').removeClass("showprocess"); $('#video_source').attr("src", video_source); $('#video-js-video').attr("poster", video_poster); $('#image-bg').attr("src", video_poster); initPlayer(); break; } setPosterReady(data.thumb); } var video; var videojsoptions = { "nativeControlsForTouch": false, "autoplay": false, html5: { vhs: { withCredentials: false, overrideNative: true }, nativeAudioTracks: false, nativeVideoTracks: false }, controlBar: { children: [ "fullscreenToggle", "playToggle", "volumePanel", "durationDisplay", "timeDivider", "currentTimeDisplay", "progressControl", "remainingTimeDisplay", ] }, "plugins": { "share": { "embedUrl": "//sendvid.com/embed/73z9w0yn", "shareUrl": "https://sendvid.com/73z9w0yn", "shareOverlayTitle": "sendvid", "reportUrl": "//sendvid.com/report?id=73z9w0yn" }, "VolumeRestore": {"key": "nil"}, "thumbnailsSprite": { "image": video_storyboard, "duration": video_duration, "interval": video_storyboard_interval, "frameWidth": video_storyboard_width, "frameHeight": video_storyboard_height }, } }; function reinitPlayer() { video = videojs('video-js-video', videojsoptions); } function initPlayer() { //$('#video-page-bg').css("background-image","url('"+video_poster+"')"); $('#video-js-video').attr("poster", video_poster); //$('#video_container').css("padding-top",video_container_padding); var isVast = false; var hasRestarted = false; video = videojs('video-js-video', videojsoptions).ready(function () { var player = this; player.on('ended', function () { if (isVast && isVast.isEnabled()) { video.vastClient(); isVast.disable(); if (!hasRestarted) { jQuery('.vjs-replay-button.vjs-control').click(); hasRestarted = true; } isVast = false; } }); player.on('volumechange', () => { if (window.localStorage) { window.localStorage.setItem('volume', player.muted() ? 0 : player.volume()) } }) }); var setCookie = function (name, value, hours) { var expires = ""; if (hours) { var date = new Date(); date.setTime(date.getTime() + (hours * 60 * 60 * 1000)); expires = "; expires=" + date.toUTCString(); } document.cookie = name + "=" + (value || "") + expires + "; path=/"; }; var getCookie = function (name) { var nameEQ = name + "="; var ca = document.cookie.split(';'); for (var i = 0; i < ca.length; i++) { var c = ca[i]; while (c.charAt(0) == ' ') c = c.substring(1, c.length); if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length); } return null; }; // } // } } //$(document).ready(function(e){ // moved to layout //});