[WebIf] Add Deinterlace option to WebTv
[enigma2-plugins.git] / webinterface / src / web-data / vlcplayer.js
1 var VlcBouquetListHandler = Class.create(AbstractContentHandler, {
2         initialize: function($super, target){
3                 $super('streaminterface/tplBouquetList', target);
4                 this.provider = new SimpleServiceListProvider(this.show.bind(this));
5         }
6 });
7
8 var VlcServiceListHandler = Class.create(AbstractContentHandler, {
9         initialize: function($super, target){
10                 $super('streaminterface/tplServiceList', target, [this.getSubservices.bind(this)]);
11
12                 this.provider = new ServiceListProvider(this.show.bind(this));
13 //              this.subServiceHandler = new ServiceListSubserviceHandler();
14         },
15
16         /**
17          * getSubservices
18          * calls this.subServiceHandler.load() to show Now/Next epg information
19          */
20         getSubservices: function(){
21 //              this.subServiceHandler.load({});
22         },
23
24         /**
25          * call this to switch to a service
26          * Parameters:
27          * @servicereference - the (unescaped) reference to the service that should be shown
28          */
29         zap: function(parms){
30                 this.provider.simpleResultQuery(URL.zap, parms, this.simpleResultCallback.bind(this));
31         },
32
33         showSimpleResult: function($super, result){
34                 if(result.getState()){
35                         core.updateItemsLazy();
36                 }
37                 $super(result);
38         }
39 });
40
41 var WebTv = Class.create({
42         initialize: function(vlcObjectTarget){
43                 this.target = vlcObjectTarget;
44                 this.instance = null;
45                 this.bouquetHandler = new VlcBouquetListHandler('bouquetList');
46                 this.serviceHandler = new VlcServiceListHandler('serviceList');
47                 this.bouquetHandler.onFinished.push(this.onLoadBouquetFinished.bind(this));
48         },
49
50         run: function(){
51                 this.instance = $(this.target);
52
53                 try {
54                         $('vlcVolume').update(this.instance.audio.volume);
55                 } catch (e) {
56                         debug('[WebTv].run Error on initializing WebTv');
57                 }
58                 this.registerEvents();
59                 this.bouquetHandler.load({'bRef' : bouquetsTv});
60         },
61
62         onLoadBouquetFinished: function(){
63                 var bref = decodeURIComponent( this.bouquetHandler.data.services[0].servicereference );
64                 this.serviceHandler.load({'bRef' : bref});
65         },
66
67
68         registerEvents: function(){
69                 $('bouquetList').on(
70                         'change',
71                         '.bouquets',
72                         function(event, element){
73                                 var bref = decodeURIComponent ( $('bouquets').options[$('bouquets').selectedIndex].id );
74                                 this.serviceHandler.load({ 'bRef' : bref });
75                         }.bind(this)
76                 );
77
78                 $('deinterlace').on(
79                         'change',
80                         function(event, element){
81                                 this.setDeinterlace(element);
82                         }.bind(this)
83                 );
84
85                 $('serviceList').on(
86                         'change',
87                         '.services',
88                         function(event, element){
89                                 this.onServiceChanged();
90                         }.bind(this)
91                 );
92
93                 var buttons = $('vlcButtons');
94                 buttons.on(
95                         'click',
96                         '.vlcPrev',
97                         function(event, element){
98                                 this.prev();
99                         }.bind(this)
100                 );
101                 buttons.on(
102                         'click',
103                         '.vlcPlay',
104                         function(event, element){
105                                 this.play();
106                         }.bind(this)
107                 );
108                 buttons.on(
109                         'click',
110                         '.vlcNext',
111                         function(event, element){
112                                 this.next();
113                         }.bind(this)
114                 );
115                 buttons.on(
116                         'click',
117                         '.vlcStop',
118                         function(event, element){
119                                 this.stop();
120                         }.bind(this)
121                 );
122                 buttons.on(
123                         'click',
124                         '.vlcFullscreen',
125                         function(event, element){
126                                 this.fullscreen();
127                         }.bind(this)
128                 );
129                 buttons.on(
130                         'click',
131                         '.vlcTeletext',
132                         function(event, element){
133                                 this.teletext();
134                         }.bind(this)
135                 );
136                 buttons.on(
137                         'click',
138                         '.vlcVolumeDown',
139                         function(event, element){
140                                 this.volumeDown();
141                         }.bind(this)
142                 );
143                 buttons.on(
144                         'click',
145                         '.vlcVolumeUp',
146                         function(event, element){
147                                 this.volumeUp();
148                         }.bind(this)
149                 );
150                 buttons.on(
151                         'click',
152                         '.vlcToggleMute',
153                         function(event, element){
154                                 this.toggleMute();
155                         }.bind(this)
156                 );
157         },
158
159         onServiceChanged: function(){
160                 var sref = decodeURIComponent (  $('services').options[$('services').selectedIndex].id );
161                 this.setStreamTarget(sref);
162                 this.setDeinterlace($('deinterlace'));
163         },
164
165         setDeinterlace: function(element){
166                 var modes = ["blend", "bob", "discard", "linear", "mean", "x", "yadif", "yadif2x"];
167                 var value = element.value;
168                 if(value != "off" && modes.indexOf(value) >= 0){
169                         this.instance.video.deinterlace.enable(value);
170                 } else {
171                         this.instance.video.deinterlace.disable();
172                 }
173         },
174
175         play: function() {
176                 try {
177                         this.onServiceChanged();
178                 } catch (e) {
179                         notify("Nothing to play", false);
180                 }
181         },
182
183         prev: function() {
184                 if ($('services').selectedIndex > 0) {
185                         $('services').selectedIndex -= 1;
186                         this.onServiceChanged();
187                 }
188         },
189
190         next: function() {
191                 if ($('services').selectedIndex < $('services').length - 1) {
192                         $('services').selectedIndex += 1;
193                         this.onServiceChanged();
194                 }
195         },
196
197         pause: function() {
198                 this.instance.playlist.togglePause();
199         },
200
201         stop: function() {
202                 try {
203                         this.instance.playlist.stop();
204                 } catch (e) {
205                         notify("Nothing to stop", false);
206                 }
207         },
208
209         volumeUp: function() {
210                 if (this.instance.audio.volume < 200) {
211                         if (this.instance.audio.volume + 10 > 200) {
212                                 this.instance.audio.volume = 200;
213                         } else {
214                                 this.instance.audio.volume += 10;
215                         }
216                 }
217
218                 $('vlcVolume').update(this.instance.audio.volume);
219         },
220
221         volumeDown: function() {
222                 if (this.instance.audio.volume > 0) {
223                         if (this.instance.audio.volume < 10) {
224                                 this.instance.audio.volume = 0;
225                         } else {
226                                 this.instance.audio.volume -= 10;
227                         }
228                 }
229
230                 $('vlcVolume').update(this.instance.audio.volume);
231         },
232
233         toggleMute: function() {
234                 this.instance.audio.mute = !this.instance.audio.mute;
235                 if (this.instance.audio.mute) {
236                         $('vlcVolume').update('Muted');
237                 } else {
238                         $('vlcVolume').update(this.instance.audio.volume);
239                 }
240         },
241
242         fullscreen: function() {
243                 if (this.instance.playlist.isPlaying) {
244                         if (this.instance.input.hasVout) {
245                                 this.instance.video.fullscreen = true;
246                                 return;
247                         }
248                 }
249
250                 notify("Cannot enable fullscreen mode when no Video is being played!",
251                                 false);
252         },
253
254         teletext: function() {
255                 try {
256                         this.instance.video.teletext = 100;
257                 } catch (e) {
258                         debug("Error - Could not set teletext");
259                 }
260                 debug("Current Teletext Page:" + this.instance.video.teletext);
261         },
262
263         playUrl: function(url) {
264                 current = this.instance.playlist.add(url);
265                 this.instance.playlist.playItem(current);
266                 $('vlcVolume').update(this.instance.audio.volume);
267         },
268
269         setStreamTarget: function(servicereference) {
270                 host = top.location.host;
271                 url = 'http://' + host + ':8001/' + decodeURIComponent(servicereference);
272
273                 debug("setStreamTarget " + url);
274                 this.instance.playlist.clear();
275                 this.playUrl(url);
276         },
277
278         notify: function(text, state){
279                 debug("[E2WebCore].notify");
280                 notif = $('notification');
281
282                 if(notif !== null){
283                         //clear possibly existing hideNotifier timeout of a previous notfication
284                         clearTimeout(this.hideNotifierTimeout);
285                         if(state === false){
286                                 notif.style.background = "#C00";
287                         } else {
288                                 notif.style.background = "#85C247";
289                         }
290
291                         this.set('notification', "<div>"+text+"</div>");
292                         notif.fadeIn({'delay' : 500, 'to' : 90});
293                         var _this = this;
294                         this.hideNotifierTimeout = setTimeout(_this.hideNotifier.bind(this), 5000);
295                 }
296         },
297
298         getBaseHash: function(){
299                 return '#';
300         }
301 });
302
303 core = new WebTv('vlc');