add some EPG-related Information for currently playing service.
[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 incomingVLCServiceEPG(request){
31         if (request.readyState == 4) {
32                 var EPGItems = getXML(request).getElementsByTagName("e2eventlist").item(0).getElementsByTagName("e2event");                     
33                 var epg_current =new EPGEvent(EPGItems.item(0));
34                 var namespace = {
35                                 'servicename' : epg_current.getServiceName(),
36                                 'eventname': epg_current.getTitle(),
37                                 'duration': (parseInt(epg_current.duration)/60, 10)                             
38                                 };
39                 
40                 var data = { 'current' : namespace };
41                 
42                 processTpl('streaminterface/tplCurrent', data, 'current');
43                 
44         }
45 }
46
47 function incomingVLCBouquetList(request){
48         if (request.readyState == 4) {
49                 var bouquets = new ServiceList(getXML(request)).getArray();
50                 
51                 var namespace = [];
52                 for(var i = 0; i < bouquets.length; i++){
53                         var bouquet = bouquets[i];
54                         
55                         namespace[i] = {
56                                         "servicereference"      : bouquet.getServiceReference(),
57                                         "servicename"           : bouquet.getServiceName()
58                         };
59                 }
60                 data = { bouquets : namespace };
61                 
62                 processTpl('streaminterface/tplBouquetList', data, 'bouquetList');
63                 loadVLCBouquet(bouquets[0].getServiceReference());
64         }
65 }
66
67
68 function loadVLCBouquet(servicereference){ 
69         servicereftoloadepgnow = servicereference;
70         doRequest(url_getServices+servicereference, incomingVLCChannellist);
71 }
72
73 function incomingVLCChannellist(request){
74         if(request.readyState == 4){
75                 var services = new ServiceList(getXML(request)).getArray();
76                                 
77                 debug("got "+services.length+" Services");
78                 
79                 namespace = [];
80                 
81                 for ( var i = 0; i < services.length ; i++){
82                         var reference = services[i];
83                         namespace[i] = {        'servicereference': reference.getServiceReference(),
84                                                                 'servicename': reference.getServiceName() 
85                                                         };
86                         
87                         
88                 }
89                 var data = { services : namespace };
90                 
91                 processTpl('streaminterface/tplServiceList', data, 'channelList');              
92         }
93 }
94
95 function vlcPlay(){
96         try{
97                 onServiceSelected();
98         } catch(e){
99                 notify("Nothing to play", false);
100         }
101 }
102
103 function vlcPrev(){
104         if(     $('channelSelect').selectedIndex > 0 ){ 
105                 $('channelSelect').selectedIndex -= 1;
106                 onServiceSelected();
107         }
108 }
109
110 function vlcNext(){
111         if($('channelSelect').selectedIndex < $('channelSelect').length - 1 ){
112                 $('channelSelect').selectedIndex += 1;
113                 onServiceSelected();
114         }
115 }
116
117 function vlcPause(){
118         vlc.playlist.togglePause();
119 }
120
121 function vlcStop(){
122         try{
123                 vlc.playlist.stop();
124         } catch(e) {
125                 notify("Nothing to stop", false);
126         }
127 }
128
129 function vlcVolumeUp(){
130         if(vlc.audio.volume < 200){
131                 if(vlc.audio.volume + 10 > 200){
132                         vlc.audio.volume = 200;
133                 } else {
134                         vlc.audio.volume += 10;
135                 }
136         }
137         
138         set('vlcVolume', vlc.audio.volume);
139 }
140
141 function vlcVolumeDown(){
142         if(vlc.audio.volume > 0){
143                 if(vlc.audio.volume < 10){
144                         vlc.audio.volume = 0;
145                 } else {
146                         vlc.audio.volume -= 10;
147                 }
148         }
149         
150         set('vlcVolume', vlc.audio.volume);
151 }
152
153 function vlcToogleMute(){
154         vlc.audio.mute = !vlc.audio.mute;
155         if(vlc.audio.mute){
156                 set('vlcVolume', 'Muted');
157         } else {
158                 set('vlcVolume', vlc.audio.volume);
159         }
160 }
161
162 function vlcFullscreen(){       
163         if(vlc.playlist.isPlaying){
164                 if(vlc.input.hasVout){
165                         vlc.video.fullscreen = true;
166                         return;
167                 } 
168         }
169
170         notify("Cannot enable fullscreen mode when no Video is being played!", false);
171 }
172
173 function vlcTeletext(){
174         try{
175                 vlc.video.teletext = 100;
176         } catch(e) {
177                 debug("Error - Could not set teletext");
178         }
179         debug("Current Teletext Page:" + vlc.video.teletext);
180 }
181
182 function setStreamTarget(servicereference){
183         host = top.location.host;
184         
185         url = 'http://'+host+':8001/'+decodeURIComponent(servicereference);
186         debug("setStreamTarget " + url);
187         
188         vlc.playlist.add(url);
189         
190         if(vlc.playlist.isPlaying){
191                 vlc.playlist.next();
192         } else {
193                 vlc.playlist.play();
194         }
195 }
196
197 function loadBouquets(){
198         url = url_getServices + bouquetsTv;
199         doRequest(url, incomingVLCBouquetList);
200 }
201
202 function initWebTv(){
203         if(DBG){
204                 loadAndOpenDebug();             
205         }
206         
207         vlc = $("vlc");
208         set('vlcVolume', vlc.audio.volume);
209 //      vlc.log.verbosity = 0;
210         loadBouquets();
211 }
212
213