+ },
+
+ vlc: {
+ widget: this,
+ timerHandle: null,
+
+ STATES: {
+ IDLE_CLOSE: [0, "Idle / Close"],
+ OPENING: [1, "Opening..."],
+ BUFFERING: [2, "Buffering..."],
+ PLAYING: [3, "Playing..."],
+ PAUSED: [4, "Paused"],
+ STOPPING: [5, "Stopping..."],
+ ERROR: [6, "Error!"]
+ },
+
+ init: function() {
+ if (widget.options.autoplay)
+ widget.vlc.play();
+ widget.vlc.refreshAll();
+ },
+
+ togglePlay: function() {
+ if (! widget.$video[0].playlist.isPlaying)
+ {
+ widget.vlc.play();
+ }
+ else
+ {
+ widget.vlc.pause();
+ }
+ },
+
+ play: function() {
+ if (! widget.$video[0].playlist.isPlaying)
+ widget.$video[0].playlist.play();
+
+ widget.setPauseButton();
+
+ // Schedule information refreshment at refreshInterval seconds.
+ if (! widget.vlc.timerHandle)
+ widget.vlc.timerHandle = setTimeout(widget.vlc.refreshHandler,
+ widget.options.refreshInterval * 1000);
+
+ widget.vlc.refreshState();
+
+ return widget;
+ },
+
+ pause: function() {
+ if (widget.$video[0].playlist.isPlaying)
+ widget.$video[0].playlist.togglePause();
+
+ widget.setPlayButton();
+
+ // Cancel information refreshment scheduling.
+ clearTimeout(widget.vlc.timerHandle);
+ widget.vlc.timerHandle = null;
+
+ widget.vlc.refreshState();
+
+ return widget;
+ },
+
+ toggleMute: function() {
+ if (! widget.$video[0].audio.mute)
+ {
+ widget.vlc.mute();
+ }
+ else
+ {
+ widget.vlc.unmute();
+ }
+ },
+
+ mute: function() {
+ if (! widget.$video[0].audio.mute)
+ widget.$video[0].audio.toggleMute();
+
+ widget.setMuteButton();
+
+ widget.vlc.refreshVolume();
+
+ return widget;
+ },
+
+ unmute: function() {
+ if (widget.$video[0].audio.mute)
+ widget.$video[0].audio.toggleMute();
+
+ widget.setUnmuteButton();
+
+ widget.vlc.refreshVolume();
+
+ return widget;
+ },
+
+ /**
+ * Volume value is expressed in percents.
+ */
+ volume: function(vol) {
+ if (typeof vol == 'undefined')
+ return Math.round(widget.$video[0].audio.volume);
+
+ widget.vlc.unmute();
+ widget.$video[0].audio.volume = vol;
+
+ return widget;
+ },
+
+ /**
+ * Seek position is a value between 0 and 1000.
+ */
+ crtTime: function(pos) {
+ // getter
+ if (typeof pos == 'undefined')
+ {
+ var crtTime = widget.$video[0].input.time;
+ var totTime = widget.$video[0].input.length;
+ if (isNaN(totTime) || totTime == 0)
+ return 0;
+ else
+ return Math.round(crtTime / totTime * 1000.0);
+ }
+
+ // setter
+ widget.$video[0].input.time =
+ pos / 1000 * widget.$video[0].input.length;
+
+ widget.vlc.refreshState();
+ },
+
+ /**
+ * Timeout callback called at refreshInterval during playing in order
+ * to refresh information.
+ */
+ refreshHandler: function() {
+ if (widget.$video[0].input.state
+ == widget.vlc.STATES.PLAYING[0])
+ {
+ widget.vlc.refreshTime();
+ widget.vlc.timerHandle = setTimeout(widget.vlc.refreshHandler,
+ widget.options.refreshInterval * 1000);
+ }
+ else
+ widget.vlc.pause();
+
+ widget.vlc.refreshState();
+ },
+
+ refreshAll: function() {
+ widget.vlc.refreshState();
+ widget.vlc.refreshVolume();
+ widget.vlc.refreshLoadedProgress();
+
+ try {
+ widget.vlc.refreshTime();
+ } catch(e) {
+ console.log(e);
+ widget.$time.html('--:-- / --:--');
+ }
+ },
+
+ refreshTime: function() {
+ // TODO while seeking (maybe not necessary for VLC)
+// if (widget.$video[0].seeking)
+// return widget;
+
+ // Time values in seconds.
+ var crtTime = widget.$video[0].input.time / 1000.0;
+ var totTime = widget.$video[0].input.length / 1000.0;
+ //var crtTime = widget.$video[0].input.position * totTime;
+
+ // Current time string
+ var crtH = Math.floor(crtTime / 3600);
+ var crtM = Math.floor((crtTime / 60) % 60);
+ var crtS = Math.floor(crtTime % 60);
+ var strCrtTime =
+ (crtH == 0 ? '' : (widget._leadingZeros(crtH) + ':'))
+ + widget._leadingZeros(crtM) + ':' + widget._leadingZeros(crtS);
+
+ // Total time string
+ var totH = Math.floor(totTime / 3600);
+ var totM = Math.floor((totTime / 60) % 60);
+ var totS = Math.floor(totTime % 60);
+ var strTotTime =
+ (totH == 0 || isNaN(totH) ? '' : (widget._leadingZeros(totH) + ':'))
+ + widget._leadingZeros(totM) + ':' + widget._leadingZeros(totS);
+
+ widget.setTimeText('' + strCrtTime + ' / ' + strTotTime);
+
+ // Update time progress slider.
+ widget.vlc.refreshProgress();
+
+ return widget;
+ },
+
+ _state: function(code) {
+ var r;
+ $.each(widget.vlc.STATES, function(index, value) {
+ if ('' + code == '' + value[0])
+ {
+ r = value;
+ return false;
+ }
+ });
+
+ return r;
+ },
+
+ refreshState: function() {
+ widget.$stateText
+ .html(widget.vlc._state(widget.$video[0].input.state)[1]);
+ },
+
+ refreshVolume: function() {
+ var vol;
+
+ if (widget.$video[0].audio.mute)
+ vol = 0;
+ else
+ vol = Math.floor(widget.$video[0].audio.volume);
+
+ widget.setVolumeSlider(vol);
+
+ return widget;
+ },
+
+ refreshProgress: function() {
+ widget.setProgressSlider(widget.vlc.crtTime());
+
+ return widget;
+ },