|
694
|
1 |
IriSP.Widgets.JwpPlayer = function(player, config) { |
|
|
2 |
IriSP.Widgets.Widget.call(this, player, config); |
|
|
3 |
}; |
|
|
4 |
|
|
|
5 |
IriSP.Widgets.JwpPlayer.prototype = new IriSP.Widgets.Widget(); |
|
|
6 |
|
|
|
7 |
IriSP.Widgets.JwpPlayer.prototype.defaults = { |
|
|
8 |
} |
|
|
9 |
|
|
|
10 |
IriSP.Widgets.JwpPlayer.prototype.draw = function() { |
|
|
11 |
|
|
|
12 |
var _opts = {}, |
|
|
13 |
_player = jwplayer(this.$[0]), |
|
|
14 |
_seekPause = false, |
|
|
15 |
_pauseState = true, |
|
|
16 |
_props = [ "live", "provider", "autostart" ]; |
|
|
17 |
|
|
|
18 |
if (typeof this.video === "undefined") { |
|
|
19 |
this.video = this.media.video; |
|
|
20 |
} |
|
|
21 |
|
|
|
22 |
if (typeof this.streamer === "undefined") { |
|
|
23 |
this.streamer = this.media.streamer; |
|
|
24 |
} |
|
|
25 |
|
|
|
26 |
if (typeof this.streamer === "function") { |
|
|
27 |
this.streamer = this.streamer(this.video); |
|
|
28 |
} |
|
|
29 |
|
|
|
30 |
if (typeof this.streamer === "string" && (this.provider === "http" || this.provider === "rtmp")) { |
|
|
31 |
this.video = this.video.replace(this.streamer,""); |
|
|
32 |
_opts.streamer = this.streamer; |
|
|
33 |
} |
|
|
34 |
|
|
|
35 |
_opts.file = this.video; |
|
|
36 |
_opts.flashplayer = IriSP.getLib("jwPlayerSWF"); |
|
|
37 |
_opts["controlbar.position"] = "none"; |
|
|
38 |
_opts.width = this.width; |
|
765
|
39 |
if (this.height) { |
|
|
40 |
_opts.height = this.height; |
|
|
41 |
} |
|
694
|
42 |
|
|
|
43 |
for (var i = 0; i < _props.length; i++) { |
|
|
44 |
if (typeof this[_props[i]] !== "undefined") { |
|
|
45 |
_opts[_props[i]] = this[_props[i]]; |
|
|
46 |
} |
|
|
47 |
} |
|
|
48 |
|
|
|
49 |
if (this.autostart) { |
|
|
50 |
_pauseState = false; |
|
|
51 |
this.media.trigger("play"); |
|
|
52 |
} |
|
719
|
53 |
|
|
694
|
54 |
// Binding functions to jwplayer |
|
|
55 |
|
|
719
|
56 |
var _media = this.media; |
|
|
57 |
|
|
|
58 |
_media.on("setcurrenttime", function(_milliseconds) { |
|
694
|
59 |
_seekPause = _pauseState; |
|
719
|
60 |
_player.seek(_milliseconds / 1000); |
|
|
61 |
}); |
|
|
62 |
|
|
|
63 |
_media.on("setvolume", function(_vol) { |
|
|
64 |
_player.setVolume(Math.floor(_vol*100)); |
|
|
65 |
_media.volume = _vol; |
|
|
66 |
}); |
|
|
67 |
|
|
|
68 |
_media.on("setmuted", function(_muted) { |
|
|
69 |
_player.setMute(_muted); |
|
|
70 |
_media.muted = _muted; |
|
|
71 |
}); |
|
|
72 |
|
|
|
73 |
_media.on("setplay", function() { |
|
|
74 |
_player.play(true); |
|
|
75 |
_media.paused = false; |
|
|
76 |
}); |
|
|
77 |
|
|
|
78 |
_media.on("setpause", function() { |
|
|
79 |
_player.pause(true); |
|
|
80 |
_media.paused = true; |
|
|
81 |
}); |
|
694
|
82 |
|
|
|
83 |
// Binding jwplater events to media |
|
|
84 |
|
|
719
|
85 |
function getVolume() { |
|
|
86 |
_media.muted = _player.getMute(); |
|
|
87 |
_media.volume = _player.getVolume() / 100; |
|
|
88 |
} |
|
694
|
89 |
|
|
|
90 |
_opts.events = { |
|
|
91 |
onReady: function() { |
|
719
|
92 |
getVolume(); |
|
|
93 |
_media.currentTime = new IriSP.Model.Time(1000*_player.getPosition() || 0); |
|
694
|
94 |
_media.trigger("loadedmetadata"); |
|
|
95 |
}, |
|
|
96 |
onTime: function(_progress) { |
|
|
97 |
if (_seekPause) { |
|
|
98 |
_player.pause(true); |
|
|
99 |
_seekPause = false; |
|
|
100 |
} else { |
|
|
101 |
if (_pauseState && _player.getState() === "PLAYING") { |
|
|
102 |
_pauseState = false; |
|
|
103 |
_media.trigger("play"); |
|
|
104 |
} |
|
|
105 |
} |
|
|
106 |
_media.trigger("timeupdate", new IriSP.Model.Time(_progress.position * 1000)); |
|
|
107 |
}, |
|
|
108 |
onPlay: function() { |
|
|
109 |
if (!_seekPause) { |
|
|
110 |
_pauseState = false; |
|
|
111 |
_media.trigger("play"); |
|
|
112 |
} |
|
|
113 |
}, |
|
|
114 |
onPause: function() { |
|
|
115 |
_pauseState = true; |
|
|
116 |
_media.trigger("pause"); |
|
|
117 |
}, |
|
|
118 |
onSeek: function() { |
|
|
119 |
_media.trigger("seeked"); |
|
719
|
120 |
}, |
|
|
121 |
onMute: function(_event) { |
|
|
122 |
_media.muted = _event.mute; |
|
|
123 |
_media.trigger("volumechange"); |
|
|
124 |
}, |
|
|
125 |
onVolume: function(_event) { |
|
|
126 |
_media.volume = _event.volume / 100; |
|
|
127 |
_media.trigger("volumechange"); |
|
694
|
128 |
} |
|
|
129 |
} |
|
|
130 |
_player.setup(_opts); |
|
|
131 |
|
|
|
132 |
this.jwplayer = _player; |
|
|
133 |
|
|
|
134 |
} |