-
Notifications
You must be signed in to change notification settings - Fork 155
/
utils.js
39 lines (35 loc) · 1.64 KB
/
utils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
function InitVisualisations(videoCtx, graphCanvasID, visualisationCanvasID){
/****************************
* GUI setup
*****************************/
/*
* Create an interactive visualisation canvas.
*/
var visualisationCanvas = document.getElementById(visualisationCanvasID);
RefreshGraph(videoCtx, graphCanvasID);
//visualisationCanvas.height = 20;
//visualisationCanvas.width = 390;
//Setup up a render function so we can update the playhead position.
function render () {
//VideoCompositor.renderPlaylist(playlist, visualisationCanvas, videoCompositor.currentTime);
VideoContext.visualiseVideoContextTimeline(videoCtx, visualisationCanvas, videoCtx.currentTime);
requestAnimationFrame(render);
}
requestAnimationFrame(render);
//catch mouse events to we can scrub through the timeline.
visualisationCanvas.addEventListener("mousedown", function(evt){
var x;
if (evt.x!== undefined){
x = evt.x - visualisationCanvas.offsetLeft;
}else{
//Fix for firefox
x = evt.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
}
var secondsPerPixel = videoCtx.duration / visualisationCanvas.width;
if(secondsPerPixel*x !== Infinity) videoCtx.currentTime = secondsPerPixel*x;
}, false);
}
function RefreshGraph(videoCtx, graphCanvasID){
var graphCanvas = document.getElementById(graphCanvasID);
VideoContext.visualiseVideoContextGraph(videoCtx, graphCanvas);
}