From 8964bc77125b82620bcd283ee51e06032bcab235 Mon Sep 17 00:00:00 2001 From: trialuser02 Date: Tue, 12 Mar 2013 11:40:06 +0000 Subject: scrobbler plugin: added pause handling (patch by Ferdinand Vesely) (Closes issue 578) git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@3308 90c681e8-e032-0410-971d-27865f9a5e38 --- src/plugins/General/scrobbler/lastfmscrobbler.cpp | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'src/plugins/General/scrobbler/lastfmscrobbler.cpp') diff --git a/src/plugins/General/scrobbler/lastfmscrobbler.cpp b/src/plugins/General/scrobbler/lastfmscrobbler.cpp index ba414f58b..2a449c410 100644 --- a/src/plugins/General/scrobbler/lastfmscrobbler.cpp +++ b/src/plugins/General/scrobbler/lastfmscrobbler.cpp @@ -123,17 +123,29 @@ LastfmScrobbler::~LastfmScrobbler() void LastfmScrobbler::setState(Qmmp::State state) { + static Qmmp::State previousState = state; + static int elapsed = 0; m_state = state; switch ((uint) state) { case Qmmp::Playing: - m_start_ts = QDateTime::currentDateTime().toTime_t(); + if (previousState != Qmmp::Paused) + { + qDebug("LastfmScrobbler: new song started"); + m_start_ts = QDateTime::currentDateTime().toTime_t(); + elapsed = 0; + } + else + { + qDebug("LastfmScrobbler: resuming after pause, %d seconds played", elapsed / 1000); + } m_time->restart(); break; case Qmmp::Stopped: + elapsed += m_time->elapsed(); if (!m_song.metaData().isEmpty() - && ((m_time->elapsed ()/1000 > 240) || (m_time->elapsed ()/1000 > int(m_song.length()/2))) - && (m_song.length() > MIN_SONG_LENGTH)) + && ((elapsed / 1000 > 240) || (elapsed / 1000 > int(m_song.length()/2))) + && (m_song.length() > MIN_SONG_LENGTH)) { m_song.setTimeStamp(m_start_ts); m_cachedSongs << m_song; @@ -147,9 +159,14 @@ void LastfmScrobbler::setState(Qmmp::State state) if (!m_session.isEmpty() && !m_submitReply) submit(); break; + case Qmmp::Paused: + elapsed += m_time->restart(); + qDebug("LastfmScrobbler: pausing after %d seconds played", elapsed / 1000); + break; default: ; } + previousState = state; } void LastfmScrobbler::updateMetaData() -- cgit v1.2.3-13-gbd6f