| author | veltr |
| Thu, 19 Apr 2012 19:20:41 +0200 | |
| branch | new-model |
| changeset 872 | d777d05a16e4 |
| parent 870 | 2c025db10a10 |
| child 875 | 43629caa77bc |
| permissions | -rw-r--r-- |
| 387 | 1 |
/* wrapper that simulates popcorn.js because |
2 |
popcorn is a bit unstable at the time */ |
|
| 388 | 3 |
|
| 702 | 4 |
IriSP.PopcornReplacement = { |
| 442 | 5 |
}; |
| 390 | 6 |
|
| 702 | 7 |
/** base class for our popcorn-compatible players. |
| 699 | 8 |
*/ |
| 702 | 9 |
IriSP.PopcornReplacement.player = function(container, options) { |
10 |
/* the jwplayer calls the callbacks in the global space so we need to |
|
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
841
diff
changeset
|
11 |
preserve them this way */ |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
841
diff
changeset
|
12 |
var _this = this; |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
841
diff
changeset
|
13 |
|
| 702 | 14 |
this.callbacks = { |
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
841
diff
changeset
|
15 |
onReady: IriSP._.bind(this.__initApi, this), |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
841
diff
changeset
|
16 |
onTime: IriSP._.bind(this.__timeHandler, this), |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
841
diff
changeset
|
17 |
onPlay: IriSP._.bind(this.__playHandler, this), |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
841
diff
changeset
|
18 |
onPause: IriSP._.bind(this.__pauseHandler, this), |
|
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
841
diff
changeset
|
19 |
onSeek: IriSP._.bind(this.__seekHandler, this) |
| 702 | 20 |
}; |
21 |
|
|
| 699 | 22 |
this.media = { |
23 |
"paused": true, |
|
24 |
"muted": false |
|
25 |
}; |
|
| 702 | 26 |
|
27 |
this.container = container.slice(1); //eschew the '#' |
|
| 699 | 28 |
|
29 |
this.msgPump = {}; /* dictionnary used to receive and send messages */ |
|
| 702 | 30 |
this.__codes = []; /* used to schedule the execution of a piece of code in |
31 |
a segment (similar to the popcorn.code plugin). */ |
|
| 785 | 32 |
|
33 |
this._options = options; |
|
| 702 | 34 |
|
| 388 | 35 |
}; |
36 |
||
| 699 | 37 |
IriSP.PopcornReplacement.player.prototype.listen = function(msg, callback) { |
38 |
if (!this.msgPump.hasOwnProperty(msg)) |
|
39 |
this.msgPump[msg] = []; |
|
40 |
||
41 |
this.msgPump[msg].push(callback); |
|
42 |
}; |
|
43 |
||
44 |
IriSP.PopcornReplacement.player.prototype.trigger = function(msg, params) { |
|
45 |
if (!this.msgPump.hasOwnProperty(msg)) |
|
|
445
c2eac11a9053
wrote our own pubsub system because of a bug in the jquery one
hamidouk
parents:
442
diff
changeset
|
46 |
return; |
|
c2eac11a9053
wrote our own pubsub system because of a bug in the jquery one
hamidouk
parents:
442
diff
changeset
|
47 |
|
| 699 | 48 |
var d = this.msgPump[msg]; |
| 596 | 49 |
|
| 586 | 50 |
for(var i = 0; i < d.length; i++) { |
51 |
d[i].call(window, params); |
|
|
445
c2eac11a9053
wrote our own pubsub system because of a bug in the jquery one
hamidouk
parents:
442
diff
changeset
|
52 |
} |
|
c2eac11a9053
wrote our own pubsub system because of a bug in the jquery one
hamidouk
parents:
442
diff
changeset
|
53 |
|
| 388 | 54 |
}; |
55 |
||
| 702 | 56 |
IriSP.PopcornReplacement.player.prototype.guid = function(prefix) { |
| 388 | 57 |
var str = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { |
58 |
var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8); |
|
59 |
return v.toString(16); |
|
60 |
}); |
|
61 |
||
62 |
return prefix + str; |
|
63 |
}; |
|
64 |
||
| 702 | 65 |
/** init the api after that flash player has been setup - called by the callback |
66 |
defined by the embedded flash player |
|
67 |
*/ |
|
68 |
IriSP.PopcornReplacement.player.prototype.__initApi = function() { |
|
69 |
this.trigger("loadedmetadata"); // we've done more than loading metadata of course, |
|
|
463
7ef123b2410f
trigger a bunch of signals for popcorn compatibility.
hamidouk
parents:
458
diff
changeset
|
70 |
// but popcorn doesn't need to know more. |
| 702 | 71 |
this.media.muted = this.playerFns.getMute(); |
| 578 | 72 |
/* some programmed segments are supposed to be run at the beginning */ |
73 |
var i = 0; |
|
| 702 | 74 |
for(i = 0; i < this.__codes.length; i++) { |
75 |
var c = this.__codes[i]; |
|
| 578 | 76 |
if (0 == c.start) { |
77 |
c.onStart(); |
|
78 |
} |
|
79 |
|
|
80 |
if (0 == c.end) { |
|
81 |
c.onEnd(); |
|
82 |
} |
|
83 |
} |
|
| 388 | 84 |
}; |
85 |
||
| 702 | 86 |
IriSP.PopcornReplacement.player.prototype.currentTime = function(time) { |
|
605
e1a6f73038b4
made the listWidget redraw at every timeupdate event (added a small optimization though,
hamidouk
parents:
604
diff
changeset
|
87 |
if (typeof(time) === "undefined") { |
| 702 | 88 |
return this.playerFns.getPosition(); |
| 388 | 89 |
} else { |
90 |
var currentTime = +time; |
|
| 723 | 91 |
this.playerFns.seek(currentTime); |
| 604 | 92 |
return currentTime; |
| 388 | 93 |
} |
94 |
}; |
|
95 |
||
| 702 | 96 |
IriSP.PopcornReplacement.player.prototype.play = function() { |
97 |
this.media.paused = false; |
|
98 |
this.trigger("play"); |
|
99 |
//IriSP.PopcornReplacement.trigger("playing"); |
|
100 |
this.playerFns.play(); |
|
| 388 | 101 |
}; |
102 |
|
|
| 702 | 103 |
IriSP.PopcornReplacement.player.prototype.pause = function() { |
| 841 | 104 |
// if ( !this.media.paused ) { |
| 702 | 105 |
this.media.paused = true; |
106 |
this.trigger( "pause" ); |
|
107 |
this.playerFns.pause(); |
|
| 841 | 108 |
// } |
| 390 | 109 |
}; |
110 |
||
| 702 | 111 |
IriSP.PopcornReplacement.player.prototype.muted = function(val) { |
112 |
if (typeof(val) !== "undefined") { |
|
113 |
||
114 |
if (this.playerFns.getMute() !== val) { |
|
115 |
if (val) { |
|
116 |
this.playerFns.setMute(true); |
|
117 |
this.media.muted = true; |
|
118 |
} else { |
|
119 |
this.playerFns.setMute(false); |
|
120 |
this.media.muted = false; |
|
121 |
} |
|
| 394 | 122 |
|
| 702 | 123 |
this.trigger( "volumechange" ); |
124 |
} |
|
125 |
|
|
126 |
return this.playerFns.getMute(); |
|
127 |
} else { |
|
128 |
return this.playerFns.getMute(); |
|
129 |
} |
|
130 |
}; |
|
131 |
||
| 839 | 132 |
IriSP.PopcornReplacement.player.prototype.volume = function(val) { |
133 |
if (typeof this.playerFns.getVolume == "undefined" || typeof this.playerFns.setVolume == "undefined") { |
|
134 |
return false; |
|
135 |
} |
|
136 |
var _vol = this.playerFns.getVolume(); |
|
137 |
if (typeof(val) !== "undefined" && parseFloat(val) !== NaN) { |
|
138 |
val = Math.max(0, Math.min(1, val)); |
|
139 |
if (parseFloat(val) != parseFloat(_vol)) { |
|
140 |
this.playerFns.setVolume(val); |
|
141 |
this.trigger("volumechange"); |
|
142 |
_vol = this.playerFns.getVolume(); |
|
143 |
} |
|
144 |
} |
|
145 |
return _vol; |
|
146 |
}; |
|
147 |
||
| 702 | 148 |
IriSP.PopcornReplacement.player.prototype.mute = IriSP.PopcornReplacement.player.prototype.muted; |
149 |
||
150 |
IriSP.PopcornReplacement.player.prototype.code = function(options) { |
|
151 |
this.__codes.push(options); |
|
152 |
return this; |
|
| 390 | 153 |
}; |
154 |
||
| 394 | 155 |
/* called everytime the player updates itself |
156 |
(onTime event) |
|
157 |
*/ |
|
158 |
||
| 706 | 159 |
IriSP.PopcornReplacement.player.prototype.__timeHandler = function(event) { |
|
417
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
160 |
var pos = event.position; |
| 702 | 161 |
|
|
417
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
162 |
var i = 0; |
| 702 | 163 |
for(i = 0; i < this.__codes.length; i++) { |
164 |
var c = this.__codes[i]; |
|
| 580 | 165 |
|
|
417
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
166 |
if (pos >= c.start && pos < c.end && |
| 580 | 167 |
pos - 1 <= c.start) { |
|
417
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
168 |
c.onStart(); |
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
169 |
} |
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
170 |
|
|
475
5c254621cd9c
fixed popcorn replacement bug where onEnd would be called after onStart.
hamidouk
parents:
463
diff
changeset
|
171 |
if (pos > c.start && pos > c.end && |
| 580 | 172 |
pos - 1 <= c.end) { |
| 578 | 173 |
c.onEnd(); |
|
417
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
174 |
} |
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
175 |
|
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
176 |
} |
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
177 |
|
| 702 | 178 |
this.trigger("timeupdate"); |
| 390 | 179 |
}; |
| 394 | 180 |
|
| 702 | 181 |
IriSP.PopcornReplacement.player.prototype.__seekHandler = function(event) { |
|
417
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
182 |
var i = 0; |
| 723 | 183 |
|
| 702 | 184 |
for(i = 0; i < this.__codes.length; i++) { |
185 |
var c = this.__codes[i]; |
|
|
417
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
186 |
|
|
475
5c254621cd9c
fixed popcorn replacement bug where onEnd would be called after onStart.
hamidouk
parents:
463
diff
changeset
|
187 |
if (event.position >= c.start && event.position < c.end) { |
|
417
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
188 |
c.onEnd(); |
|
475
5c254621cd9c
fixed popcorn replacement bug where onEnd would be called after onStart.
hamidouk
parents:
463
diff
changeset
|
189 |
} |
|
5c254621cd9c
fixed popcorn replacement bug where onEnd would be called after onStart.
hamidouk
parents:
463
diff
changeset
|
190 |
} |
| 580 | 191 |
|
| 702 | 192 |
for(i = 0; i < this.__codes.length; i++) { |
193 |
var c = this.__codes[i]; |
|
|
475
5c254621cd9c
fixed popcorn replacement bug where onEnd would be called after onStart.
hamidouk
parents:
463
diff
changeset
|
194 |
|
|
417
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
195 |
if (typeof(event.offset) === "undefined") |
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
196 |
event.offset = 0; |
|
475
5c254621cd9c
fixed popcorn replacement bug where onEnd would be called after onStart.
hamidouk
parents:
463
diff
changeset
|
197 |
|
|
5c254621cd9c
fixed popcorn replacement bug where onEnd would be called after onStart.
hamidouk
parents:
463
diff
changeset
|
198 |
if (event.offset >= c.start && event.offset < c.end) { |
|
417
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
199 |
c.onStart(); |
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
200 |
} |
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
201 |
|
|
bae7c50704d7
fixed code() function. The Popcorn workaround now works correctly.
hamidouk
parents:
394
diff
changeset
|
202 |
} |
| 723 | 203 |
|
| 750 | 204 |
/* this signal sends as an extra argument the position in the video. |
205 |
As far as I know, this argument is not provided by popcorn */ |
|
| 749 | 206 |
this.trigger("seeked", event.offset); |
| 702 | 207 |
}; |
208 |
||
209 |
IriSP.PopcornReplacement.player.prototype.__playHandler = function(event) { |
|
210 |
this.media.paused = false; |
|
211 |
this.trigger("play"); |
|
|
441
99b7c5192330
fixed horrible bug involving jQuery message passing.
hamidouk
parents:
431
diff
changeset
|
212 |
}; |
|
99b7c5192330
fixed horrible bug involving jQuery message passing.
hamidouk
parents:
431
diff
changeset
|
213 |
|
| 702 | 214 |
IriSP.PopcornReplacement.player.prototype.__pauseHandler = function(event) { |
215 |
this.media.paused = true; |
|
216 |
this.trigger("pause"); |
|
|
441
99b7c5192330
fixed horrible bug involving jQuery message passing.
hamidouk
parents:
431
diff
changeset
|
217 |
}; |
|
99b7c5192330
fixed horrible bug involving jQuery message passing.
hamidouk
parents:
431
diff
changeset
|
218 |
|
| 702 | 219 |
IriSP.PopcornReplacement.player.prototype.roundTime = function() { |
220 |
var currentTime = this.currentTime(); |
|
| 394 | 221 |
return Math.round(currentTime); |
|
711
323205a7bd39
separated jwplayer code from pop.js and put it into its own folder, players/.
hamidouk
parents:
706
diff
changeset
|
222 |
}; |