first demo of an Streaminginterface with VLC Browserplugins
[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
10 var tplVLCBouquetListItem  = '<tr>\n';
11         tplVLCBouquetListItem += '<td><div class="navMenuItem"  id="%(servicereference)" onclick="loadVLCBouquet(this.id);">%(bouquetname)</div></td>';
12         tplVLCBouquetListItem += '</tr>\n';
13
14 var tplVLCBouquetListFooter = "</table>";
15
16 // Bouquetlist Template
17 var tplVLCServiceListHeader = '<select id="channelselect" onChange="onServiceSelected()" width="150px"><option selected>choose Service</option>';
18
19 var tplVLCServiceListItem  = '<option id="%(servicereference)" >%(servicename)</option>';
20
21 var tplVLCServiceListFooter = "</select>";
22
23 // current EPG Template
24 var tplVLCEPGItem = '<div class="currentServiceEPGStarttime">%(starttime)</div><div  class="currentServiceEPGTitle">%(title)</div><div class="currentServiceEPGDuration">%(duration)&nbsp;Min.</div>';
25
26 function isIE(){
27         if(navigator.userAgent.indexOf("MSIE") >=0){ 
28         return true;
29         }else{
30                 return false;
31         }
32         
33 }
34 function getVersion() {
35         if(isIE()){
36                 var vstr = document.vlc.VersionInfo;
37                 var words = vstr.split(" ");
38                 return words[0];
39         }else if(navigator.plugins) {
40                 var plug = navigator.plugins['VLC multimedia plugin'];
41                 if(typeof plug == 'undefined')
42                         var plug = navigator.plugins['VLC Multimedia Plugin'];
43                 var ex = /^.*[vV]ersion [\"]*([^ \"]*)[\"]*.*$/;
44                 var ve = ex.exec(plug.description);
45                 if(ve[1]){
46                         return ve[1];
47                 }else{
48                         return "0.0.0";
49                 }
50         }else{
51                 return "0.0.0";
52         }
53 }
54 function plugintype(){
55                 var ex = /([^\.]*)[\.]*([^\.]*)[\.]*([^\.-]*)[\.-]*([^\.]*).*$/;
56                 var ve = ex.exec(getVersion());
57                 if(ve.length >1)        version_level1 = ve[1];
58                 if(ve.length >2)        version_level2 = ve[2];
59                 if(ve.length >3 && ve[3] != "") version_level3 = ve[3];
60                 if(ve.length >4 && ve[4] != "") version_level4 = ve[4];
61                 if(isIE())
62                         return "ie1";
63                 else
64                         if(version_level1 <= "0" && version_level2 <= "8" && version_level3 <= "5")
65                                 return "moz1";
66                         else
67                                 return "moz2";
68 }
69 function onStart(){
70         DBG = true;
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_fetchchannels+encodeURIComponent(bouqet_tv);
91         doRequest(url, incomingVLCTVBouquetList);
92
93         var url = url_fetchchannels+encodeURIComponent(bouqet_radio);
94         doRequest(url, incomingVLCRadioBouquetList);
95
96         var url = url_fetchchannels+encodeURIComponent(bouqet_provider_tv);
97         doRequest(url, incomingVLCProviderTVBouquetList);
98
99         var url = url_fetchchannels+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         $('currentServiceName').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                 $('currentServiceEPG').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_fetchchannels+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
227         $('vlcbuttons').innerHTML = htmlbuttons;
228 }
229
230
231 function play(){
232         if(isIE()){
233                 document.vlc.play();
234         }else{
235                 document.vlc.play();
236         }
237 }
238 function pause(){
239         if(isIE()){
240                 document.vlc.playlist.togglePause()
241         }else{
242                 document.vlc.pause();
243         }
244 }
245 function stop(){
246         if(isIE()){
247                 debug("ie stop");
248                 document.vlc.stop();
249         }else{
250                 document.vlc.stop();
251         }
252 }
253 function volumeUpVLC(){
254         debug("volumeUpVLC");   
255 }
256 function volumeDownVLC(){
257         debug("volumeUpVLC");
258 }
259 function muteVLC(){
260         debug("muteVLC");
261         if(isIE()) {
262                 document.vlc.toggleMute();
263         }else{
264                 document.vlc.mute();
265         }
266 }
267 function fullscreen(){
268         try{
269                 if(isIE()) {
270                         document.vlc.fullscreen();
271                 }else{
272                         document.vlc.fullscreen();
273                 }
274         }catch(e){debug(e);}
275 }
276 function setStreamTarget(servicereference){
277         debug("setStreamTarget "+servicereference);
278         url = '/web/stream.m3u?ref='+decodeURIComponent(servicereference);
279         if(isIE()){
280                 debug("ie setStreamTarget");
281                 document.vlc.playlistClear();
282                 document.vlc.addTarget(url, null, 2,0);
283                 play();
284                                 
285         }else{
286                 document.vlc.clear_playlist();
287                 document.vlc.add_item(url);
288                 play();
289         }
290
291 }