-
Notifications
You must be signed in to change notification settings - Fork 6
/
reactor.html
105 lines (94 loc) · 4.17 KB
/
reactor.html
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<!DOCTYPE html>
<html>
<body>
<!-- 1. The <iframe> (and video player) will replace this <div> tag. -->
<div id="reactor"></div>
<script>
// 2. This code loads the IFrame Player API code asynchronously.
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
// 3. This function creates an <iframe> (and YouTube player)
// after the API code downloads.
//console.log("Reactor Frame Start time is: " +localStorage.getItem("reactorStart"));
var videotime = 0;
var player;
function onYouTubeIframeAPIReady() {
// console.log("FUNCTION: Reactor Frame Start time is: " + localStorage.getItem("reactorStart") + "Int: " + parseInt(localStorage.getItem("reactorStart")));
var startTime = parseInt(localStorage.getItem("reactorStart"));
player = new YT.Player('reactor', {
// height: '400',
// width: '100%',
playerVars: { 'enablejsapi' : 1, 'autoplay': 0, 'controls': 1,'rel': 0, 'autohide':1,'wmode':'opaque','origin':'https://reactorhub.github.io','start':startTime },
videoId: localStorage.getItem("reactorVideoID"),
//start: 180,
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
}
});
}
// setTimeout(function(){
// 4. The API will call this function when the video player is ready.
function onPlayerReady(event) {
// setTimeout(function(){
event.target.playVideo();
// console.log("reactor ready: " + localStorage.getItem("reactorVideoID"));
player.setVolume(localStorage.getItem("reactorVOL"));
// console.log("Reactor Frame Start time is: " +localStorage.getItem("reactorStart"));
// }, 189000)
if (typeof(Storage) !== "undefined") {
// If there is a local storage timer, then set it to the current time of the talent video
if ( localStorage.reactortimer) {
localStorage.reactortimer = videotime;
//localStorage.setItem('talentPlayer', JSON.stringify(player));
// console.log("+=+=+=+=+=+=+=+=+= local storage talenttimer is: " + localStorage.talenttimer);
} else {
// no local storage timer? create it and set it to 0
localStorage.reactortimer = 0;
}
}
// console.log("Reator time is: " + videotime);
function updateTime() {
var oldTime = videotime;
if(player && player.getCurrentTime) {
videotime = player.getCurrentTime();
localStorage.reactortimer = videotime;
// console.log("reactor time is: " + localStorage.reactortimer);
// document.getElementById("time").innerHTML = videotime;
}
if(videotime !== oldTime) {
onProgress(videotime);
}
}
function readCommands() {
// console.log("Inside read commands function");
}
function onProgress() {
// console.log("Inside on Progress function");
}
// call the updateTime function every 100 ms
timeupdater = setInterval(updateTime, 100);
// call the storeReactorTime
// talenttimeupdater = setInterval(storeReactorTime,100);
var readcommands = setInterval(readCommands,100);
}
// 5. The API calls this function when the player's state changes.
// The function indicates that when playing a video (state=1),
// the player should play for six seconds and then stop.
var done = false;
function onPlayerStateChange(event) {
// if (event.data == YT.PlayerState.PLAYING && !done) {
// setTimeout(stopVideo, 6000);
// done = true;
// }
// console.log("onPlayerStateChange: in")
}
function stopVideo() {
player.pauseVideo();
}
// }, 9000);
</script>
</body>
</html>