Project

General

Profile

Feature #436 » tune_vlc_popup.patch

cyberjunk -, 2011-04-14 02:29

View differences:

tvheadend/src/webui/static/app/tvheadend.js 2011-04-14 01:28:40.000000000 +0200
31 31
 * Displays a mediaplayer using VLC plugin
32 32
 */
33 33
tvheadend.VLC = function(url) {
34
 
35
  function randomString() {
36
	var chars = "ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
37
	var string_length = 8;
38
	var randomstring = '';
39
	for (var i=0; i<string_length; i++) {
40
		var rnum = Math.floor(Math.random() * chars.length);
41
		randomstring += chars.substring(rnum,rnum+1);
42
	}
43
	return randomstring;
44
  }
34 45
  var vlc = document.createElement('embed');
35 46
  vlc.setAttribute('type', 'application/x-vlc-plugin');
36 47
  vlc.setAttribute('pluginspage', 'http://www.videolan.org');
37
  vlc.setAttribute('version', 'version="VideoLAN.VLCPlugin.2');
38
  vlc.setAttribute('width', '507');
39
  vlc.setAttribute('height', '384');
40
  vlc.setAttribute('autoplay', 'yes');
41
  vlc.setAttribute('id', 'vlc');
42
  if(url) {
43
    vlc.setAttribute('src', url);
44
  } else {
45
    vlc.style.display = 'none';
46
  }
48
  vlc.setAttribute('version', 'VideoLAN.VLCPlugin.2');
49
  vlc.setAttribute('width', '100%');
50
  vlc.setAttribute('height', '100%');
51
  vlc.setAttribute('autoplay', 'no');
52
  vlc.setAttribute('id', randomString());
47 53
  
48 54
  var missingPlugin = document.createElement('div');
49 55
  missingPlugin.style.display = 'none';
50 56
  missingPlugin.style.padding = '5px';
51

  
57
  
52 58
  var selectChannel = new Ext.form.ComboBox({
53 59
    loadingText: 'Loading...',
54 60
    width: 200,
......
61 67
  });
62 68
  
63 69
  selectChannel.on('select', function(c, r) {
64
      var url = 'stream/channelid/' + r.data.chid;
65
      var playlist = 'playlist/channelid/' + r.data.chid;
70
      var streamurl = 'stream/channelid/' + r.data.chid;
71
      var playlisturl = 'playlist/channelid/' + r.data.chid;
66 72

  
67
      var chName = r.data.name;
68
      if (!chName.length) {
69
	  chName = 'the stream';
70
      }
71

  
72
      vlc.style.display = 'block';
73
      // if the player was initialised, but not yet shown, make it visible
74
      if (vlc.playlist && (vlc.style.display == 'none'))
75
	vlc.style.display = 'block';
73 76

  
74 77
      if(!vlc.playlist || vlc.playlist == 'undefined') {
75
	  var innerHTML = '';
76
	  innerHTML += '<p>You are missing a plugin for your browser.'
77
	  innerHTML += 'You can still watch ' + chName;
78
	  innerHTML += ' using an external player.</p>';
79
	  innerHTML += '<p><a href="' + playlist + '">M3U Playlist</a></p>';
80
	  innerHTML += '<p><a href="' + url + '">Direct URL</a></p>';
81

  
82
	  missingPlugin.innerHTML = innerHTML;
83
	  vlc.style.display = 'none';
84
	  missingPlugin.style.display = 'block';
85
	  return;
78
	 missingPlugin.innerHTML  = '<p>Embedded player could not be started. <br> You are probably missing VLC Mozilla plugin for your browser.</p>';
79
	 missingPlugin.innerHTML += '<p><a href="' + playlisturl + '">M3U Playlist</a></p>';
80
	 missingPlugin.innerHTML += '<p><a href="' + streamurl + '">Direct URL</a></p>';
86 81
      }
87

  
88
      if(vlc.playlist && vlc.playlist.isPlaying) {
82
      else {
89 83
        vlc.playlist.stop();
90
      }
91
      if(vlc.playlist && vlc.playlist.items.count) {
92
        vlc.playlist.items.clear();
93
      }
94
      
95
      vlc.playlist.add(url, chName, "");
96
      vlc.playlist.play();
97
      vlc.audio.volume = slider.getValue();
84
   	 vlc.playlist.items.clear();
85
   	 vlc.playlist.add(streamurl);
86
    	 vlc.playlist.playItem(0);
87
     	 vlc.audio.volume = slider.getValue();
88
	}
98 89
    }
99 90
  );
100 91
  
......
125 116
    height: 384 + 56,
126 117
    constrainHeader: true,
127 118
    iconCls: 'eye',
128
    resizable: false,
119
    resizable: true,
129 120
    tbar: [
130 121
      selectChannel,
131 122
      '-',
......
151 142
        iconCls: 'control_stop',
152 143
        tooltip: 'Stop',
153 144
        handler: function() {
154
          if(vlc.playlist && vlc.playlist.items.count) {
145
          if(vlc.playlist) {
155 146
            vlc.playlist.stop();
156
            vlc.style.display = 'none';
157 147
          }
158 148
        }
159 149
      },
......
162 152
        iconCls: 'control_fullscreen',
163 153
        tooltip: 'Fullscreen',
164 154
        handler: function() {
165
          if(vlc.playlist && vlc.playlist.isPlaying) {
155
          if(vlc.playlist && vlc.playlist.isPlaying && (vlc.VersionInfo.substr(0,3) != '1.1')) {
166 156
            vlc.video.toggleFullscreen();
167 157
          }
158
	   else if (vlc.VersionInfo.substr(0,3) == '1.1') {
159
            alert('Fullscreen mode is broken in VLC 1.1.x');
160
          }
168 161
        }
169 162
      },
170 163
      '-',
......
177 170
    items: [vlc, missingPlugin]
178 171
  });
179 172
	  
180
  win.on('render', function() {
173
  win.on('beforeShow', function() {
181 174
    win.getTopToolbar().add(slider);
182 175
    win.getTopToolbar().add(new Ext.Toolbar.Spacer());
183 176
    win.getTopToolbar().add(new Ext.Toolbar.Spacer());
184 177
    win.getTopToolbar().add(new Ext.Toolbar.Spacer());
185 178
    win.getTopToolbar().add(sliderLabel);
186 179

  
187
    if(url && (!vlc.playlist || vlc.playlist == 'undefined')) {
180
    // check if vlc plugin wasn't initialised correctly
181
    if(!vlc.playlist || (vlc.playlist == 'undefined')) {
188 182
      vlc.style.display = 'none';
183
      
184
      missingPlugin.innerHTML  = '<p>Embedded player could not be started. <br> You are probably missing VLC Mozilla plugin for your browser.</p>';
185
      
186
      if (url) {
187
        var channelid = url.substr(url.lastIndexOf('/'));
188
        var streamurl = 'stream/channelid/' + channelid;
189
        var playlisturl = 'playlist/channelid/' + channelid;
190
        missingPlugin.innerHTML += '<p><a href="' + playlisturl + '">M3U Playlist</a></p>';
191
        missingPlugin.innerHTML += '<p><a href="' + streamurl + '">Direct URL</a></p>';
192
      }
189 193

  
190
      var chUrl = '<a href="' + url + '">the stream</a>';
191
      missingPlugin.innerHTML  = '<p>You are missing a plugin for your browser.</p>';
192
      missingPlugin.innerHTML += '<p>You can still watch ' + chUrl + ' using an external player.</p>';
193 194
      missingPlugin.style.display = 'block';
194 195
    }
196
    else {
197
	// check if the window was opened with an url-parameter
198
	if (url) {
199
	  vlc.playlist.items.clear();
200
	  vlc.playlist.add(url);
201
	  vlc.playlist.playItem(0);
202
	}
203
    }
195 204
  });
196 205

  
197 206
  win.show();
(5-5/8)