function getVideoPlayerTabId(video){ return `videoPlayer-${video.mid}-${moment(video.time).format('YYYY-MM-DD-HH-mm-ss')}` } $(document).ready(function(){ var theBlock = $('#tab-videoPlayer') window.createVideoPlayerTab = function(video,timeStart){ var newTabId = getVideoPlayerTabId(video) var humanStartTime = formattedTime(video.time,true) var humanEndTime = formattedTime(video.end,true) var tabLabel = `${lang['Video']} : ${loadedMonitors[video.mid].name} : ${formattedTime(video.time,true)}` var videoUrl = getLocation() + video.href var hasRows = video.events && video.events.length > 0 var loadedEvents = {} var eventMatrixHtml = `` if(hasRows){ var objectsFound = {} eventMatrixHtml += `

${lang.Events}

` $.each(video.events,function(n,theEvent){ loadedEvents[new Date(theEvent.time)] = theEvent var objectsFound = {} eventMatrixHtml += `
` eventMatrixHtml += `
${formattedTime(theEvent.time)}
` $.each(theEvent.details.matrices,function(n,matrix){ if(!objectsFound[matrix.tag])objectsFound[matrix.tag] = 1 ++objectsFound[matrix.tag] }) $.each(objectsFound,function(tag,count){ eventMatrixHtml += `
${tag} : ${count}
` }) eventMatrixHtml += `
` }) eventMatrixHtml += `` } var baseHtml = `
${tabLabel}
${lang.Started}
${humanStartTime}
${lang.Ended}
${humanEndTime}
${eventMatrixHtml}
` var tabCreateResponse = createNewTab(newTabId,tabLabel,baseHtml,{},null,'videoPlayer') var videoElement = tabCreateResponse.theTab.find('.tab-videoPlayer-video-element')[0] if(!tabCreateResponse.existAlready){ var videoObjectContainer = tabCreateResponse.theTab.find('.tab-videoPlayer-event-objects') var videoHeight = videoObjectContainer.height() var videoWidth = videoObjectContainer.width() videoElement.ontimeupdate = function(time){ var eventTime = new Date(((new Date(video.time).getTime() / 1000) + videoElement.currentTime) * 1000) var theEvent = loadedEvents[eventTime] if(theEvent){ drawMatrices(theEvent,{ theContainer: videoObjectContainer, height: videoHeight, width: videoWidth, }) }else{ videoObjectContainer.find('.stream-detected-object').remove() } } } if(timeStart)videoElement.currentTime = timeStart; } window.closeVideoPlayer = function(tabId){ console.log('closeVideoPlayer') try{ var videoElement = $(`#tab-${tabId}`).find('video')[0] if(!videoElement.paused)videoElement.pause(); videoElement.removeAttribute('src'); videoElement.load(); }catch(err){ console.log(err) } } window.pauseVideoPlayer = function(tabId){ console.log('pauseVideoPlayer') try{ var videoElement = $(`#tab-${tabId}`).find('video')[0] try{ videoElement.pause(); }catch(err){ } }catch(err){ console.log(err) } } window.resumeVideoPlayer = function(tabId){ console.log('resumeVideoPlayer') try{ var videoElement = $(`#tab-${tabId}`).find('video')[0] try{ videoElement.play(); }catch(err){ } }catch(err){ console.log(err) } } function drawVideoInfoCard(){ } function drawVideoEventsList(){ } $('body') .on('tab-open-videoPlayer',function(){ if(pageLoadingData && pageLoadingData.title){ theBlock.find('.video-title').html(pageLoadingData.title) theBlock.find('.video-time').html(formattedTime(pageLoadingData.time,true)) theBlock.find('.video-end').html(formattedTime(pageLoadingData.end,true)) } }) .on('click','.tab-videoPlayer-event-row',function(){ var el = $(this) var parent = el.parents('main') var videoEl = parent.find('video') var videoData = loadedVideosInMemory[parent.attr('video-id')] var videoTime = new Date(videoData.time).getTime() / 1000 var timeIndex = new Date(el.attr('time-index')).getTime() / 1000 var newVideoTimeIndex = timeIndex - videoTime console.log(newVideoTimeIndex) videoEl[0].currentTime = newVideoTimeIndex }) })