rename getservices.m3u to services.m3u.
[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) {
72                 debugWin = openWindow("DEBUG", "", 300, 300, "debugWindow");
73         }
74         debug("startup");
75 }
76
77 var accordionOptions = {
78         expandedBg : 'transparent',
79         hoverBg : 'CCCCCC',
80         collapsedBg : 'transparent',
81         expandedTextColor : '#000000',
82         expandedFontWeight : 'bold',
83         hoverTextColor : '#000000',
84         collapsedTextColor : '#000000',
85         collapsedFontWeight : 'normal',
86         borderColor : '#EEEEEE',
87         border : '0',
88         panelHeight : 150
89 }
90
91 //new Rico.Accordion( $('accordionMenue'), accordionOptions );
92 //      
93 //      var url = url_getServices+encodeURIComponent(bouqet_tv);
94 //      doRequest(url, incomingVLCTVBouquetList);
95 //
96 //      var url = url_getServices+encodeURIComponent(bouqet_radio);
97 //      doRequest(url, incomingVLCRadioBouquetList);
98 //
99 //      var url = url_getServices+encodeURIComponent(bouqet_provider_tv);
100 //      doRequest(url, incomingVLCProviderTVBouquetList);
101 //
102 //      var url = url_getServices+encodeURIComponent(bouqet_provider_radio);
103 //      doRequest(url, incomingVLCProviderRadioBouquetList);
104 //      buildButtons();
105 //      buildplayer(550,412);
106 ////    buildplayer(720,576);
107 //      debug("VLC-Version: "+getVersion()+" "+plugintype());
108 //      
109 //}
110 function onServiceSelected(){
111         var index = $('channelselect').selectedIndex;
112         var servicereference = $('channelselect').options[index].id;
113         $('CurrentService').innerHTML = $('channelselect').options[index].text;
114         loadEPG(servicereference);
115         setStreamTarget(servicereference);
116 }
117 function loadEPG(servicereference){
118         doRequest(url_epgservice+servicereference, incomingVLCServiceEPG);
119 }
120  
121 function incomingVLCServiceEPG(request){
122         if (request.readyState == 4) {
123                 var EPGItems = getXML(request).getElementsByTagName("e2eventlist").item(0).getElementsByTagName("e2event");                     
124                 var epg_current =new EPGEvent(EPGItems.item(0))
125                 var namespace = {
126                                 'title': epg_current.getTitle(),
127                                 'starttime': epg_current.getTimeStartString(),
128                                 'duration': (parseInt(epg_current.duration)/60)                         
129                                 };
130                 $('CurrentEvent').innerHTML =  RND(tplVLCEPGItem, namespace);
131                 
132         }
133 }
134 function incomingVLCTVBouquetList(request){
135         if (request.readyState == 4) {
136                 var list_tv = new ServiceList(getXML(request)).getArray();
137                 list_provider_tv_loaded = true;         
138                 $('accordionMenueBouquetContentTV').innerHTML = renderBouquetTable(list_tv,tplVLCBouquetListHeader,tplVLCBouquetListItem,tplVLCBouquetListFooter);
139                 loadVLCBouquet(list_tv[0].getServiceReference());
140         }
141 }
142 function incomingVLCRadioBouquetList(request){
143         if (request.readyState == 4) {
144                 var list_radio = new ServiceList(getXML(request)).getArray();
145                 list_radio_loaded = true;
146                 $('accordionMenueBouquetContentRadio').innerHTML = renderBouquetTable(list_radio,tplVLCBouquetListHeader,tplVLCBouquetListItem,tplVLCBouquetListFooter);
147         }
148 }
149 function incomingVLCProviderTVBouquetList(request){
150         if (request.readyState == 4) {
151                 var list_provider_tv = new ServiceList(getXML(request)).getArray();
152                 list_provider_tv_loaded = false;
153                 $('accordionMenueBouquetContentProviderTV').innerHTML = renderBouquetTable(list_provider_tv,tplVLCBouquetListHeader,tplVLCBouquetListItem,tplVLCBouquetListFooter);
154         }
155 }
156 function incomingVLCProviderRadioBouquetList(request){
157         if (request.readyState == 4) {
158                 var list_provider_radio = new ServiceList(getXML(request)).getArray();
159                 list_provider_radio_loaded = true;
160                 $('accordionMenueBouquetContentProviderRadio').innerHTML = renderBouquetTable(list_provider_radio,tplVLCBouquetListHeader,tplVLCBouquetListItem,tplVLCBouquetListFooter);
161         }
162 }
163 function loadVLCBouquet(servicereference){ 
164         debug("loading bouquet with "+servicereference);
165         servicereftoloadepgnow = servicereference;
166         doRequest(url_getServices+servicereference, incomingVLCChannellist);
167 }
168 function incomingVLCChannellist(request){
169         if(request.readyState == 4){
170                 var services = new ServiceList(getXML(request)).getArray();
171                 listerHtml      = tplVLCServiceListHeader;              
172                 debug("got "+services.length+" Services");
173                 for ( var i = 0; i < services.length ; i++){
174                         var reference = services[i];
175                         var namespace = {       'servicereference': reference.getServiceReference(),
176                                                                 'servicename': reference.getServiceName() 
177                                                         };
178                         listerHtml += RND(tplVLCServiceListItem, namespace);
179                 }               
180                 listerHtml += tplVLCServiceListFooter;
181                 document.getElementById('VLCChannellist').innerHTML = listerHtml;
182         }
183 }
184
185 function buildplayer( width, height){
186         if(isIE()){ 
187         buildPlayerIE( width, height);
188         }else{
189                 buildPlayer( width, height);
190         }
191 }
192
193 function buildPlayer( width, height){
194         var html  = '<embed type="application/x-vlc-plugin" ';
195         html += '    id="vlc"'; 
196         html += '    autoplay="yes" loop="yes"'; 
197         html += '    width="'+width+'"';
198         html += '    height="'+height+'"';
199         html += '  ></embed>';
200         $('vlcplayer').innerHTML =html;
201 }
202  
203 function buildPlayerIE( width, height){
204         var html  = '<OBJECT classid="clsid:E23FE9C6-778E-49D4-B537-38FCDE4887D8"'; 
205         html += '          codebase="cab/axvlc.cab"';
206         html += '          width="' + width + '"';
207         html += '          height="'+ height +'"'; 
208         html += '          id="vlc" ';
209         html += '          events="True" >'; 
210         html += '    <param name="Src" value="" />'; 
211         html += '    <param name="Visible" value="True" />'; 
212         html += '    <param name="AutoLoop" value="False" />';
213         html += '    <param name="AutoPlay" value="False" />'; 
214         html += '</OBJECT>';
215         $('vlcplayer').innerHTML = html;
216 }
217
218 function buildButtons(){
219         //TODO use nice GFX for buttons
220         var htmlbuttons  = '<button onClick="prev()">&lt;&lt;</button>';
221                 htmlbuttons += '<button onClick="play()">&gt;</button>';
222                 htmlbuttons += '<button onClick="next()">&gt;&gt;</button>';
223                 htmlbuttons += '<button onClick="pause()">||</button>';
224                 htmlbuttons += '<button onClick="stop()">stop</button>';
225                 htmlbuttons += '<button onClick="fullscreen()">Fullscreen</button>';
226                 htmlbuttons += '<button onClick="volumeUpVLC()">Vol+</button>';
227                 htmlbuttons += '<button onClick="muteVLC()">Mute</button>';
228                 htmlbuttons += '<button onClick="volumeDownVLC()">Vol-</button>';
229                 htmlbuttons += '<div id="VLCChannellist"></div>';
230
231         $('vlcbuttons').innerHTML = htmlbuttons;
232 }
233
234
235 function play(){
236         if(isIE()){
237                 document.vlc.play();
238         }else{
239                 document.vlc.play();
240         }
241 }
242 function pause(){
243         if(isIE()){
244                 document.vlc.playlist.togglePause()
245         }else{
246                 document.vlc.pause();
247         }
248 }
249 function stop(){
250         if(isIE()){
251                 debug("ie stop");
252                 document.vlc.stop();
253         }else{
254                 document.vlc.stop();
255         }
256 }
257 function volumeUpVLC(){
258         debug("volumeUpVLC");   
259 }
260 function volumeDownVLC(){
261         debug("volumeUpVLC");
262 }
263 function muteVLC(){
264         debug("muteVLC");
265         if(isIE()) {
266                 document.vlc.toggleMute();
267         }else{
268                 document.vlc.mute();
269         }
270 }
271 function fullscreen(){
272         try{
273                 if(isIE()) {
274                         document.vlc.fullscreen();
275                 }else{
276                         document.vlc.fullscreen();
277                 }
278         }catch(e){debug(e);}
279 }
280 function setStreamTarget(servicereference){
281         debug("setStreamTarget "+servicereference);
282         url = '/web/stream.m3u?ref='+decodeURIComponent(servicereference);
283         if(isIE()){
284                 debug("ie setStreamTarget");
285                 document.vlc.playlistClear();
286                 document.vlc.addTarget(url, null, 2,0);
287                 play();
288                                 
289         }else{
290                 document.vlc.clear_playlist();
291                 document.vlc.add_item(url);
292                 play();
293         }
294
295 }