From faee1977fe8b78ede4961ffeda7e91faa98cfd70 Mon Sep 17 00:00:00 2001 From: Jonas Kvinge Date: Tue, 30 Oct 2018 23:21:51 +0100 Subject: [PATCH] Add better error handling between engine and player --- src/core/player.cpp | 32 +++++++++++++++++--------------- src/core/player.h | 6 ++++-- src/engine/enginebase.h | 10 ++++++---- 3 files changed, 27 insertions(+), 21 deletions(-) diff --git a/src/core/player.cpp b/src/core/player.cpp index 0112bac6..28b0cfc4 100644 --- a/src/core/player.cpp +++ b/src/core/player.cpp @@ -71,6 +71,7 @@ #include "equalizer/equalizer.h" #include "analyzer/analyzercontainer.h" #include "settings/backendsettingspage.h" +#include "settings/playbacksettingspage.h" #include "settings/behavioursettingspage.h" #include "settings/playlistsettingspage.h" #include "internet/internetservices.h" @@ -86,6 +87,8 @@ Player::Player(Application *app, QObject *parent) nb_errors_received_(0), volume_before_mute_(50), last_pressed_previous_(QDateTime::currentDateTime()), + continue_on_error_(false), + greyout_(true), menu_previousmode_(PreviousBehaviour_DontRestart), seek_step_sec_(10) { @@ -177,6 +180,7 @@ void Player::Init() { analyzer_->SetEngine(engine_.get()); connect(engine_.get(), SIGNAL(Error(QString)), SIGNAL(Error(QString))); + connect(engine_.get(), SIGNAL(FatalError()), SLOT(FatalError())); connect(engine_.get(), SIGNAL(ValidSongRequested(QUrl)), SLOT(ValidSongRequested(QUrl))); connect(engine_.get(), SIGNAL(InvalidSongRequested(QUrl)), SLOT(InvalidSongRequested(QUrl))); connect(engine_.get(), SIGNAL(StateChanged(Engine::State)), SLOT(EngineStateChanged(Engine::State))); @@ -206,6 +210,8 @@ void Player::ReloadSettings() { QSettings s; s.beginGroup(PlaylistSettingsPage::kSettingsGroup); + continue_on_error_ = s.value("continue_on_error", false).toBool(); + greyout_ = s.value("greyout_songs_play", true).toBool(); menu_previousmode_ = PreviousBehaviour(s.value("menu_previousmode", PreviousBehaviour_DontRestart).toInt()); s.endGroup(); @@ -703,29 +709,25 @@ void Player::TrackAboutToEnd() { void Player::IntroPointReached() { NextInternal(Engine::Intro); } +void Player::FatalError() { + nb_errors_received_ = 0; + Stop(); +} + void Player::ValidSongRequested(const QUrl &url) { emit SongChangeRequestProcessed(url, true); } void Player::InvalidSongRequested(const QUrl &url) { - // First send the notification to others... - emit SongChangeRequestProcessed(url, false); + if (greyout_) emit SongChangeRequestProcessed(url, false); - // TODO: Continue to the next item in the playlist based on the error type. - // When our listeners have completed their processing of the current item we can change the current item by skipping to the next song - // NextItem(Engine::Auto); - - // Manual track changes override "Repeat track" - Playlist *active_playlist = app_->playlist_manager()->active(); - const bool ignore_repeat_track = Engine::Auto & Engine::Manual; - int i = active_playlist->next_row(ignore_repeat_track); - if (i == -1) { - app_->playlist_manager()->active()->set_current_row(i); - emit PlaylistFinished(); + if (!continue_on_error_) { + FatalError(); + return; } - nb_errors_received_ = 0; - Stop(); + + NextItem(Engine::Auto); } diff --git a/src/core/player.h b/src/core/player.h index 8151aa8d..c645334e 100644 --- a/src/core/player.h +++ b/src/core/player.h @@ -193,6 +193,7 @@ class Player : public PlayerInterface { void NextInternal(Engine::TrackChangeFlags); + void FatalError(); void ValidSongRequested(const QUrl&); void InvalidSongRequested(const QUrl&); @@ -219,10 +220,11 @@ class Player : public PlayerInterface { QMap url_handlers_; QUrl loading_async_; - int volume_before_mute_; - QDateTime last_pressed_previous_; + + bool continue_on_error_; + bool greyout_; PreviousBehaviour menu_previousmode_; int seek_step_sec_; diff --git a/src/engine/enginebase.h b/src/engine/enginebase.h index 9fcd16ae..7f016a36 100644 --- a/src/engine/enginebase.h +++ b/src/engine/enginebase.h @@ -137,13 +137,15 @@ signals: void FadeoutFinishedSignal(); - void StatusText(const QString&); - void Error(const QString&); + void StatusText(const QString &text); + void Error(const QString &text); + // Emitted when there was a fatal error + void FatalError(); // Emitted when Engine was unable to play a song with the given QUrl. - void InvalidSongRequested(const QUrl&); + void InvalidSongRequested(const QUrl &url); // Emitted when Engine successfully started playing a song with the given QUrl. - void ValidSongRequested(const QUrl&); + void ValidSongRequested(const QUrl &url); void MetaData(const Engine::SimpleMetaBundle&);