mirror of
https://github.com/clementine-player/Clementine
synced 2024-12-16 03:09:57 +01:00
Don't crash when doing stuff after clearing the playlist
This commit is contained in:
parent
dd972ff58b
commit
b4313e3410
@ -302,9 +302,9 @@ void MainWindow::MediaPlaying() {
|
||||
ui_.action_play_pause->setText("Pause");
|
||||
|
||||
ui_.action_play_pause->setEnabled(
|
||||
! (playlist_->current_item_options() & PlaylistItem::PauseDisabled));
|
||||
! (player_->GetCurrentItemOptions() & PlaylistItem::PauseDisabled));
|
||||
|
||||
bool is_lastfm = (playlist_->current_item_options() & PlaylistItem::LastFMControls);
|
||||
bool is_lastfm = (player_->GetCurrentItemOptions() & PlaylistItem::LastFMControls);
|
||||
LastFMService* lastfm = radio_model_->GetLastFMService();
|
||||
|
||||
ui_.action_ban->setEnabled(lastfm->IsScrobblingEnabled() && is_lastfm);
|
||||
@ -320,7 +320,7 @@ void MainWindow::ScrobblingEnabledChanged(bool value) {
|
||||
if (!player_->GetState() == Engine::Idle)
|
||||
return;
|
||||
|
||||
bool is_lastfm = (playlist_->current_item_options() & PlaylistItem::LastFMControls);
|
||||
bool is_lastfm = (player_->GetCurrentItemOptions() & PlaylistItem::LastFMControls);
|
||||
ui_.action_ban->setEnabled(value && is_lastfm);
|
||||
ui_.action_love->setEnabled(value);
|
||||
}
|
||||
@ -406,7 +406,7 @@ void MainWindow::FilePathChanged(const QString& path) {
|
||||
void MainWindow::UpdateTrackPosition() {
|
||||
// Track position in seconds
|
||||
const int position = std::floor(float(player_->GetEngine()->position()) / 1000.0 + 0.5);
|
||||
const int length = playlist_->current_item()->Metadata().length();
|
||||
const int length = player_->GetCurrentItem().length();
|
||||
|
||||
if (length <= 0) {
|
||||
// Probably a stream that we don't know the length of
|
||||
|
@ -9,6 +9,7 @@ Player::Player(Playlist* playlist, LastFMService* lastfm, QObject* parent)
|
||||
: QObject(parent),
|
||||
playlist_(playlist),
|
||||
lastfm_(lastfm),
|
||||
current_item_options_(PlaylistItem::Default),
|
||||
engine_(new XineEngine)
|
||||
{
|
||||
if (!engine_->init()) {
|
||||
@ -57,7 +58,7 @@ void Player::PlayPause() {
|
||||
|
||||
case Engine::Playing:
|
||||
// We really shouldn't pause last.fm streams
|
||||
if (playlist_->current_item()->options() & PlaylistItem::PauseDisabled)
|
||||
if (current_item_options_ & PlaylistItem::PauseDisabled)
|
||||
break;
|
||||
|
||||
qDebug() << "Pausing";
|
||||
@ -122,6 +123,8 @@ void Player::PlayAt(int index) {
|
||||
playlist_->set_current_index(index);
|
||||
|
||||
PlaylistItem* item = playlist_->item_at(index);
|
||||
current_item_options_ = item->options();
|
||||
current_item_ = item->Metadata();
|
||||
|
||||
if (item->options() & PlaylistItem::SpecialPlayBehaviour)
|
||||
item->StartLoading();
|
||||
|
@ -5,6 +5,8 @@
|
||||
#include <QSettings>
|
||||
|
||||
#include "engine_fwd.h"
|
||||
#include "playlistitem.h"
|
||||
#include "song.h"
|
||||
|
||||
class Playlist;
|
||||
class Settings;
|
||||
@ -20,6 +22,9 @@ class Player : public QObject {
|
||||
Engine::State GetState() const;
|
||||
int GetVolume() const;
|
||||
|
||||
PlaylistItem::Options GetCurrentItemOptions() const { return current_item_options_; }
|
||||
Song GetCurrentItem() const { return current_item_; }
|
||||
|
||||
public slots:
|
||||
void PlayAt(int index);
|
||||
void PlayPause();
|
||||
@ -47,6 +52,9 @@ class Player : public QObject {
|
||||
LastFMService* lastfm_;
|
||||
QSettings settings_;
|
||||
|
||||
PlaylistItem::Options current_item_options_;
|
||||
Song current_item_;
|
||||
|
||||
EngineBase* engine_;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user