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