Change behaviour of /web/epgnow and /web/epgnext when getting the epg of a bouquet.
[enigma2-plugins.git] / webinterface / src / web-data / vlcplayer.js
1 var vlc = '';
2 // current EPG Template
3 var tplVLCEPGItem = '<div class="currentServiceEPGStarttime">%(starttime)</div><div  class="currentServiceEPGTitle">%(title)</div><div class="currentServiceEPGDuration">%(duration)&nbsp;Min.</div>';
4
5
6 function getVersion() {
7         var vstr = vlc.VersionInfo;
8         var words = vstr.split(" ");
9         return words[0];
10 }
11
12
13 function onServiceSelected(){
14         var servicereference =$('channelSelect').options[$('channelSelect').selectedIndex].id;
15 //      $('currentName').innerHTML = $('channelSelect').options[$('channelSelect').selectedIndex].value;
16
17         loadEPG(servicereference);      
18         setStreamTarget(servicereference);
19 }
20
21 function onBouquetSelected(){   
22         var servicereference =$('bouquetSelect').options[$('bouquetSelect').selectedIndex].id;  
23         loadVLCBouquet(servicereference);
24 }
25
26 function loadEPG(servicereference){
27         doRequest(url_epgservice+servicereference, incomingVLCServiceEPG);
28 }
29
30 function incomingVLCEpgNow(request){
31         if (request.readyState == 4) {
32                 var events = getXML(request).getElementsByTagName("e2eventlist").item(0).getElementsByTagName("e2event");                       
33
34                 var namespace = [];
35
36                 for(var i = 0; i < events.length; i++){
37                         var event = new EPGEvent(events.item(i));
38                         var eventname = event.getTitle();
39                 
40                         if(eventname.length > 40){
41                                 eventname = eventname.substring(0, 40) + '...';
42                         }
43                         
44                         namespace[i] = {
45                                 'servicereference' : event.getServiceReference(),
46                                 'servicename' : event.getServiceName(),
47                                 'eventname' : eventname,
48                                 'duration' : ( parseInt( (event.duration/60) , 10) )
49                         };
50                 }
51                 
52                 var data = { 'services' : namespace };          
53                 processTpl('streaminterface/tplServiceList', data, 'channelList');
54         }       
55 }
56
57 function loadVLCEpgNow(bouquetreference){
58         doRequest(url_epgnow+bouquetreference, incomingVLCEpgNow);
59 }
60
61
62 function incomingVLCServiceEPG(request){
63         if (request.readyState == 4) {
64                 var events = getXML(request).getElementsByTagName("e2eventlist").item(0).getElementsByTagName("e2event");                       
65                 
66                 var event =new EPGEvent(events.item(0));
67                 var namespace = {
68                                 'servicename' : event.getServiceName(),
69                                 'eventname': event.getTitle(),
70                                 'duration': ( parseInt( (event.duration/60) , 10) )                             
71                                 };
72                 
73                 var data = { 'current' : namespace };           
74                 processTpl('streaminterface/tplCurrent', data, 'current');              
75         }
76 }
77
78 function incomingVLCBouquetList(request){
79         if (request.readyState == 4) {
80                 var bouquets = new ServiceList(getXML(request)).getArray();
81                 
82                 var namespace = [];
83                 for(var i = 0; i < bouquets.length; i++){
84                         var bouquet = bouquets[i];
85                         
86                         namespace[i] = {
87                                         "servicereference"      : bouquet.getServiceReference(),
88                                         "servicename"           : bouquet.getServiceName()
89                         };
90                 }
91                 data = { bouquets : namespace };
92                 
93                 processTpl('streaminterface/tplBouquetList', data, 'bouquetList');
94                 loadVLCBouquet(bouquets[0].getServiceReference());
95         }
96 }
97
98
99 function loadVLCBouquet(servicereference){ 
100         loadVLCEpgNow(servicereference);        
101 }
102
103 function incomingVLCChannellist(request){
104         if(request.readyState == 4){
105                 var services = new ServiceList(getXML(request)).getArray();
106                                 
107                 debug("got "+services.length+" Services");
108                 
109                 namespace = [];
110                 
111                 for ( var i = 0; i < services.length ; i++){
112                         var service = services[i];
113                         namespace[i] = {        'servicereference': service.getServiceReference(),
114                                                                 'servicename': service.getServiceName() 
115                                                         };
116                         
117                         
118                 }
119                 var data = { services : namespace };
120                 
121                 processTpl('streaminterface/tplServiceList', data, 'channelList');              
122         }
123 }
124
125 function vlcPlay(){
126         try{
127                 onServiceSelected();
128         } catch(e){
129                 notify("Nothing to play", false);
130         }
131 }
132
133 function vlcPrev(){
134         if(     $('channelSelect').selectedIndex > 0 ){ 
135                 $('channelSelect').selectedIndex -= 1;
136                 onServiceSelected();
137         }
138 }
139
140 function vlcNext(){
141         if($('channelSelect').selectedIndex < $('channelSelect').length - 1 ){
142                 $('channelSelect').selectedIndex += 1;
143                 onServiceSelected();
144         }
145 }
146
147 function vlcPause(){
148         vlc.playlist.togglePause();
149 }
150
151 function vlcStop(){
152         try{
153                 vlc.playlist.stop();
154         } catch(e) {
155                 notify("Nothing to stop", false);
156         }
157 }
158
159 function vlcVolumeUp(){
160         if(vlc.audio.volume < 200){
161                 if(vlc.audio.volume + 10 > 200){
162                         vlc.audio.volume = 200;
163                 } else {
164                         vlc.audio.volume += 10;
165                 }
166         }
167         
168         set('vlcVolume', vlc.audio.volume);
169 }
170
171 function vlcVolumeDown(){
172         if(vlc.audio.volume > 0){
173                 if(vlc.audio.volume < 10){
174                         vlc.audio.volume = 0;
175                 } else {
176                         vlc.audio.volume -= 10;
177                 }
178         }
179         
180         set('vlcVolume', vlc.audio.volume);
181 }
182
183 function vlcToogleMute(){
184         vlc.audio.mute = !vlc.audio.mute;
185         if(vlc.audio.mute){
186                 set('vlcVolume', 'Muted');
187         } else {
188                 set('vlcVolume', vlc.audio.volume);
189         }
190 }
191
192 function vlcFullscreen(){       
193         if(vlc.playlist.isPlaying){
194                 if(vlc.input.hasVout){
195                         vlc.video.fullscreen = true;
196                         return;
197                 } 
198         }
199
200         notify("Cannot enable fullscreen mode when no Video is being played!", false);
201 }
202
203 function vlcTeletext(){
204         try{
205                 vlc.video.teletext = 100;
206         } catch(e) {
207                 debug("Error - Could not set teletext");
208         }
209         debug("Current Teletext Page:" + vlc.video.teletext);
210 }
211
212 function setStreamTarget(servicereference){
213         host = top.location.host;
214         
215         url = 'http://'+host+':8001/'+decodeURIComponent(servicereference);
216         debug("setStreamTarget " + url);
217         
218         vlc.playlist.add(url);
219         
220         if(vlc.playlist.isPlaying){
221                 vlc.playlist.next();
222         } else {
223                 vlc.playlist.play();
224         }
225 }
226
227 function loadBouquets(){
228         url = url_getServices + bouquetsTv;
229         doRequest(url, incomingVLCBouquetList);
230 }
231
232 function initWebTv(){
233         if(DBG){
234                 loadAndOpenDebug();             
235         }
236         
237         vlc = $("vlc");
238         
239         try{
240                 set('vlcVolume', vlc.audio.volume);
241         } catch (e){}
242 //      vlc.log.verbosity = 0;
243         loadBouquets();
244 }
245
246