-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscene.js
More file actions
170 lines (141 loc) · 3.75 KB
/
Copy pathscene.js
File metadata and controls
170 lines (141 loc) · 3.75 KB
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
f.Scene = function(chapter, title, config) {
this.constructor.call(this, chapter, title, config);
};
Ext.extend(f.Scene, Ext.util.Observable, {
chapter: null,
title: null,
voiceoverTrack: null,
started: false,
constructor: function(chapter, title, config) {
this.chapter = chapter;
this.title = title;
this.timecodes = new Ext.util.MixedCollection();
return this;
},
duration: function(time) {
console.log("duration called.");
this.length = time;
return this;
},
voiceover: function(assetId) {
console.log("Voiceover assetId: " + assetId);
this.voiceoverTrack = this.asset(assetId);
console.log("Have voice over with id: " + assetId + " and src: " + this.voiceoverTrack.src);
return this;
},
asset: function(id) {
return this.chapter.assets.get(id);
},
at: function(timecode) {
var list = this.timecodes.get(timecode);
if(!list) {
list = new Array();
}
var event = new f.Event(this);
list.push(event);
this.timecodes.add(timecode, list);
console.log("Created new event for timecode: " + timecode);
return event;
},
start: function() {
console.log("starting scene: " + this.title);
if(this.voiceoverTrack) {
// start audio and register events
console.log("Starting voice over.");
this.voiceoverTrack.el.on("timeupdate", this.htmlEventFired.createDelegate(this));
this.voiceoverTrack.el.on("ended", this.sceneComplete.createDelegate(this));
if(this.chapter.stage.isTablet) {
// we have to prompt the user to continue due to audio issues.
this.voiceoverTrack.el.dom.play();
} else {
console.log(this.voiceoverTrack)
this.voiceoverTrack.el.dom.play();
}
} else {
console.log("Starting timer based.");
// start timer
var task = {
run: this.timerFired,
interval: 1000,
scope:this
}
this.seconds = 0;
/*
this.runner = new Ext.util.TaskRunner();
this.runner.start(task);
*/
Ext.TaskMgr.start(task);
// this.timerFired();
}
},
pause: function() {
this.stop(); // pause == stop. Have pause to match unpause.
},
unpause: function() {
if(this.voiceoverTrack) {
// start audio and register events
console.log("Restarting voice over.");
this.voiceoverTrack.el.dom.play();
} else {
console.log("Restarting timer based.");
// start timer
var task = {
run: this.timerFired,
interval: 1000,
scope:this
}
Ext.TaskMgr.start(task);
}
},
stop: function() {
/*
if(this.runner)
this.runner.stopAll();
*/
Ext.TaskMgr.stopAll();
},
htmlEventFired: function(event, el) {
console.log("htmlEventFired: " + el.currentTime);
this.timeEvent(el.currentTime);
},
timerFired: function() {
if(this.seconds > this.length) {
// next scene...
this.sceneComplete();
return;
}
this.timeEvent(this.seconds);
this.seconds++;
},
convertToTimeCode: function(seconds) {
var minutes = seconds / 60;
seconds = seconds % 60;
return sprintf("%d:%02d", minutes, seconds);
},
timeEvent: function(time) {
// coalesce similar events...
if(this.started || this.currentTime) { // started is a flag because when current time is zero, it evaluates to false and we call 0:00 multiple times.
if(Math.floor(time) == this.currentTime)
return;
}
this.started = true;
this.currentTime = Math.floor(time);
try {
var timecode = this.convertToTimeCode(time);
console.log("Timecode: " + timecode);
var list = this.timecodes.get(timecode);
if(list) {
Ext.each(list, function(item) {
item.start();
})
}
} catch(exception) {
console.log("Caught exception: ");
console.log(exception);
}
},
sceneComplete: function() {
console.log("Scene[" + this.title + "] complete");
this.chapter.sceneComplete();
}
});