diff --git a/lib/javascript/clipchamp/player.js b/lib/javascript/clipchamp/player.js index 94144a3..0cc2362 100644 --- a/lib/javascript/clipchamp/player.js +++ b/lib/javascript/clipchamp/player.js @@ -1,4 +1,4 @@ -/*! +/* * jQuery Clipchamp MJPEG Player Plugin v0.0.1 * https://github.com/clipchamp/jquery-clipchamp-mjpeg-player-plugin * @@ -15,10 +15,33 @@ (function($) { var DEFAULT_FPS = 15, DEFAULT_AUTOLOOP = true, - JPEG_MAGIG_NUMBER = [0xff, 0xd8, 0xff]; + JPEG_MAGIG_NUMBER = [0xff, 0xd8, 0xff], CONTINUE_PLAY = true, imageElement = null, nextFrameIndex = 0, jpegUrl, jpegFiles = null, autoloop = false, fps =1, ran=null; var requestAnimationFrame = window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.msRequestAnimationFrame || window.setTimeout; + function showNextFrame() { + if (imageElement) { + if (jpegUrl) { + URL.revokeObjectURL(jpegUrl); + } + jpegUrl = URL.createObjectURL(jpegFiles[nextFrameIndex++]); + imageElement.onload = function() { + + if (imageElement) { + if (autoloop || nextFrameIndex < jpegFiles.length) { + nextFrameIndex = (nextFrameIndex === jpegFiles.length) ? 0 : nextFrameIndex; + ran.value = nextFrameIndex; + + if( CONTINUE_PLAY ) + setTimeout(function() { + requestAnimationFrame(showNextFrame); + }, 1000/fps); + } + } + }; + imageElement.setAttribute('src', jpegUrl); + }; + }; function splitMJPEG(mjpegUrl, callback) { var xhr = new XMLHttpRequest(); @@ -46,49 +69,64 @@ xhr.send(); }; - function playMJPEGInternal(wrapperElement, mjpegUrl, fps, autoloop) { - fps = (typeof fps === 'number') ? fps : DEFAULT_FPS; - autoloop = (typeof autoloop === 'boolean') ? autoloop : DEFAULT_AUTOLOOP; - - var playbackFinished = false, - imageElement = document.createElement('img'), - jpegUrl; - - imageElement.setAttribute('style', 'width:100%;'); - wrapperElement.appendChild(imageElement); + function playMJPEGInternal(wrapperElement, mjpegUrl, fp, aloop) { + fps = (typeof fp === 'number') ? fp : DEFAULT_FPS; + autoloop = (typeof aloop === 'boolean') ? aloop : DEFAULT_AUTOLOOP; + + var playbackFinished = false; + imageElement = document.createElement('img'); + var dWE = document.createElement('div'); + dWE.setAttribute( 'id', 'wrpo_'+wrapperElement.id ); + var W = wrapperElement.clientWidth; + var H = ( W / 16 ) * 9; + dWE.setAttribute( 'style', "display: block; width: 100%; height: "+H+"px; background-color: #000; background-image:url('/style/assets/loading_red_cube.gif');background-position: center;background-repeat: no-repeat;" ); + dWE.appendChild(imageElement); + imageElement.setAttribute('style', "width:100%;"); + wrapperElement.appendChild( dWE ); + //alert('SLADKIY_BUBALEKH:'+ W + " " + H ); //Show SLADKIY_BUBALEKH - splitMJPEG(mjpegUrl, function(jpegFiles) { + splitMJPEG(mjpegUrl, function( Files ) { + jpegFiles = Files; //Hide SLADKIY_BUBALEKH -> or error! - alert( jpegFiles.length ); - if (jpegFiles.length > 0) { - var nextFrameIndex = 0; - - function showNextFrame() { - if (imageElement) { - if (jpegUrl) { - URL.revokeObjectURL(jpegUrl); - } - jpegUrl = URL.createObjectURL(jpegFiles[nextFrameIndex++]); - - imageElement.onload = function() { - - if (imageElement) { - if (autoloop || nextFrameIndex < jpegFiles.length) { - nextFrameIndex = (nextFrameIndex === jpegFiles.length) ? 0 : nextFrameIndex; - setTimeout(function() { - requestAnimationFrame(showNextFrame); - }, 1000/fps); - } - } - }; - imageElement.setAttribute('src', jpegUrl); - }; - }; - - setTimeout(function() { + //alert( jpegFiles.length ); + var ctlDIV = document.createElement('div'); + ctlDIV.setAttribute( 'id', 'ctl_'+wrapperElement.id ); + ctlDIV.setAttribute( 'class', 'player_controls' ); + var btn = document.createElement('div'); + btn.setAttribute( 'id', 'btn_play_stop'+wrapperElement.id ); + btn.setAttribute( 'onclick', "stop_mjpeg('btn_play_stop"+wrapperElement.id+"');" ); + btn.classList.add('pl_ctl_btn'); + btn.classList.add('stop_button'); + ctlDIV.appendChild(btn); + + ran = document.createElement('input'); + ran.setAttribute( 'type', "range" ); + ran.setAttribute( 'id', 'range_'+wrapperElement.id ); + ran.setAttribute( 'step','1'); + ran.setAttribute( 'min','0'); + ran.setAttribute( 'max', jpegFiles.length ); + ran.setAttribute( 'value','0'); + ran.setAttribute( 'style','margin-left: 10px;width: 80%;' ); + ran.setAttribute( 'oninput', "setpos_mjpeg(this.value);" ); + ran.setAttribute( 'onchange', "setpos_s_mjpeg(this.value);" ); + ctlDIV.appendChild(ran); + + btn = document.createElement('div'); + btn.setAttribute( 'id', 'btn_loop'+wrapperElement.id ); + btn.setAttribute( 'onclick', "stop_loop_mjpeg('btn_loop"+wrapperElement.id+"');" ); + btn.classList.add('pl_ctl_btn'); + btn.classList.add('loop'); + ctlDIV.appendChild(btn); + dWE.appendChild(ctlDIV); + if (jpegFiles.length > 0) { + + + if( CONTINUE_PLAY ) setTimeout(function() { requestAnimationFrame(showNextFrame); }, 1000/fps); - } + } else { + alert('Error Loading Video'); + }; }); return { @@ -100,11 +138,17 @@ } }, pause: function(){ + CONTINUE_PLAY = false; }, play: function( fromBegin ){ - }, - stop: function(){ - pause(); + if(typeof fromBegin === 'number') { + nextFrameIndex = fromBegin; + nextFrameIndex = (nextFrameIndex === jpegFiles.length) ? 0 : nextFrameIndex; + }; + CONTINUE_PLAY = true; + setTimeout(function() { + requestAnimationFrame( showNextFrame); + }, 1000/fps); }, alertInfo: function(){ alert( jpegFiles.length ); diff --git a/lib/javascript/jsapi_dynamic/mojo_reports.js b/lib/javascript/jsapi_dynamic/mojo_reports.js index 04fecc2..95b1cbb 100644 --- a/lib/javascript/jsapi_dynamic/mojo_reports.js +++ b/lib/javascript/jsapi_dynamic/mojo_reports.js @@ -603,6 +603,39 @@ var VideoLinks = []; var VideoPlayer = null; var cEventTSS = 0; var cEventETS = 0; +function stop_mjpeg( a ){ + if( VideoPlayer != null ){ + var tt = document.getElementById( a ); + if( tt != undefined ){ + //tt.removeAttribute( 'onclick' ); + tt.classList.remove('stop_button'); + tt.classList.add('play_button'); + tt.setAttribute( 'onclick', "cont_mjpeg('"+a+"');" ); + }; + VideoPlayer.pause(); + }; +}; +function cont_mjpeg( a ){ + if( VideoPlayer != null ){ + var tt = document.getElementById( a ); + if( tt != undefined ){ + tt.classList.remove('play_button'); + tt.classList.add('stop_button'); + tt.setAttribute( 'onclick', "stop_mjpeg('"+a+"');" ); + }; + VideoPlayer.play(); + }; +}; +function setpos_mjpeg( v ){ + if( VideoPlayer != null ){ + VideoPlayer.play( v ); + }; +}; +function setpos_s_mjpeg( v ){ + if( VideoPlayer != null ){ + VideoPlayer.play( v ); + }; +}; function loadEventData( record ){ ReportSelectionMode = 3; // Just One Event cEventTSS = record.ts+record.ms/1000; @@ -639,7 +672,7 @@ function loadEventData( record ){ var tVL = '/lib/controller/data/reports/'+data.base+'/'+data.md5+'.'+data.ext; if( tVL != VideoLinks[data.node_id] ){ VideoLinks[data.node_id] = tVL; - alert( tVL ); + //alert( tVL ); switch( data.ext ){ case 'mp4':{ ctype = 'video/mp4'; @@ -664,7 +697,7 @@ function loadEventData( record ){ $( video_t ).clipchamp_mjpeg_player( VideoLinks[data.node_id] , fps, autoloop, function( wrapperElement, playerInterface ) { //playerInterface.finish(); - + VideoPlayer = playerInterface; $( wrapperElement ).dblclick(function(){ //playerInterface.finish(); fullScreen( wrapperElement.id ); diff --git a/style/assets/loading_red_cube.gif b/style/assets/loading_red_cube.gif new file mode 100644 index 0000000..fcad404 Binary files /dev/null and b/style/assets/loading_red_cube.gif differ diff --git a/style/assets/picons2.png b/style/assets/picons2.png new file mode 100644 index 0000000..30e9253 Binary files /dev/null and b/style/assets/picons2.png differ diff --git a/style/style.css b/style/style.css index 4770926..ad82a8e 100644 --- a/style/style.css +++ b/style/style.css @@ -1351,3 +1351,136 @@ A.CalendarDS:hover { background-position: 6px 4px; text-align: center; } +/********** Range Input Styles **********/ +/*Range Reset*/ +input[type="range"] { + accent-color: #ff9030; + cursor: pointer; + width: 10rem; +} + +/* Removes default focus */ +input[type="range"]:focus { + outline: none; +} + +/***** Chrome, Safari, Opera and Edge Chromium styles *****/ + +/* slider thumb */ +input[type="range"]::-webkit-slider-thumb { + -webkit-appearance: none; /* Override default look */ + appearance: none; + maargin-top: -12px; /* Centers thumb on the track */ + + /*custom styles*/ + background-color: #5cd5eb; + height: 2rem; + width: 1rem; +} + +input[type="range"]:focus::-webkit-slider-thumb { + border: 1px solid #3f4757; + outline: 3px solid #3f4757; + outline-offset: 0.125rem; +} + +/******** Firefox styles ********/ +/* slider track */ +input[type="range"]::-moz-range-track { + bzackground-color: #3f4757; + border-radius: 0.5rem; + height: 0.5rem; +} + +/* slider thumb */ +input[type="range"]::-moz-range-thumb { + border: none; /*Removes extra border that FF applies*/ + border-radius: 0; /*Removes default border-radius that FF applies*/ + + /*custom styles*/ + background-color: #3f4757; + height: 2rem; + width: 1rem; +} + +input[type="range"]:focus::-moz-range-thumb { + border: 1px solid #3f4757; + outline: 3px solid #3f4757; + outline-offset: 0.125rem; +} + +.player_controls{ + position: relative; + bottom: 29px; + width:100%; + padding:5px; + background: rgba( 255, 255, 255, 0.5 ); + box-sizing:border-box; + z-index: 1000; +} + +.pl_ctl_btn{ + display: inline-block; + height: 16px; + width: 16px; + cursor: pointer; + margin-top: 3px; + background-repeat: no-repeat; + background-size: 16px 160px; + border: solid 2px #3f4757; + border-radius: 2px; +} + +.pl_ctl_btn:hover{ + border: solid 2px #ffffff; +} + +.pl_ctl_btn.play_button{ + background-position: -2px -1px; + background-image: url( 'assets/picons2.png' ); +} +.pl_ctl_btn.play_button:hover{ + background-position: -2px -17px; + background-image: url( 'assets/picons2.png' ); +} +.pl_ctl_btn.stop_button{ + background-position: -2px -34px; + background-image: url( 'assets/picons2.png' ); +} +.pl_ctl_btn.stop_button:hover{ + background-position: -2px -50px; + background-image: url( 'assets/picons2.png' ); +} +.pl_ctl_btn.loop{ + float: right; + background-position: -2px -34px; + background-image: url( 'assets/picons2.png' ); +} +.pl_ctl_btn.loop:hover{ + background-position: -2px -50px; + background-image: url( 'assets/picons2.png' ); +} +.pl_ctl_btn.noloop{ + background-position: -2px -50px; + background-image: url( 'assets/picons2.png' ); +} +.pl_ctl_btn.noloop:hover{ + background-position: -2px -34px; + background-image: url( 'assets/picons2.png' ); +} + +.pl_ctl_btn.download_button{ + background-position: 0px -80px; + background-image: url( 'assets/picons2.png' ); +} +.pl_ctl_btn.download_button:hover{ + background-position: 0px -65px; + background-image: url( 'assets/picons2.png' ); +} +.pl_ctl_btn.fullscreen_button{ + background-position: 0px -111px; + background-image: url( 'assets/picons2.png' ); +} +.pl_ctl_btn.fullscreen_button:hover{ + background-position: 0px -96px; +}