Added display of the current time position as well as the total length of the file being played.
Mon Apr 12 23:13:17 PDT 2010 Thomas Persson <tompa.persson@gmail.com>
* Added display of the current time position as well as the total length of the file being played.
diff -rN -u old-climplayer/gui.lisp new-climplayer/gui.lisp
--- old-climplayer/gui.lisp 2014-07-31 16:42:22.000000000 -0700
+++ new-climplayer/gui.lisp 2014-07-31 16:42:22.000000000 -0700
@@ -39,7 +39,8 @@
(player-speed player-speed)
(play-list-tab play-list-tab)
(random-playbackp random-playbackp)
- (continuous-playbackp continuous-playbackp))
+ (continuous-playbackp continuous-playbackp)
+ (mplayer-file-length mplayer-file-length))
frame
(cond ((not play-list))
((and play-list-tab
@@ -69,7 +70,8 @@
(get-stream-info))
(next-to-play
(when mplayer-process
- (close (cl-user::process-input mplayer-process)))
+ (close (cl-user::process-input mplayer-process))
+ (close (cl-user::process-output mplayer-process)))
(unless (find next-to-play (current-playlist frame))
(setf (play-list-tab frame)
nil))
@@ -82,7 +84,9 @@
mplayer-process
(play currently-playing)
current-title
- nil)
+ nil
+ mplayer-file-length
+ 0)
(redisplay-climplayer-frame frame))
(currently-playing
(unless (current-playlist frame)
@@ -134,6 +138,15 @@
:region (pane-viewport-region browser)
:sheet browser)))))
+(defun redisplay-controls (frame)
+ (let ((control (find-pane-named frame 'control)))
+ (clim-sys:with-lock-held (*display-lock*)
+ (redisplay-frame-pane frame control)
+ (queue-repaint control
+ (make-instance 'window-repaint-event
+ :region (sheet-region control)
+ :sheet control)))))
+
(defmethod (setf currently-playing) :before (node
frame)
(let ((current (currently-playing frame)))
@@ -178,7 +191,11 @@
(volume :accessor volume
:initform 0)
(volume-updated :accessor volume-updated
- :initform (get-universal-time)))
+ :initform (get-universal-time))
+ (mplayer-position :accessor mplayer-position
+ :initform 0)
+ (mplayer-file-length :accessor mplayer-file-length
+ :initform 0))
(:panes
(info (make-pane 'application-pane
:scroll-bars nil
@@ -207,7 +224,7 @@
(outlining ()
(vertically ()
(40 info)
- (30 control)))
+ (45 control)))
(with-tab-layout ('pane :name 'main-pane)
("Browser" browser :drawing-options `(:ink ,+dark-green+
:text-style ,(make-text-style nil :bold nil))))
@@ -369,9 +386,56 @@
(+ x 6)
(+ y 10))))
+(defun seconds-to-hour-min-sec (seconds)
+ (let* ((hour (floor (/ seconds 3600)))
+ (min (floor (/ (- seconds
+ (* hour
+ 3600))
+ 60)))
+ (seconds (- seconds
+ (* hour 3600)
+ (* min 60))))
+ (format nil "~2,'0D:~2,'0D:~2,'0D"
+ hour
+ min
+ seconds)))
+
+(defun draw-timer (pane frame)
+ (let ((timer (timer frame)))
+ (write-string " Will play "
+ pane)
+ (with-drawing-options (pane :ink +darkred+)
+ (with-output-as-presentation (pane `(com-change-file-or-url)
+ 'command)
+ (write-string (title (caddr timer))
+ pane)))
+ (write-string " at " pane)
+ (with-drawing-options (pane :ink +darkred+)
+ (with-output-as-presentation (pane `(com-change-hour)
+ 'command)
+ (format pane
+ "~2,'0D"
+ (car timer))))
+ (write-string ":" pane)
+ (with-drawing-options (pane :ink +darkred+)
+ (with-output-as-presentation (pane `(com-change-minute)
+ 'command)
+ (format pane
+ "~2,'0D"
+ (cadr timer))))
+ (write-string "." pane)))
+
(defun display-controls (frame pane)
(with-text-size (pane *climplayer-text-size*)
(with-text-face (pane :bold)
+ (if (and (cl-user::process-p (mplayer-process frame))
+ (cl-user::process-alive-p (mplayer-process frame)))
+ (format pane
+ " ~A / ~A"
+ (seconds-to-hour-min-sec (mplayer-position frame))
+ (seconds-to-hour-min-sec (mplayer-file-length frame)))
+ (write-string " 00:00:00 / 00:00:00" pane))
+ (terpri pane)
(write-string " " pane)
(with-output-as-presentation (pane `(com-previous) 'command)
(write-string "<<" pane))
@@ -419,29 +483,7 @@
(write-string "-" pane)))
(terpri pane)
(when (timer frame)
- (let ((timer (timer frame)))
- (write-string " Will play "
- pane)
- (with-drawing-options (pane :ink +darkred+)
- (with-output-as-presentation (pane `(com-change-file-or-url)
- 'command)
- (write-string (title (caddr timer))
- pane)))
- (write-string " at " pane)
- (with-drawing-options (pane :ink +darkred+)
- (with-output-as-presentation (pane `(com-change-hour)
- 'command)
- (format pane
- "~2,'0D"
- (car timer))))
- (write-string ":" pane)
- (with-drawing-options (pane :ink +darkred+)
- (with-output-as-presentation (pane `(com-change-minute)
- 'command)
- (format pane
- "~2,'0D"
- (cadr timer))))
- (write-string "." pane)))))
+ (draw-timer pane frame))))
(define-climplayer-command (com-increase-volume :name nil)
()
@@ -876,9 +918,12 @@
(let ((mplayer-out-stream (cl-user::process-output (mplayer-process *climplayer-frame*)))
(*application-frame* *climplayer-frame*))
(when mplayer-out-stream
- (when (< 1 (- (get-universal-time)
- (volume-updated *climplayer-frame*)))
- (mplayer-command "pausing_keep_force get_property volume")
+ (when (<= 1 (- (get-universal-time)
+ (volume-updated *climplayer-frame*)))
+ (mplayer-command (format nil
+ "pausing_keep_force get_property volume~%pausing_keep_force get_time_pos"))
+ (when (zerop (mplayer-file-length *climplayer-frame*))
+ (mplayer-command "pausing_keep_force get_property length"))
(setf (volume-updated *climplayer-frame*)
(get-universal-time)))
(let ((line (read-line-no-hang mplayer-out-stream)))
@@ -893,7 +938,7 @@
(volume *climplayer-frame*)))
(setf (volume *climplayer-frame*)
new-volume)
- (redisplay-climplayer-frame *climplayer-frame*)))))
+ (redisplay-controls *climplayer-frame*)))))
(when (eq (type-of (currently-playing *climplayer-frame*))
'net-node)
(multiple-value-bind (start end)
@@ -904,7 +949,27 @@
(subseq line
(+ start 13)
(- end 2)))
- (redisplay-climplayer-frame *climplayer-frame*))))))))
+ (redisplay-climplayer-frame *climplayer-frame*))))
+ (multiple-value-bind (start end)
+ (cl-ppcre:scan "ANS_TIME_POSITION=[^\.]*."
+ line)
+ (when start
+ (let ((new-position (parse-integer (subseq line
+ (+ start 18)
+ (- end 1)))))
+ (unless (= new-position
+ (mplayer-position *climplayer-frame*))
+ (setf (mplayer-position *climplayer-frame*)
+ new-position)
+ (redisplay-controls *climplayer-frame*)))))
+ (multiple-value-bind (start end)
+ (cl-ppcre:scan "ANS_length=[^\.]*."
+ line)
+ (when start
+ (setf (mplayer-file-length *climplayer-frame*)
+ (parse-integer (subseq line
+ (+ start 11)
+ (1- end))))))))))
;;;; commands
Warning: CRC errors found. These are probably harmless but should be repaired.
See 'darcs gzcrcs --help' for more information.