Make sure song changed is only called once

This commit is contained in:
Jonas Kvinge
2020-09-29 22:40:43 +02:00
parent d02dc54c1b
commit 938ee20f1f
5 changed files with 54 additions and 68 deletions

View File

@@ -571,7 +571,6 @@ MainWindow::MainWindow(Application *app, SystemTrayIcon *tray_icon, OSDBase *osd
connect(app_->player(), SIGNAL(VolumeChanged(int)), osd_, SLOT(VolumeChanged(int)));
connect(app_->player(), SIGNAL(VolumeChanged(int)), ui_->volume, SLOT(setValue(int)));
connect(app_->player(), SIGNAL(ForceShowOSD(Song, bool)), SLOT(ForceShowOSD(Song, bool)));
connect(app_->player(), SIGNAL(SendNowPlaying()), SLOT(SendNowPlaying()));
connect(app_->playlist_manager(), SIGNAL(CurrentSongChanged(Song)), SLOT(SongChanged(Song)));
connect(app_->playlist_manager(), SIGNAL(CurrentSongChanged(Song)), app_->player(), SLOT(CurrentMetadataChanged(Song)));
@@ -1263,21 +1262,14 @@ void MainWindow::MediaPlaying() {
track_slider_timer_->start();
UpdateTrackPosition();
if (app_->playlist_manager()->active()) app_->playlist_manager()->active()->set_nowplaying(false);
SendNowPlaying();
}
void MainWindow::SendNowPlaying() {
PlaylistItemPtr item(app_->player()->GetCurrentItem());
if (!item) return;
// Send now playing to scrobble services
Playlist *playlist = app_->playlist_manager()->active();
if (app_->scrobbler()->IsEnabled() && playlist && !playlist->nowplaying() && item->Metadata().is_metadata_good()) {
app_->scrobbler()->UpdateNowPlaying(item->Metadata());
playlist->set_nowplaying(true);
if (app_->scrobbler()->IsEnabled() && playlist && playlist->current_item() && playlist->current_item()->Metadata().is_metadata_good()) {
app_->scrobbler()->UpdateNowPlaying(playlist->current_item()->Metadata());
ui_->action_love->setEnabled(true);
ui_->button_love->setEnabled(true);
if (tray_icon_) tray_icon_->LoveStateChanged(true);
@@ -1297,6 +1289,8 @@ void MainWindow::SongChanged(const Song &song) {
setWindowTitle(song.PrettyTitleWithArtist());
if (tray_icon_) tray_icon_->SetProgress(0);
SendNowPlaying();
}
void MainWindow::TrackSkipped(PlaylistItemPtr item) {
@@ -1568,7 +1562,7 @@ void MainWindow::UpdateTrackPosition() {
// Send Scrobble
if (app_->scrobbler()->IsEnabled() && item->Metadata().is_metadata_good()) {
Playlist *playlist = app_->playlist_manager()->active();
if (playlist && playlist->nowplaying() && !playlist->scrobbled()) {
if (playlist && !playlist->scrobbled()) {
const int scrobble_point = (playlist->scrobble_point_nanosec() / kNsecPerSec);
if (position >= scrobble_point) {
app_->scrobbler()->Scrobble(item->Metadata(), scrobble_point);

View File

@@ -237,10 +237,11 @@ void Player::HandleLoadResult(const UrlHandler::LoadResult &result) {
if (!item) {
return;
}
const bool has_next_row = app_->playlist_manager()->active()->next_row() != -1;
int next_row = app_->playlist_manager()->active()->next_row();
const bool has_next_row = next_row != -1;
PlaylistItemPtr next_item;
if (has_next_row) {
next_item = app_->playlist_manager()->active()->item_at(app_->playlist_manager()->active()->next_row());
next_item = app_->playlist_manager()->active()->item_at(next_row);
}
bool is_current(false);
@@ -322,11 +323,12 @@ void Player::HandleLoadResult(const UrlHandler::LoadResult &result) {
if (update) {
if (is_current) {
item->SetTemporaryMetadata(song);
app_->playlist_manager()->active()->InformOfCurrentSongChange(autoscroll_);
app_->playlist_manager()->active()->InformOfCurrentSongChange(autoscroll_, true);
app_->playlist_manager()->active()->UpdateScrobblePoint();
}
else if (is_next) {
next_item->SetTemporaryMetadata(song);
app_->playlist_manager()->active()->ItemChanged(next_item);
app_->playlist_manager()->active()->ItemChanged(next_row);
}
}
@@ -599,15 +601,6 @@ void Player::CurrentMetadataChanged(const Song &metadata) {
// Those things might have changed (especially when a previously invalid song was reloaded) so we push the latest version into Engine
engine_->RefreshMarkers(metadata.beginning_nanosec(), metadata.end_nanosec());
// Send now playing to scrobble services
if (app_->scrobbler()->IsEnabled() && engine_->state() == Engine::Playing) {
Playlist *playlist = app_->playlist_manager()->active();
current_item_ = playlist->current_item();
if (playlist && current_item_ && !playlist->nowplaying() && current_item_->Metadata() == metadata && current_item_->Metadata().is_metadata_good()) {
emit SendNowPlaying();
}
}
}
void Player::SeekTo(const int seconds) {
@@ -649,13 +642,14 @@ void Player::EngineMetadataReceived(const Engine::SimpleMetaBundle &bundle) {
return;
}
if (app_->playlist_manager()->active()->next_row() != -1) {
PlaylistItemPtr next_item = app_->playlist_manager()->active()->item_at(app_->playlist_manager()->active()->next_row());
int next_row = app_->playlist_manager()->active()->next_row();
if (next_row != -1) {
PlaylistItemPtr next_item = app_->playlist_manager()->active()->item_at(next_row);
if (bundle.url == next_item->Url()) {
Song song = next_item->Metadata();
song.MergeFromSimpleMetaBundle(bundle);
next_item->SetTemporaryMetadata(song);
app_->playlist_manager()->active()->ItemChanged(next_item);
app_->playlist_manager()->active()->ItemChanged(next_row);
}
}

View File

@@ -122,7 +122,6 @@ class PlayerInterface : public QObject {
// The toggle parameter is true when user requests to toggle visibility for Pretty OSD
void ForceShowOSD(Song, bool toggle);
void SendNowPlaying();
void Authenticated();
};