function onNewFrame(date) { var d = new Date(date);// Date.parse(date); var item = new Object(); item.fileName = ''; item.datetime = d; if (globalUpdateInfoHandler != null) { globalUpdateInfoHandler(item, 0, 0, 0); //playing... } } function onError(errorCode, msg) { console.log(errorCode + " -- " + msg); var d = new Date(); var item = new Object(); item.fileName = ''; item.datetime = d; if (globalUpdateInfoHandler != null) { globalUpdateInfoHandler(item, 0, 0, errorCode); //switch to use tranditional player... } } var globalUpdateInfoHandler = null; var ImgRealtimePlayer = function () { this.PlayDelay = 1000; //1s; var playTimerHandler = null; var isStopped = false; var elemImg = null, dataItems = [], updateInfoCallback = null, elemParent; var item = null, w, h; var playerID = "cameraImg"; var isFlashVer = true; this.player = this; /* Initialize the canvas elements and data source. */ this.Init = function (_elemParent, playSpeed, _updateInfoCallback) { elemParent = _elemParent; updateInfoCallback = _updateInfoCallback; globalUpdateInfoHandler = _updateInfoCallback; elemImg = $("
"); $(_elemParent).empty(); $(_elemParent).append(elemImg); updateInfoCallback = _updateInfoCallback; if (swfobject.getFlashPlayerVersion().major === 0) { var mjpegURL = "/api/Camera/MJpegStreaming.aspx?cameraID=" + parentID + ""; var imgLoaded = false; $(_elemParent).empty(); $(_elemParent).append($("")); $("#cameraImg").error(function (ex) { if (imgLoaded) { //if it's network problem, let's retry; $(this).attr("src", mjpegURL + "&t=" + (new Date()).getTime()); } else { $("#cameraImg").hide(); onError(5, "No live image found, switch to play history records."); } }); $("#cameraImg").load(function () { imgLoaded = true; if (updateInfoCallback != null) { var item = new Object(); item.fileName = ''; item.datetime = new Date(); updateInfoCallback(item, $(elemImg).height(), $(elemImg).width(), 0); //start playing... } }); isFlashVer = false; } else { // For version detection, set to min. required Flash Player version, or 0 (or 0.0.0), for no version detection. var swfVersionStr = "11.1.0"; // To use express install, set to playerProductInstall.swf, otherwise the empty string. var xiSwfUrlStr = "/ResellerWebsite/js/cameraplayer/playerProductInstall.swf"; var flashvars = {}; var params = {}; params.quality = "high"; params.bgcolor = "#333333"; //#333 params.allowscriptaccess = "always"; params.allowfullscreen = "true"; params.wmode = "transparent"; flashvars.host = window.location.host; flashvars.port = "80"; flashvars.appBgColor = "#333333"; var streamingURL = "http://" + flashvars.host + "/api/camera/MJpegStreaming.aspx?cameraID=" + parentID + "&shareID=" + shareID + "&sesID=" + sesID; var isWebkit = 'WebkitAppearance' in document.documentElement.style; if (isWebkit) streamingURL += "&from=FlashonWebkit"; flashvars.streamingURL = encodeURIComponent(streamingURL); var attributes = {}; attributes.id = playerID; attributes.name = playerID; attributes.align = "middle"; swfobject.embedSWF( "/ResellerWebsite/js/cameraplayer/MJpegPlayer.swf", "cameraImg", "640", "480", swfVersionStr, xiSwfUrlStr, flashvars, params, attributes); } if (updateInfoCallback != null) { var item = new Object(); item.fileName = ''; item.datetime = new Date(); updateInfoCallback(item, "Loading live data...", "", 4); //loading... } }; function getSWF(movieName) { return swfobject.getObjectById(movieName); // if (navigator.appName.indexOf("Microsoft") != -1) { // return document.getElementById(movieName); // } // else { // return document[movieName]; // } } /* Start to play. */ this.Start = function (_dataItems) { if (isFlashVer) { var flashPalyer = getSWF(playerID); if (flashPalyer != null) { flashPalyer.Start(); } } else { this.Init(elemParent, 0, updateInfoCallback); } }; /* Stop to play the images. */ this.Stop = function () { if (isFlashVer) { var flashPalyer = getSWF(playerID); if (flashPalyer != null) { flashPalyer.Stop(); } } else { var c = document.createElement('canvas'); var $img = document.getElementById("cameraImg"); if ($img == null) return; var h = $img.naturalHeight; var w = $img.naturalWidth; if (h > 0 && w > 0) { c.width = w; c.height = h; var ctx = c.getContext('2d'); ctx.drawImage($img, 0, 0); $img.src = c.toDataURL('image/jpeg'); } } }; /* Request full screen */ this.FullScreen = function () { //player.requestFullscreen(); return false; } /* Exit full screen. */ this.ExitFullScreen = function () { //player.exitFullscreen(); return false; } /* Reset playing context. */ this.Reset = function () { //do nothing. } this.Getdimension = function () { if (!isFlashVer) { var $img = document.getElementById("cameraImg"); var h = $img.naturalHeight; var w = $img.naturalWidth; return new Array(w, h); } else { var flashPalyer = getSWF(playerID); if (flashPalyer != null) { return flashPalyer.GetDimensions(); } } } this.Zoom = function () { } this.Mute = function () { }; return this; }