|
|
|
@ -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 ); |
|
|
|
|