forked from marisademeglio/media-overlays-js
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmo.js
74 lines (63 loc) · 2.13 KB
/
mo.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
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
// the main object
MediaOverlaysModel = Backbone.Model.extend({
smilplayer: null,
packageDocument: null,
audioplayer: null,
packageUrl: null,
initialize: function() {
this.smilplayer = new SmilFilePlayer();
this.packageDocument = null;
this.audioplayer = this.smilplayer.getAudioPlayer();
// use these properties to communicate status
this.set({
currentTextUrl: null,
isPlaying: false,
isDocumentDone: true
});
var self = this;
// register for callbacks with the smil and audio players
this.audioplayer.setNotifyOnPause(function() {
self.updateIsPlaying();
});
this.audioplayer.setNotifyOnPlay(function(){
self.updateIsPlaying();
});
this.smilplayer.setNotifySmilDone(function() {
// TODO fetch the next SMIL document and start playing it
// for now we'll skip all that and just say we're done with everything
self.set({isDocumentDone: true});
});
this.smilplayer.setNotifyTextRender(function(src) {
self.set({currentTextUrl: src});
});
},
setPackageFile: function(url) {
this.packageUrl = url;
var self = this;
// TODO can we load this synchronously? doing it for now because it makes life easier.
$.ajax({
type: "GET",
url: url,
dataType: "xml",
async: false,
success: function(xml) {
self.packageDocument = xml;
}
});
},
playTextUrl: function(url) {
this.isDocumentDone = false;
smilUrl = MOUtils.lookupSmil(url, this.packageDocument);
fullSmilUrl = MOUtils.resolveUrl(smilUrl, this.packageUrl);
this.smilplayer.playFile(fullSmilUrl);
},
pause: function() {
this.audioplayer.pause();
},
resume: function() {
this.audioplayer.resume();
},
updateIsPlaying: function() {
this.set({isPlaying: this.audioplayer.isPlaying()});
}
});