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