Changes:
[enigma2-plugins.git] / webinterface / src / web-data / vlcplayer.js
1 var vlc = '';
2 var currentServiceRef = '';
3 var bouquetUpdatePoller = '';
4 var currentBouquetRef = '';
5 /*
6  * incoming request-data for Current Service Epg
7  */
8 function incomingVLCServiceEPG(request) {
9         if (request.readyState == 4) {
10                 var events = getXML(request).getElementsByTagName("e2eventlist")
11                                 .item(0).getElementsByTagName("e2event");
12
13                 var event = new EPGEvent(events.item(0)).toJSON();
14
15                 var data = {
16                         'current' : event
17                 };
18                 processTpl('streaminterface/tplCurrent', data, 'current');
19         }
20 }
21
22 /*
23  * Load Now information for Service
24  */
25 function loadVLCEPGServiceNow(servicereference) {
26         doRequest(URL.epgservicenow + servicereference, incomingVLCServiceEPG);
27 }
28
29 function onServiceSelected() {
30         currentServiceRef = $('channelSelect').options[$('channelSelect').selectedIndex].id;
31         
32         if(currentServiceRef !== "vlcemptyservice"){
33                 loadVLCEPGServiceNow(currentServiceRef);
34                 setStreamTarget(currentServiceRef);
35                 
36                 if($('vlcZap').checked){                        
37                         doRequest("/web/zap?sRef=" + currentServiceRef);                        
38                 }
39                 delayedLoadVlcSubservices();
40         } else {
41                 vlcStop();
42         }
43 }
44
45 function incomingVLCBouquetList(request) {
46         if (request.readyState == 4) {
47                 var services = new ServiceList(getXML(request)).getArray();
48
49                 data = {
50                         bouquets : services
51                 };
52
53                 processTpl('streaminterface/tplBouquetList', data, 'bouquetList');
54                 loadVLCBouquet(services[0].servicereference);
55         }
56 }
57 function reloadVLCBouquet(){
58         loadVLCBouquet(currentBouquetRef);
59 }
60
61
62 function loadVLCBouquet(servicereference) {
63 //      clearInterval(bouquetUpdatePoller);     
64         currentBouquetRef = servicereference;
65         
66         loadVLCChannelList(servicereference);
67         
68 //      bouquetUpdatePoller = setInterval(reloadVLCBouquet, 30000);
69 }
70
71 function incomingVLCSubservices(request){
72         if (request.readyState == 4) {
73                 var services = new ServiceList(getXML(request)).getArray();
74                 debug("[incomincVLCSubservices] Got " + services.length + " SubServices");
75                 
76                 if(services.length > 1) {
77
78                         var first = services[0];
79                         
80                         var lastoption = $(services[0].servicereference);
81                         
82                         if(lastoption !== null){
83                                 // we already have the main service in our servicelist so we'll
84                                 // start with the second element
85                                 for ( var i = 1; i < services.length ; i++){
86                                         var service = services[i];
87                                         
88                                         //TODO: FIX THIS UGLY CODE
89                                         var option = $(service.servicereference);
90                                         if(option !== null){
91                                                 option.remove();
92                                         }
93                                         option = new Option(' |- ' + service.servicename);
94                                         option.id =  service.servicereference;
95                                         
96                                         lastoption.insert( { after : option } );
97                                         
98                                         lastoption = option;
99                                 }
100                         }
101                 }
102         }
103 }
104
105 function loadVlcSubservices(){
106         var url = URL.streamsubservices + currentServiceRef;
107         doRequest(url, incomingVLCSubservices);
108 }
109
110 function delayedLoadVlcSubservices(){
111         setTimeout(loadVlcSubservices, 7500);
112 }
113
114 /*
115  * Incoming request-data for EPG Now information
116  * Builds the Channellist
117  */
118 function incomingVLCChannelList(request) {
119         if (request.readyState == 4) {
120                 var events = new EPGList(getXML(request)).getArray();
121
122                 var data = {
123                         'events' : events
124                 };
125                 processTpl('streaminterface/tplServiceList', data, 'channelList');
126         }
127 }
128
129 /*
130  * Load List of all Channels with epg now where available
131  */
132 function loadVLCChannelList(bouquetreference) {
133         doRequest(URL.epgnow + bouquetreference, incomingVLCChannelList);
134 }
135
136 function vlcPlay() {
137         try {
138                 onServiceSelected();
139         } catch (e) {
140                 notify("Nothing to play", false);
141         }
142 }
143
144 function vlcPrev() {
145         if ($('channelSelect').selectedIndex > 0) {
146                 $('channelSelect').selectedIndex -= 1;
147                 onServiceSelected();
148         }
149 }
150
151 function vlcNext() {
152         if ($('channelSelect').selectedIndex < $('channelSelect').length - 1) {
153                 $('channelSelect').selectedIndex += 1;
154                 onServiceSelected();
155         }
156 }
157
158 function vlcPause() {
159         vlc.playlist.togglePause();
160 }
161
162 function vlcStop() {
163         try {
164                 vlc.playlist.stop();
165         } catch (e) {
166                 notify("Nothing to stop", false);
167         }
168 }
169
170 function vlcVolumeUp() {
171         if (vlc.audio.volume < 200) {
172                 if (vlc.audio.volume + 10 > 200) {
173                         vlc.audio.volume = 200;
174                 } else {
175                         vlc.audio.volume += 10;
176                 }
177         }
178
179         set('vlcVolume', vlc.audio.volume);
180 }
181
182 function vlcVolumeDown() {
183         if (vlc.audio.volume > 0) {
184                 if (vlc.audio.volume < 10) {
185                         vlc.audio.volume = 0;
186                 } else {
187                         vlc.audio.volume -= 10;
188                 }
189         }
190
191         set('vlcVolume', vlc.audio.volume);
192 }
193
194 function vlcToogleMute() {
195         vlc.audio.mute = !vlc.audio.mute;
196         if (vlc.audio.mute) {
197                 set('vlcVolume', 'Muted');
198         } else {
199                 set('vlcVolume', vlc.audio.volume);
200         }
201 }
202
203 function vlcFullscreen() {
204         if (vlc.playlist.isPlaying) {
205                 if (vlc.input.hasVout) {
206                         vlc.video.fullscreen = true;
207                         return;
208                 }
209         }
210
211         notify("Cannot enable fullscreen mode when no Video is being played!",
212                         false);
213 }
214
215 function vlcTeletext() {
216         try {
217                 vlc.video.teletext = 100;
218         } catch (e) {
219                 debug("Error - Could not set teletext");
220         }
221         debug("Current Teletext Page:" + vlc.video.teletext);
222 }
223
224 function playUrl(url) {
225         current = vlc.playlist.add(url);
226         vlc.playlist.playItem(current);
227 }
228
229 function setStreamTarget(servicereference) {
230         host = top.location.host;
231         url = 'http://' + host + ':8001/' + decodeURIComponent(servicereference);
232
233         debug("setStreamTarget " + url);
234         vlc.playlist.clear();
235         playUrl(url);
236 }
237
238 function loadVLCBouquets() {
239         url = URL.getservices + bouquetsTv;
240         doRequest(url, incomingVLCBouquetList);
241         
242 }
243
244 /*
245  * Event when the user selected a Bouquet in the bouquets <select>
246  */
247 function onBouquetSelected() {
248         var servicereference = $('bouquetSelect').options[$('bouquetSelect').selectedIndex].id;
249         loadVLCBouquet(servicereference);
250 }
251
252 function initWebTv() {
253         var DBG = userprefs.data.debug || false;
254         if (DBG) {
255                 openDebug();
256         }
257
258         vlc = $('vlc');
259
260         try {
261                 set('vlcVolume', vlc.audio.volume);
262         } catch (e) {
263                 debug('[initWebTv] Error on initializing WebTv');
264         }
265
266         loadVLCBouquets();
267 }