| author | veltr |
| Mon, 17 Sep 2012 00:17:06 +0900 | |
| branch | players-as-widgets |
| changeset 957 | 4da0a5740b6c |
| parent 919 | 972099304059 |
| permissions | -rw-r--r-- |
| 957 | 1 |
//TODO: Remove Popcorn replacement, replace it by Media Events |
2 |
||
| 387 | 3 |
/* wrapper that simulates popcorn.js because |
4 |
popcorn is a bit unstable at the time */ |
|
| 388 | 5 |
|
| 919 | 6 |
/* Popcorn.code replacement has been disabled. It didn't work properly and was not even used */ |
7 |
||
| 702 | 8 |
IriSP.PopcornReplacement = { |
| 442 | 9 |
}; |
| 390 | 10 |
|
| 702 | 11 |
/** base class for our popcorn-compatible players. |
| 699 | 12 |
*/ |
| 702 | 13 |
IriSP.PopcornReplacement.player = function(container, options) { |
| 919 | 14 |
|
15 |
this.media = { |
|
16 |
"paused": true, |
|
17 |
"muted": false |
|
18 |
}; |
|
|
870
2c025db10a10
Migrated playerWidget and started annotationsListWidget
veltr
parents:
841
diff
changeset
|
19 |
|
| 919 | 20 |
this.container = container.replace(/^#/,''); //remove '#' at beginning |
21 |
this.msgPump = {}; /* dictionnary used to receive and send messages */ |
|
22 |
this._options = options; |
|
| 917 | 23 |
|
| 388 | 24 |
}; |
25 |
||
| 699 | 26 |
IriSP.PopcornReplacement.player.prototype.listen = function(msg, callback) { |
| 919 | 27 |
if (!this.msgPump.hasOwnProperty(msg)) { |
28 |
this.msgPump[msg] = []; |
|
29 |
} |
|
30 |
this.msgPump[msg].push(callback); |
|
| 699 | 31 |
}; |
32 |
||
| 917 | 33 |
IriSP.PopcornReplacement.player.prototype.on = IriSP.PopcornReplacement.player.prototype.listen; |
34 |
||
| 699 | 35 |
IriSP.PopcornReplacement.player.prototype.trigger = function(msg, params) { |
| 919 | 36 |
if (!this.msgPump.hasOwnProperty(msg)) { |
37 |
return; |
|
38 |
} |
|
39 |
var d = this.msgPump[msg]; |
|
40 |
for(var i = 0; i < d.length; i++) { |
|
41 |
d[i].call(window, params); |
|
42 |
} |
|
| 388 | 43 |
}; |
44 |
||
| 917 | 45 |
IriSP.PopcornReplacement.player.prototype.emit = IriSP.PopcornReplacement.player.prototype.trigger; |
| 919 | 46 |
/* |
| 702 | 47 |
IriSP.PopcornReplacement.player.prototype.guid = function(prefix) { |
| 388 | 48 |
var str = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { |
49 |
var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8); |
|
50 |
return v.toString(16); |
|
51 |
}); |
|
52 |
||
53 |
return prefix + str; |
|
54 |
}; |
|
55 |
||
| 702 | 56 |
/** init the api after that flash player has been setup - called by the callback |
57 |
defined by the embedded flash player |
|
| 919 | 58 |
|
| 702 | 59 |
IriSP.PopcornReplacement.player.prototype.__initApi = function() { |
60 |
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
|
61 |
// but popcorn doesn't need to know more. |
| 702 | 62 |
this.media.muted = this.playerFns.getMute(); |
| 919 | 63 |
/* some programmed segments are supposed to be run at the beginning |
| 578 | 64 |
var i = 0; |
| 702 | 65 |
for(i = 0; i < this.__codes.length; i++) { |
66 |
var c = this.__codes[i]; |
|
| 578 | 67 |
if (0 == c.start) { |
68 |
c.onStart(); |
|
69 |
} |
|
70 |
|
|
71 |
if (0 == c.end) { |
|
72 |
c.onEnd(); |
|
73 |
} |
|
74 |
} |
|
| 919 | 75 |
|
| 388 | 76 |
}; |
| 919 | 77 |
*/ |
| 388 | 78 |
|
| 702 | 79 |
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
|
80 |
if (typeof(time) === "undefined") { |
| 702 | 81 |
return this.playerFns.getPosition(); |
| 388 | 82 |
} else { |
83 |
var currentTime = +time; |
|
| 723 | 84 |
this.playerFns.seek(currentTime); |
| 604 | 85 |
return currentTime; |
| 388 | 86 |
} |
87 |
}; |
|
88 |
||
| 702 | 89 |
IriSP.PopcornReplacement.player.prototype.play = function() { |
90 |
this.media.paused = false; |
|
91 |
this.trigger("play"); |
|
92 |
this.playerFns.play(); |
|
| 388 | 93 |
}; |
94 |
|
|
| 702 | 95 |
IriSP.PopcornReplacement.player.prototype.pause = function() { |
96 |
this.media.paused = true; |
|
| 919 | 97 |
this.trigger("pause"); |
| 702 | 98 |
this.playerFns.pause(); |
| 390 | 99 |
}; |
100 |
||
| 702 | 101 |
IriSP.PopcornReplacement.player.prototype.muted = function(val) { |
102 |
if (typeof(val) !== "undefined") { |
|
103 |
||
104 |
if (this.playerFns.getMute() !== val) { |
|
105 |
if (val) { |
|
106 |
this.playerFns.setMute(true); |
|
107 |
this.media.muted = true; |
|
108 |
} else { |
|
109 |
this.playerFns.setMute(false); |
|
110 |
this.media.muted = false; |
|
111 |
} |
|
| 394 | 112 |
|
| 702 | 113 |
this.trigger( "volumechange" ); |
114 |
} |
|
115 |
|
|
116 |
return this.playerFns.getMute(); |
|
117 |
} else { |
|
118 |
return this.playerFns.getMute(); |
|
119 |
} |
|
120 |
}; |
|
121 |
||
| 839 | 122 |
IriSP.PopcornReplacement.player.prototype.volume = function(val) { |
123 |
if (typeof this.playerFns.getVolume == "undefined" || typeof this.playerFns.setVolume == "undefined") { |
|
124 |
return false; |
|
125 |
} |
|
126 |
var _vol = this.playerFns.getVolume(); |
|
127 |
if (typeof(val) !== "undefined" && parseFloat(val) !== NaN) { |
|
128 |
val = Math.max(0, Math.min(1, val)); |
|
129 |
if (parseFloat(val) != parseFloat(_vol)) { |
|
130 |
this.playerFns.setVolume(val); |
|
131 |
this.trigger("volumechange"); |
|
132 |
_vol = this.playerFns.getVolume(); |
|
133 |
} |
|
134 |
} |
|
135 |
return _vol; |
|
136 |
}; |
|
137 |
||
| 917 | 138 |
IriSP.PopcornReplacement.player.prototype.mute = function() { |
139 |
this.muted(true); |
|
140 |
} |
|
141 |
||
142 |
IriSP.PopcornReplacement.player.prototype.unmute = function() { |
|
143 |
this.muted(false); |
|
144 |
} |
|
| 702 | 145 |
|
|
441
99b7c5192330
fixed horrible bug involving jQuery message passing.
hamidouk
parents:
431
diff
changeset
|
146 |
|
| 702 | 147 |
IriSP.PopcornReplacement.player.prototype.roundTime = function() { |
148 |
var currentTime = this.currentTime(); |
|
| 394 | 149 |
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
|
150 |
}; |