|
755
|
1 |
/* To wrap a player the develop should create a new class derived from |
|
|
2 |
the IriSP.PopcornReplacement.player and defining the correct functions */ |
|
|
3 |
|
|
|
4 |
/** youtube player wrapper */ |
|
|
5 |
IriSP.PopcornReplacement.youtube = function(container, options) { |
|
|
6 |
|
|
|
7 |
/* appel du parent pour initialiser les structures communes à tous les players */ |
|
|
8 |
IriSP.PopcornReplacement.player.call(this, container, options); |
|
|
9 |
|
|
|
10 |
this.media.duration = options.duration; /* optional */ |
|
757
|
11 |
var _this = this; |
|
755
|
12 |
|
|
|
13 |
/* Définition des fonctions de l'API - */ |
|
|
14 |
this.playerFns = { |
|
757
|
15 |
play: function() { return _this.player.playVideo(); }, |
|
|
16 |
pause: function() { return _this.player.pauseVideo(); }, |
|
|
17 |
getPosition: function() { console.log("ho"); return _this.player.getCurrentTime(); }, |
|
|
18 |
seek: function(pos) { return _this.player.seekTo(pos, true); }, |
|
|
19 |
getMute: function() { return _this.player.isMuted(); }, |
|
|
20 |
setMute: function(p) { return _this.player.mute(p); } |
|
755
|
21 |
} |
|
|
22 |
|
|
757
|
23 |
window.onYouTubePlayerReady = IriSP.wrap(this, this.ready); |
|
755
|
24 |
|
|
|
25 |
options.events = this.callbacks; |
|
|
26 |
var params = { allowScriptAccess: "always" }; |
|
756
|
27 |
var atts = { id: container }; |
|
|
28 |
swfobject.embedSWF("http://www.youtube.com/apiplayer?enablejsapi=1&version=3", |
|
|
29 |
container, options.width, options.height, "8", null, null, params, atts); |
|
755
|
30 |
|
|
756
|
31 |
|
|
755
|
32 |
}; |
|
|
33 |
|
|
757
|
34 |
IriSP.PopcornReplacement.youtube.prototype = new IriSP.PopcornReplacement.player("", {}); |
|
755
|
35 |
|
|
757
|
36 |
IriSP.PopcornReplacement.youtube.prototype.ready = function() { |
|
|
37 |
// save the player dom object. |
|
|
38 |
this.player = IriSP.jQuery("#" + this.container).get(0); |
|
|
39 |
// crap - youtube player expects a string describing the function to call. |
|
|
40 |
this.player.addEventListener("onStateChange", "IriSP.PopcornReplacement.youtube.prototype.stateHandler"); |
|
|
41 |
this.player.loadVideoByUrl("http://www.youtube.com/v/ucc58jIasI8?version=3"); |
|
|
42 |
|
|
756
|
43 |
}; |
|
|
44 |
|
|
757
|
45 |
|
|
|
46 |
/* we've got to store the previous state in the prototype because, well |
|
|
47 |
the youtube player is crap */ |
|
|
48 |
IriSP.PopcornReplacement.youtube.prototype.previousState = -1; |
|
755
|
49 |
|
|
757
|
50 |
IriSP.PopcornReplacement.youtube.prototype.stateHandler = function(state) { |
|
|
51 |
if (state === 1) // playing { |
|
|
52 |
/* we're already playing */ |
|
|
53 |
|
|
|
54 |
if (IriSP.PopcornReplacement.youtube.prototype.previousState === state) { |
|
|
55 |
var time = this.player.getCurrentTime(); |
|
|
56 |
console.log(time); |
|
|
57 |
this.callbacks.onTime({position: time}); |
|
|
58 |
} else { /* we're entering the playing state */ |
|
|
59 |
this.callbacks.onPlay(); |
|
|
60 |
} |
|
|
61 |
else if (state === 2) // paused |
|
|
62 |
this.callbacks.onPause(); |
|
|
63 |
else if (state === 3) // buffering |
|
|
64 |
this.callbacks.onSeek(); |
|
|
65 |
|
|
|
66 |
else if (state === 5) /* video ready to play */ |
|
|
67 |
this.callbacks.onReady(); |
|
|
68 |
|
|
|
69 |
IriSP.PopcornReplacement.youtube.prototype.previousState = state; |
|
755
|
70 |
}; |