add missing ;
[enigma2-plugins.git] / webinterface / src / web-data / vlcplayer.js
1 var list_tv_loaded = false;
2 var list_radio_loaded = false;
3 var list_provider_tv_loaded = false;
4 var list_provider_radio_loaded = false;
5
6
7 // Bouquetlist Template
8 var tplVLCBouquetListHeader = '<table id="BouquetList" width="100%" border="0" cellspacing="1" cellpadding="0" border="0">';
9 var tplVLCBouquetListItem  = '<tr>\n';
10         tplVLCBouquetListItem += '<td><div class="navMenuItem" id="%(servicereference)" onclick="loadVLCBouquet(this.id);">%(bouquetname)</div></td>';
11         tplVLCBouquetListItem += '</tr>\n';
12
13 var tplVLCBouquetListFooter = "</table>";
14
15 // Bouquetlist Template
16 var tplVLCServiceListHeader = '<select id="channelselect" onChange="onServiceSelected()" width="150px"><option selected>choose Service</option>';
17
18 var tplVLCServiceListItem  = '<option id="%(servicereference)" >%(servicename)</option>';
19
20 var tplVLCServiceListFooter = "</select>";
21
22 // current EPG Template
23 var tplVLCEPGItem = '<div class="currentServiceEPGStarttime">%(starttime)</div><div  class="currentServiceEPGTitle">%(title)</div><div class="currentServiceEPGDuration">%(duration)&nbsp;Min.</div>';
24
25 function isIE(){
26         if(navigator.userAgent.indexOf("MSIE") >=0){ 
27         return true;
28         }else{
29                 return false;
30         }
31         
32 }
33 function getVersion() {
34         if(isIE()){
35                 var vstr = document.vlc.VersionInfo;
36                 var words = vstr.split(" ");
37                 return words[0];
38         }else if(navigator.plugins) {
39                 var plug = navigator.plugins['VLC multimedia plugin'];
40                 if(typeof plug == 'undefined')
41                         var plug = navigator.plugins['VLC Multimedia Plugin'];
42                 var ex = /^.*[vV]ersion [\"]*([^ \"]*)[\"]*.*$/;
43                 var ve = ex.exec(plug.description);
44                 if(ve[1]){
45                         return ve[1];
46                 }else{
47                         return "0.0.0";
48                 }
49         }else{
50                 return "0.0.0";
51         }
52 }
53 function plugintype(){
54                 var ex = /([^\.]*)[\.]*([^\.]*)[\.]*([^\.-]*)[\.-]*([^\.]*).*$/;
55                 var ve = ex.exec(getVersion());
56                 if(ve.length >1)        version_level1 = ve[1];
57                 if(ve.length >2)        version_level2 = ve[2];
58                 if(ve.length >3 && ve[3] != "") version_level3 = ve[3];
59                 if(ve.length >4 && ve[4] != "") version_level4 = ve[4];
60                 if(isIE())
61                         return "ie1";
62                 else
63                         if(version_level1 <= "0" && version_level2 <= "8" && version_level3 <= "5")
64                                 return "moz1";
65                         else
66                                 return "moz2";
67 }
68 function onStart(){
69         DBG = true;
70         DBG = false;
71         if(DBG) { debugWin = openWindow("DEBUG", "", 300, 300, "debugWindow"); }
72         debug("startup");
73
74 var accordionOptions = {
75         expandedBg : 'transparent',
76         hoverBg : 'CCCCCC',
77         collapsedBg : 'transparent',
78         expandedTextColor : '#000000',
79         expandedFontWeight : 'bold',
80         hoverTextColor : '#000000',
81         collapsedTextColor : '#000000',
82         collapsedFontWeight : 'normal',
83         borderColor : '#EEEEEE',
84         border : '0',
85         panelHeight : 150
86 }
87
88 new Rico.Accordion( $('accordionMenue'), accordionOptions );
89         
90         var url = url_getServices+encodeURIComponent(bouqet_tv);
91         doRequest(url, incomingVLCTVBouquetList);
92
93         var url = url_getServices+encodeURIComponent(bouqet_radio);
94         doRequest(url, incomingVLCRadioBouquetList);
95
96         var url = url_getServices+encodeURIComponent(bouqet_provider_tv);
97         doRequest(url, incomingVLCProviderTVBouquetList);
98
99         var url = url_getServices+encodeURIComponent(bouqet_provider_radio);
100         doRequest(url, incomingVLCProviderRadioBouquetList);
101         buildButtons();
102         buildplayer(550,412);
103 //      buildplayer(720,576);
104         debug("VLC-Version: "+getVersion()+" "+plugintype());
105         
106 }
107 function onServiceSelected(){
108         var index = $('channelselect').selectedIndex;
109         var servicereference = $('channelselect').options[index].id;
110         $('CurrentService').innerHTML = $('channelselect').options[index].text;
111         loadEPG(servicereference);
112         setStreamTarget(servicereference);
113 }
114 function loadEPG(servicereference){
115         doRequest(url_epgservice+servicereference, incomingVLCServiceEPG);
116 }
117  
118 function incomingVLCServiceEPG(request){
119         if (request.readyState == 4) {
120                 var EPGItems = getXML(request).getElementsByTagName("e2eventlist").item(0).getElementsByTagName("e2event");                     
121                 var epg_current =new EPGEvent(EPGItems.item(0))
122                 var namespace = {
123                                 'title': epg_current.getTitle(),
124                                 'starttime': epg_current.getTimeStartString(),
125                                 'duration': (parseInt(epg_current.duration)/60)                         
126                                 };
127                 $('CurrentEvent').innerHTML =  RND(tplVLCEPGItem, namespace);
128                 
129         }
130 }
131 function incomingVLCTVBouquetList(request){
132         if (request.readyState == 4) {
133                 var list_tv = new ServiceList(getXML(request)).getArray();
134                 list_provider_tv_loaded = true;         
135                 $('accordionMenueBouquetContentTV').innerHTML = renderBouquetTable(list_tv,tplVLCBouquetListHeader,tplVLCBouquetListItem,tplVLCBouquetListFooter);
136                 loadVLCBouquet(list_tv[0].getServiceReference());
137         }
138 }
139 function incomingVLCRadioBouquetList(request){
140         if (request.readyState == 4) {
141                 var list_radio = new ServiceList(getXML(request)).getArray();
142                 list_radio_loaded = true;
143                 $('accordionMenueBouquetContentRadio').innerHTML = renderBouquetTable(list_radio,tplVLCBouquetListHeader,tplVLCBouquetListItem,tplVLCBouquetListFooter);
144         }
145 }
146 function incomingVLCProviderTVBouquetList(request){
147         if (request.readyState == 4) {
148                 var list_provider_tv = new ServiceList(getXML(request)).getArray();
149                 list_provider_tv_loaded = false;
150                 $('accordionMenueBouquetContentProviderTV').innerHTML = renderBouquetTable(list_provider_tv,tplVLCBouquetListHeader,tplVLCBouquetListItem,tplVLCBouquetListFooter);
151         }
152 }
153 function incomingVLCProviderRadioBouquetList(request){
154         if (request.readyState == 4) {
155                 var list_provider_radio = new ServiceList(getXML(request)).getArray();
156                 list_provider_radio_loaded = true;
157                 $('accordionMenueBouquetContentProviderRadio').innerHTML = renderBouquetTable(list_provider_radio,tplVLCBouquetListHeader,tplVLCBouquetListItem,tplVLCBouquetListFooter);
158         }
159 }
160 function loadVLCBouquet(servicereference){ 
161         debug("loading bouquet with "+servicereference);
162         servicereftoloadepgnow = servicereference;
163         doRequest(url_getServices+servicereference, incomingVLCChannellist);
164 }
165 function incomingVLCChannellist(request){
166         if(request.readyState == 4){
167                 var services = new ServiceList(getXML(request)).getArray();
168                 listerHtml      = tplVLCServiceListHeader;              
169                 debug("got "+services.length+" Services");
170                 for ( var i = 0; i < services.length ; i++){
171                         var reference = services[i];
172                         var namespace = {       'servicereference': reference.getServiceReference(),
173                                                                 'servicename': reference.getServiceName() 
174                                                         };
175                         listerHtml += RND(tplVLCServiceListItem, namespace);
176                 }               
177                 listerHtml += tplVLCServiceListFooter;
178                 document.getElementById('VLCChannellist').innerHTML = listerHtml;
179         }
180 }
181
182 function buildplayer( width, height){
183         if(isIE()){ 
184         buildPlayerIE( width, height);
185         }else{
186                 buildPlayer( width, height);
187         }
188 }
189
190 function buildPlayer( width, height){
191         var html  = '<embed type="application/x-vlc-plugin" ';
192         html += '    id="vlc"'; 
193         html += '    autoplay="yes" loop="yes"'; 
194         html += '    width="'+width+'"';
195         html += '    height="'+height+'"';
196         html += '  ></embed>';
197         $('vlcplayer').innerHTML =html;
198 }
199  
200 function buildPlayerIE( width, height){
201         var html  = '<OBJECT classid="clsid:E23FE9C6-778E-49D4-B537-38FCDE4887D8"'; 
202         html += '          codebase="cab/axvlc.cab"';
203         html += '          width="' + width + '"';
204         html += '          height="'+ height +'"'; 
205         html += '          id="vlc" ';
206         html += '          events="True" >'; 
207         html += '    <param name="Src" value="" />'; 
208         html += '    <param name="Visible" value="True" />'; 
209         html += '    <param name="AutoLoop" value="False" />';
210         html += '    <param name="AutoPlay" value="False" />'; 
211         html += '</OBJECT>';
212         $('vlcplayer').innerHTML = html;
213 }
214
215 function buildButtons(){
216         //TODO use nice GFX for buttons
217         var htmlbuttons  = '<button onClick="prev()">&lt;&lt;</button>';
218                 htmlbuttons += '<button onClick="play()">&gt;</button>';
219                 htmlbuttons += '<button onClick="next()">&gt;&gt;</button>';
220                 htmlbuttons += '<button onClick="pause()">||</button>';
221                 htmlbuttons += '<button onClick="stop()">stop</button>';
222                 htmlbuttons += '<button onClick="fullscreen()">Fullscreen</button>';
223                 htmlbuttons += '<button onClick="volumeUpVLC()">Vol+</button>';
224                 htmlbuttons += '<button onClick="muteVLC()">Mute</button>';
225                 htmlbuttons += '<button onClick="volumeDownVLC()">Vol-</button>';
226                 htmlbuttons += '<div id="VLCChannellist"></div>';
227
228         $('vlcbuttons').innerHTML = htmlbuttons;
229 }
230
231
232 function play(){
233         if(isIE()){
234                 document.vlc.play();
235         }else{
236                 document.vlc.play();
237         }
238 }
239 function pause(){
240         if(isIE()){
241                 document.vlc.playlist.togglePause()
242         }else{
243                 document.vlc.pause();
244         }
245 }
246 function stop(){
247         if(isIE()){
248                 debug("ie stop");
249                 document.vlc.stop();
250         }else{
251                 document.vlc.stop();
252         }
253 }
254 function volumeUpVLC(){
255         debug("volumeUpVLC");   
256 }
257 function volumeDownVLC(){
258         debug("volumeUpVLC");
259 }
260 function muteVLC(){
261         debug("muteVLC");
262         if(isIE()) {
263                 document.vlc.toggleMute();
264         }else{
265                 document.vlc.mute();
266         }
267 }
268 function fullscreen(){
269         try{
270                 if(isIE()) {
271                         document.vlc.fullscreen();
272                 }else{
273                         document.vlc.fullscreen();
274                 }
275         }catch(e){debug(e);}
276 }
277 function setStreamTarget(servicereference){
278         debug("setStreamTarget "+servicereference);
279         url = '/web/stream.m3u?ref='+decodeURIComponent(servicereference);
280         if(isIE()){
281                 debug("ie setStreamTarget");
282                 document.vlc.playlistClear();
283                 document.vlc.addTarget(url, null, 2,0);
284                 play();
285                                 
286         }else{
287                 document.vlc.clear_playlist();
288                 document.vlc.add_item(url);
289                 play();
290         }
291
292 }