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