aboutsummaryrefslogtreecommitdiff
path: root/emms-lastfm.el
diff options
context:
space:
mode:
authorTassilo Horn <tassilo@member.fsf.org>2006-12-12 20:03:00 +0000
committerTassilo Horn <tassilo@member.fsf.org>2006-12-12 20:03:00 +0000
commit99bd78e86c37e8877178900e81dea03dcc1c0959 (patch)
tree0f1ccf7578f4f333130ff711d635e38f6c967e89 /emms-lastfm.el
parenta0b3273c77c85c9585e84b7ba88f4928ef47267b (diff)
submitting-when-paused.dpatch
This patch enables emms-lastfm.el to submit the current track even if the playback has been paused and resumed. It's done by canceling the `emms-lastfm-timer' when pausing and reenabling it on resume. darcs-hash:20061212200324-c06f4-2ab89e58a91532db90e54e84f209086aa28f3a7f.gz
Diffstat (limited to 'emms-lastfm.el')
-rw-r--r--emms-lastfm.el32
1 files changed, 21 insertions, 11 deletions
diff --git a/emms-lastfm.el b/emms-lastfm.el
index 1dcf9db..3f16f8c 100644
--- a/emms-lastfm.el
+++ b/emms-lastfm.el
@@ -42,9 +42,6 @@
;; -----------------------------------------------------------------------
-;; TODO: Have a look at `emms-playing-time'. Stopping the timer may not be
-;; needed.
-
(require 'url)
(require 'emms)
@@ -70,25 +67,38 @@ procedure. Only for internal use.")
(defvar emms-lastfm-timer nil "-- only used internally --")
(defun emms-lastfm-new-track-function ()
- "This function runs whenever a new track starts and sets the
-track submission timer."
+ "This function should run whenever a new track starts (or a
+paused track resumes) and sets the track submission timer."
(setq emms-lastfm-current-track
(emms-playlist-current-selected-track))
;; Tracks should be submitted, if they played 240 secs or half of their
;; length, whichever comes first.
- (let ((secs (/ (emms-track-get emms-lastfm-current-track 'info-playing-time)
- 2)))
+ (let ((secs (/ (emms-track-get emms-lastfm-current-track
+ 'info-playing-time)
+ 2)))
(when (> secs 240)
(setq secs 240))
(unless (< secs 15) ;; Skip titles shorter than 30 seconds
- (setq emms-lastfm-timer
- (run-with-timer secs nil 'emms-lastfm-submit-track)))))
+ (setq secs (- secs emms-playing-time))
+ (unless (< secs 0)
+ (setq emms-lastfm-timer
+ (run-with-timer secs nil 'emms-lastfm-submit-track))))))
(defun emms-lastfm-cancel-timer ()
+ "Cancels `emms-lastfm-timer' if it is running."
(when emms-lastfm-timer
(cancel-timer emms-lastfm-timer)
(setq emms-lastfm-timer nil)))
+(defun emms-lastfm-pause ()
+ "Handles things to be done when the player is paused or
+resumed."
+ (if emms-player-paused-p
+ ;; the player paused
+ (emms-lastfm-cancel-timer)
+ ;; The player resumed
+ (emms-lastfm-new-track-function)))
+
(defun emms-lastfm-activate (&optional ARG)
"Start submitting the tracks you listened to to
http://www.last.fm, if ARG is positive. If ARG is negative or
@@ -109,14 +119,14 @@ the current track, too."
(add-hook 'emms-player-stopped-hook
'emms-lastfm-cancel-timer)
(add-hook 'emms-player-paused-hook
- 'emms-lastfm-cancel-timer)
+ 'emms-lastfm-pause)
(message "EMMS Last.fm plugin activated."))
(remove-hook 'emms-player-started-hook
'emms-lastfm-handshake-if-needed)
(remove-hook 'emms-player-started-hook
'emms-lastfm-new-track-function)
(remove-hook 'emms-player-stopped-hook
- 'emms-lastfm-cancel-timer)
+ 'emms-lastfm-pause)
(remove-hook 'emms-player-paused-hook
'emms-lastfm-cancel-timer)
(cancel-timer emms-lastfm-timer)