|
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; |
|
39 _opts.height = this.height || Math.floor(.643*this.width); |
|
40 |
|
41 for (var i = 0; i < _props.length; i++) { |
|
42 if (typeof this[_props[i]] !== "undefined") { |
|
43 _opts[_props[i]] = this[_props[i]]; |
|
44 } |
|
45 } |
|
46 |
|
47 if (this.autostart) { |
|
48 _pauseState = false; |
|
49 this.media.trigger("play"); |
|
50 } |
|
51 // Binding functions to jwplayer |
|
52 |
|
53 this.media.getCurrentTime = function() { |
|
54 return new IriSP.Model.Time(1000*_player.getPosition() || 0); |
|
55 } |
|
56 this.media.getVolume = function() { |
|
57 return _player.getVolume() / 100; |
|
58 } |
|
59 this.media.getPaused = function() { |
|
60 return _pauseState; |
|
61 } |
|
62 this.media.getMuted = function() { |
|
63 return _player.getMute(); |
|
64 } |
|
65 this.media.setCurrentTime = function(_milliseconds) { |
|
66 _seekPause = _pauseState; |
|
67 return _player.seek(_milliseconds / 1000); |
|
68 } |
|
69 this.media.setVolume = function(_vol) { |
|
70 return _player.setVolume(Math.floor(_vol*100)); |
|
71 } |
|
72 this.media.mute = function() { |
|
73 return _player.setMute(true); |
|
74 } |
|
75 this.media.unmute = function() { |
|
76 return _player.setMute(false); |
|
77 } |
|
78 this.media.play = function() { |
|
79 return _player.play(true); |
|
80 } |
|
81 this.media.pause = function() { |
|
82 return _player.pause(true); |
|
83 } |
|
84 |
|
85 // Binding jwplater events to media |
|
86 |
|
87 var _media = this.media; |
|
88 |
|
89 _opts.events = { |
|
90 onReady: function() { |
|
91 _media.trigger("loadedmetadata"); |
|
92 }, |
|
93 onTime: function(_progress) { |
|
94 if (_seekPause) { |
|
95 _player.pause(true); |
|
96 _seekPause = false; |
|
97 } else { |
|
98 if (_pauseState && _player.getState() === "PLAYING") { |
|
99 _pauseState = false; |
|
100 _media.trigger("play"); |
|
101 } |
|
102 } |
|
103 _media.trigger("timeupdate", new IriSP.Model.Time(_progress.position * 1000)); |
|
104 }, |
|
105 onPlay: function() { |
|
106 if (!_seekPause) { |
|
107 _pauseState = false; |
|
108 _media.trigger("play"); |
|
109 } |
|
110 }, |
|
111 onPause: function() { |
|
112 _pauseState = true; |
|
113 _media.trigger("pause"); |
|
114 }, |
|
115 onSeek: function() { |
|
116 _media.trigger("seeked"); |
|
117 } |
|
118 } |
|
119 _player.setup(_opts); |
|
120 |
|
121 this.jwplayer = _player; |
|
122 |
|
123 } |