|
785
|
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 |
/** jwplayer player wrapper */ |
|
|
5 |
IriSP.PopcornReplacement.dailymotion = function(container, options) { |
|
884
|
6 |
/* Appel du constructeur de la classe parente */ |
|
788
|
7 |
IriSP.PopcornReplacement.player.call(this, container, options); |
|
|
8 |
|
|
785
|
9 |
var _this = this; |
|
|
10 |
|
|
884
|
11 |
/* Définition des fonctions de commande : |
|
|
12 |
this.playerFns.play, .pause, .getPosition, .seek, |
|
|
13 |
.getMute, .setMute, .getVolume, .setVolume |
|
|
14 |
doivent être rattachés aux fonctions du player |
|
|
15 |
* */ |
|
785
|
16 |
|
|
|
17 |
this.playerFns = { |
|
|
18 |
play : function() { |
|
789
|
19 |
if (_this.player) { |
|
|
20 |
return _this.player.playVideo(); |
|
|
21 |
} else { |
|
|
22 |
return false; |
|
|
23 |
} |
|
785
|
24 |
}, |
|
|
25 |
pause : function() { |
|
789
|
26 |
if (_this.player) { |
|
|
27 |
return _this.player.pauseVideo(); |
|
|
28 |
} else { |
|
|
29 |
return false; |
|
|
30 |
} |
|
785
|
31 |
}, |
|
|
32 |
getPosition : function() { |
|
789
|
33 |
if (_this.player) { |
|
|
34 |
return _this.player.getCurrentTime(); |
|
|
35 |
} else { |
|
|
36 |
return 0; |
|
|
37 |
} |
|
785
|
38 |
}, |
|
|
39 |
seek : function(pos) { |
|
789
|
40 |
if (_this.player) { |
|
|
41 |
return _this.player.seekTo(pos); |
|
|
42 |
} else { |
|
|
43 |
return false; |
|
|
44 |
} |
|
785
|
45 |
}, |
|
|
46 |
getMute : function() { |
|
789
|
47 |
if (_this.player) { |
|
|
48 |
return _this.player.isMuted(); |
|
|
49 |
} else { |
|
|
50 |
return false; |
|
|
51 |
} |
|
785
|
52 |
}, |
|
|
53 |
setMute : function(p) { |
|
789
|
54 |
if (_this.player) { |
|
839
|
55 |
if (p) { |
|
|
56 |
_this.player.mute(); |
|
|
57 |
} |
|
|
58 |
else { |
|
|
59 |
_this.player.unMute(); |
|
|
60 |
} |
|
|
61 |
} |
|
|
62 |
}, |
|
|
63 |
getVolume : function() { |
|
|
64 |
if (_this.player) { |
|
|
65 |
return _this.player.getVolume() / 100; |
|
789
|
66 |
} else { |
|
|
67 |
return false; |
|
|
68 |
} |
|
839
|
69 |
}, |
|
|
70 |
setVolume : function(p) { |
|
|
71 |
if (_this.player) { |
|
|
72 |
_this.player.setVolume(Math.floor(100 * p)); |
|
|
73 |
} |
|
|
74 |
}, |
|
785
|
75 |
} |
|
884
|
76 |
|
|
|
77 |
/* Dailymotion utilise un système de fonctions référencées dans |
|
|
78 |
* des variables globales pour la gestion des événements. |
|
|
79 |
*/ |
|
|
80 |
|
|
|
81 |
window.onDailymotionPlayerReady = function() { |
|
|
82 |
_this.onReady(); |
|
|
83 |
}; |
|
|
84 |
window.onDailymotionStateChange = function(_state) { |
|
|
85 |
_this.onStateChange(_state); |
|
|
86 |
} |
|
|
87 |
window.onDailymotionVideoProgress = function(_progress) { |
|
|
88 |
_this.onProgress(_progress); |
|
|
89 |
} |
|
785
|
90 |
|
|
|
91 |
var params = { |
|
788
|
92 |
"allowScriptAccess" : "always", |
|
|
93 |
"wmode": "opaque" |
|
785
|
94 |
}; |
|
|
95 |
var atts = { |
|
|
96 |
id : this.container |
|
|
97 |
}; |
|
|
98 |
swfobject.embedSWF("http://www.dailymotion.com/swf?chromeless=1&enableApi=1", this.container, options.width, options.height, "8", null, null, params, atts); |
|
|
99 |
|
|
|
100 |
}; |
|
|
101 |
|
|
|
102 |
IriSP.PopcornReplacement.dailymotion.prototype = new IriSP.PopcornReplacement.player("", {}); |
|
|
103 |
|
|
884
|
104 |
IriSP.PopcornReplacement.dailymotion.prototype.onReady = function() { |
|
785
|
105 |
|
|
|
106 |
this.player = document.getElementById(this.container); |
|
|
107 |
|
|
|
108 |
this.player.addEventListener("onStateChange", "onDailymotionStateChange"); |
|
|
109 |
this.player.addEventListener("onVideoProgress", "onDailymotionVideoProgress"); |
|
787
|
110 |
this.player.cueVideoByUrl(this._options.video); |
|
792
|
111 |
|
|
919
|
112 |
this.trigger("loadedmetadata"); |
|
785
|
113 |
}; |
|
|
114 |
|
|
884
|
115 |
IriSP.PopcornReplacement.dailymotion.prototype.onProgress = function(progressInfo) { |
|
919
|
116 |
this.trigger("timeupdate"); |
|
785
|
117 |
} |
|
|
118 |
|
|
884
|
119 |
IriSP.PopcornReplacement.dailymotion.prototype.onStateChange = function(state) { |
|
785
|
120 |
|
|
|
121 |
switch(state) { |
|
|
122 |
case 1: |
|
919
|
123 |
this.trigger("play"); |
|
785
|
124 |
break; |
|
|
125 |
|
|
|
126 |
case 2: |
|
919
|
127 |
this.trigger("pause"); |
|
785
|
128 |
break; |
|
|
129 |
|
|
|
130 |
case 3: |
|
919
|
131 |
this.trigger("seeked"); |
|
785
|
132 |
break; |
|
|
133 |
} |
|
|
134 |
|
|
789
|
135 |
}; |