|
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) { |
|
788
|
6 |
console.log("Calling"); |
|
785
|
7 |
/* appel du parent pour initialiser les structures communes à tous les players */ |
|
788
|
8 |
IriSP.PopcornReplacement.player.call(this, container, options); |
|
|
9 |
|
|
785
|
10 |
var _this = this; |
|
|
11 |
|
|
|
12 |
/* Définition des fonctions de l'API - */ |
|
|
13 |
|
|
|
14 |
this.playerFns = { |
|
|
15 |
play : function() { |
|
789
|
16 |
if (_this.player) { |
|
|
17 |
return _this.player.playVideo(); |
|
|
18 |
} else { |
|
|
19 |
return false; |
|
|
20 |
} |
|
785
|
21 |
}, |
|
|
22 |
pause : function() { |
|
789
|
23 |
if (_this.player) { |
|
|
24 |
return _this.player.pauseVideo(); |
|
|
25 |
} else { |
|
|
26 |
return false; |
|
|
27 |
} |
|
785
|
28 |
}, |
|
|
29 |
getPosition : function() { |
|
789
|
30 |
if (_this.player) { |
|
|
31 |
return _this.player.getCurrentTime(); |
|
|
32 |
} else { |
|
|
33 |
return 0; |
|
|
34 |
} |
|
785
|
35 |
}, |
|
|
36 |
seek : function(pos) { |
|
789
|
37 |
if (_this.player) { |
|
|
38 |
return _this.player.seekTo(pos); |
|
|
39 |
} else { |
|
|
40 |
return false; |
|
|
41 |
} |
|
785
|
42 |
}, |
|
|
43 |
getMute : function() { |
|
789
|
44 |
if (_this.player) { |
|
|
45 |
return _this.player.isMuted(); |
|
|
46 |
} else { |
|
|
47 |
return false; |
|
|
48 |
} |
|
785
|
49 |
}, |
|
|
50 |
setMute : function(p) { |
|
789
|
51 |
if (_this.player) { |
|
|
52 |
return p ? _this.player.mute() : _this.player.unMute(); |
|
|
53 |
} else { |
|
|
54 |
return false; |
|
|
55 |
} |
|
785
|
56 |
} |
|
|
57 |
} |
|
|
58 |
|
|
|
59 |
window.onDailymotionPlayerReady = IriSP.wrap(this, this.ready); |
|
|
60 |
window.onDailymotionStateChange = IriSP.wrap(this, this.stateHandler); |
|
|
61 |
window.onDailymotionVideoProgress = IriSP.wrap(this, this.progressHandler); |
|
|
62 |
|
|
|
63 |
var params = { |
|
788
|
64 |
"allowScriptAccess" : "always", |
|
|
65 |
"wmode": "opaque" |
|
785
|
66 |
}; |
|
|
67 |
var atts = { |
|
|
68 |
id : this.container |
|
|
69 |
}; |
|
|
70 |
swfobject.embedSWF("http://www.dailymotion.com/swf?chromeless=1&enableApi=1", this.container, options.width, options.height, "8", null, null, params, atts); |
|
|
71 |
|
|
|
72 |
}; |
|
|
73 |
|
|
|
74 |
IriSP.PopcornReplacement.dailymotion.prototype = new IriSP.PopcornReplacement.player("", {}); |
|
|
75 |
|
|
|
76 |
IriSP.PopcornReplacement.dailymotion.prototype.ready = function() { |
|
|
77 |
|
|
|
78 |
this.player = document.getElementById(this.container); |
|
|
79 |
|
|
|
80 |
this.player.addEventListener("onStateChange", "onDailymotionStateChange"); |
|
|
81 |
this.player.addEventListener("onVideoProgress", "onDailymotionVideoProgress"); |
|
787
|
82 |
this.player.cueVideoByUrl(this._options.video); |
|
792
|
83 |
|
|
|
84 |
this.callbacks.onReady(); |
|
785
|
85 |
}; |
|
|
86 |
|
|
|
87 |
IriSP.PopcornReplacement.dailymotion.prototype.progressHandler = function(progressInfo) { |
|
|
88 |
|
|
|
89 |
this.callbacks.onTime({ |
|
|
90 |
position: progressInfo.mediaTime |
|
|
91 |
}); |
|
|
92 |
} |
|
|
93 |
|
|
|
94 |
IriSP.PopcornReplacement.dailymotion.prototype.stateHandler = function(state) { |
|
|
95 |
|
|
|
96 |
switch(state) { |
|
|
97 |
case 1: |
|
|
98 |
this.callbacks.onPlay(); |
|
|
99 |
break; |
|
|
100 |
|
|
|
101 |
case 2: |
|
|
102 |
this.callbacks.onPause(); |
|
|
103 |
break; |
|
|
104 |
|
|
|
105 |
case 3: |
|
789
|
106 |
this.callbacks.onSeek({ |
|
|
107 |
position: this.player.getCurrentTime() |
|
|
108 |
}); |
|
785
|
109 |
break; |
|
|
110 |
|
|
792
|
111 |
/* |
|
785
|
112 |
case 5: |
|
|
113 |
this.callbacks.onReady(); |
|
|
114 |
break; |
|
792
|
115 |
*/ |
|
785
|
116 |
} |
|
|
117 |
|
|
789
|
118 |
}; |