* respect volume boundaries
[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         onServiceSelected();
94 }
95
96 function vlcPrev(){
97         if(     $('channelSelect').selectedIndex > 0 ){ 
98                 $('channelSelect').selectedIndex -= 1;
99                 onServiceSelected();
100         }
101 }
102
103 function vlcNext(){
104         if($('channelSelect').selectedIndex < $('channelSelect').length - 1 ){
105                 $('channelSelect').selectedIndex += 1;
106                 onServiceSelected();
107         }
108 }
109
110 function vlcPause(){
111         vlc.playlist.togglePause();
112 }
113
114 function vlcStop(){
115         vlc.playlist.stop();
116 }
117
118 function vlcVolumeUp(){
119         if(vlc.audio.volume < 200){
120                 if(vlc.audio.volume + 10 > 200){
121                         vlc.audio.volume = 200;
122                 } else {
123                         vlc.audio.volume += 10;
124                 }
125         }
126         
127         set('vlcVolume', vlc.audio.volume);
128 }
129
130 function vlcVolumeDown(){
131         if(vlc.audio.volume > 0){
132                 if(vlc.audio.volume < 10){
133                         vlc.audio.volume = 0;
134                 } else {
135                         vlc.audio.volume -= 10;
136                 }
137         }
138         
139         set('vlcVolume', vlc.audio.volume);
140 }
141
142 function vlcToogleMute(){
143         vlc.audio.mute = !vlc.audio.mute;
144         if(vlc.audio.mute){
145                 set('vlcVolume', 'Muted');
146         } else {
147                 set('vlcVolume', vlc.audio.volume);
148         }
149 }
150
151 function vlcFullscreen(){
152         try{
153                 vlc.video.fullscreen = true;
154         }catch(e){
155                 debug(e);
156         }
157 }
158
159 function vlcTeletext(){
160         try{
161                 vlc.video.teletext = 100;
162         } catch(e) {
163                 debug("Error - Could not set teletext");
164         }
165         debug("Current Teletext Page:" + vlc.video.teletext);
166 }
167
168 function setStreamTarget(servicereference){
169         host = top.location.host;
170         
171         url = 'http://'+host+':8001/'+decodeURIComponent(servicereference);
172         debug("setStreamTarget " + url);
173         
174         vlc.playlist.add(url);
175         
176         if(vlc.playlist.isPlaying){
177                 vlc.playlist.next();
178         } else {
179                 vlc.playlist.play();
180         }
181 }
182
183 function loadBouquets(){
184         url = url_getServices + bouquetsTv;
185         doRequest(url, incomingVLCBouquetList);
186 }
187
188 function initWebTv(){
189         if(DBG){
190                 loadAndOpenDebug();             
191         }
192         
193         vlc = $("vlc");
194         set('vlcVolume', vlc.audio.volume);
195 //      vlc.log.verbosity = 0;
196         loadBouquets();
197 }
198
199