make streaminterface work again (not yet done)
[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 play(){
93         vlc.playlist.play();
94         
95         iterator = vlc.log.messages.iterator();
96         while(iterator.hasNext)
97         {
98                 debug("Message: " + iterator.next().message);
99         }
100 }
101
102 function prev(){
103         vlc.playlist.prev();
104 }
105
106 function next(){
107         vlc.playlist.next();
108 }
109
110 function pause(){
111         vlc.playlist.togglePause()
112 }
113
114 function stop(){
115         vlc.playlist.stop();
116 }
117
118 function volumeUpVLC(){
119         debug("Volume: " + vlc.audio.volume);
120         vlc.audio.volume += 10;
121 }
122
123 function volumeDownVLC(){
124         debug("Volume: " + vlc.audio.volume);
125         vlc.audio.volume -= 10;
126 }
127
128 function toogleMuteVLC(){
129         vlc.audio.mute = !vlc.audio.mute;
130 }
131
132 function fullscreen(){
133         try{
134                 vlc.video.fullscreen = true;
135         }catch(e){
136                 debug(e);
137         }
138 }
139 function setStreamTarget(servicereference){
140         host = top.location.host;
141         debug("Host: " + host);
142         
143         url = 'http://'+host+':8001/'+decodeURIComponent(servicereference);
144         debug("setStreamTarget " + url);
145         
146         vlc.playlist.add(url);
147         
148         if(vlc.playlist.isPlaying){
149                 vlc.playlist.next();
150         } else {
151                 play();
152         }
153         
154         debug("VLC-Version: " + vlc.VersionInfo);
155
156 }
157
158 function loadBouquets(){
159         url = url_getServices + bouquetsTv;
160         doRequest(url, incomingVLCBouquetList)
161 }
162
163 function initWebTv(){
164         if(DBG){
165                 loadAndOpenDebug();             
166         }
167         
168         vlc = $("vlc");
169 //      vlc.log.verbosity = 0;
170         loadBouquets();
171 }
172
173