|
1 IriSP.Widgets.PopcornPlayer = function(player, config) { |
|
2 IriSP.Widgets.Widget.call(this, player, config); |
|
3 }; |
|
4 |
|
5 IriSP.Widgets.PopcornPlayer.prototype = new IriSP.Widgets.Widget(); |
|
6 |
|
7 IriSP.Widgets.PopcornPlayer.prototype.defaults = { |
|
8 } |
|
9 |
|
10 IriSP.Widgets.PopcornPlayer.prototype.draw = function() { |
|
11 var _tmpId = Popcorn.guid("video"), |
|
12 _videoEl = IriSP.jQuery('<video>'); |
|
13 |
|
14 if (typeof this.video === "undefined") { |
|
15 this.video = this.media.video; |
|
16 } |
|
17 |
|
18 if (this.url_transform) { |
|
19 this.video = this.url_transform(this.video); |
|
20 } |
|
21 |
|
22 _videoEl.attr({ |
|
23 "src" : this.video, |
|
24 "id" : _tmpId |
|
25 }) |
|
26 |
|
27 if(this.width) { |
|
28 _videoEl.attr("width", this.width); |
|
29 } |
|
30 if(this.height) { |
|
31 _videoEl.attr("height", this.height); |
|
32 } |
|
33 this.$.append(_videoEl); |
|
34 var _popcorn = Popcorn("#" + _tmpId); |
|
35 |
|
36 // Binding functions to Popcorn |
|
37 |
|
38 this.media.getCurrentTime = function() { |
|
39 return new IriSP.Model.Time(1000*_popcorn.currentTime()); |
|
40 } |
|
41 this.media.getVolume = function() { |
|
42 return _popcorn.volume(); |
|
43 } |
|
44 this.media.getPaused = function() { |
|
45 return _popcorn.media.paused; |
|
46 } |
|
47 this.media.getMuted = function() { |
|
48 return _popcorn.muted(); |
|
49 } |
|
50 this.media.setCurrentTime = function(_milliseconds) { |
|
51 return _popcorn.currentTime(_milliseconds / 1000); |
|
52 } |
|
53 this.media.setVolume = function(_vol) { |
|
54 return _popcorn.volume(_vol); |
|
55 } |
|
56 this.media.mute = function() { |
|
57 return _popcorn.muted(true); |
|
58 } |
|
59 this.media.unmute = function() { |
|
60 return _popcorn.muted(false); |
|
61 } |
|
62 this.media.play = function() { |
|
63 return _popcorn.play(); |
|
64 } |
|
65 this.media.pause = function() { |
|
66 return _popcorn.pause(); |
|
67 } |
|
68 |
|
69 // Binding Popcorn events to media |
|
70 |
|
71 var _media = this.media; |
|
72 _popcorn.on("timeupdate", function() { |
|
73 _media.trigger("timeupdate", _media.getCurrentTime()); |
|
74 }); |
|
75 |
|
76 function simpleEventBind(_eventname) { |
|
77 _popcorn.on(_eventname, function() { |
|
78 _media.trigger(_eventname); |
|
79 }); |
|
80 } |
|
81 |
|
82 simpleEventBind("play"); |
|
83 simpleEventBind("pause"); |
|
84 simpleEventBind("seeked"); |
|
85 simpleEventBind("loadedmetadata"); |
|
86 simpleEventBind("volumechange"); |
|
87 |
|
88 } |