Fix last.fm scrobbling. Fixes issue 1503

This commit is contained in:
David Sansome 2011-03-20 22:19:38 +00:00
parent 4f11cb94e1
commit 31ead96e91
3 changed files with 13 additions and 7 deletions

View File

@ -1325,9 +1325,16 @@ Song Playlist::current_item_metadata() const {
}
void Playlist::UpdateScrobblePoint() {
const int length = current_item_metadata().length_nanosec();
const qint64 length = current_item_metadata().length_nanosec();
if (length == 0) {
scrobble_point_ = 240ll * kNsecPerSec; // 4 minutes
} else {
scrobble_point_ = qBound(31ll * kNsecPerSec,
length/2,
240ll * kNsecPerSec);
}
scrobble_point_ = length == 0 ? 240 : qBound(31, length/2, 240);
has_scrobbled_ = false;
}

View File

@ -182,7 +182,7 @@ class Playlist : public QAbstractListModel {
void set_column_align_right(int column);
// Scrobbling
int scrobble_point() const { return scrobble_point_; }
qint64 scrobble_point_nanosec() const { return scrobble_point_; }
bool has_scrobbled() const { return has_scrobbled_; }
void set_scrobbled(bool v) { has_scrobbled_ = v; }
@ -333,7 +333,7 @@ class Playlist : public QAbstractListModel {
bool is_shuffled_;
int scrobble_point_;
qint64 scrobble_point_;
bool has_scrobbled_;
PlaylistSequence* playlist_sequence_;

View File

@ -973,6 +973,7 @@ void MainWindow::UpdateTrackPosition() {
const int position = std::floor(
float(player_->engine()->position_nanosec()) / kNsecPerSec + 0.5);
const int length = item->Metadata().length_nanosec() / kNsecPerSec;
const int scrobble_point = playlists_->active()->scrobble_point_nanosec() / kNsecPerSec;
if (length <= 0) {
// Probably a stream that we don't know the length of
@ -982,9 +983,7 @@ void MainWindow::UpdateTrackPosition() {
}
// Time to scrobble?
if (!playlists_->active()->has_scrobbled() &&
position >= playlists_->active()->scrobble_point()) {
if (!playlists_->active()->has_scrobbled() && position >= scrobble_point) {
#ifdef HAVE_LIBLASTFM
radio_model_->RadioModel::Service<LastFMService>()->Scrobble();
#endif