mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-09 07:36:48 +02:00
* PlaylistInterface now provides getSharedPointer(). AudioEngine makes use of it and doesn't crash when encountering a deleted playlist.
This commit is contained in:
@@ -46,8 +46,8 @@ AudioEngine::instance()
|
|||||||
AudioEngine::AudioEngine()
|
AudioEngine::AudioEngine()
|
||||||
: QObject()
|
: QObject()
|
||||||
, m_isPlayingHttp( false )
|
, m_isPlayingHttp( false )
|
||||||
, m_playlist( 0 )
|
// , m_playlist( 0 )
|
||||||
, m_currentTrackPlaylist( 0 )
|
// , m_currentTrackPlaylist( 0 )
|
||||||
, m_queue( 0 )
|
, m_queue( 0 )
|
||||||
, m_timeElapsed( 0 )
|
, m_timeElapsed( 0 )
|
||||||
, m_expectStop( false )
|
, m_expectStop( false )
|
||||||
@@ -141,8 +141,8 @@ AudioEngine::stop()
|
|||||||
|
|
||||||
m_mediaObject->stop();
|
m_mediaObject->stop();
|
||||||
|
|
||||||
if ( m_playlist )
|
if ( !m_playlist.isNull() )
|
||||||
m_playlist->reset();
|
m_playlist.data()->reset();
|
||||||
|
|
||||||
setCurrentTrack( Tomahawk::result_ptr() );
|
setCurrentTrack( Tomahawk::result_ptr() );
|
||||||
emit stopped();
|
emit stopped();
|
||||||
@@ -168,11 +168,11 @@ AudioEngine::previous()
|
|||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO;
|
qDebug() << Q_FUNC_INFO;
|
||||||
|
|
||||||
if ( !m_playlist )
|
if ( m_playlist.isNull() )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if ( m_playlist->skipRestrictions() == PlaylistInterface::NoSkip ||
|
if ( m_playlist.data()->skipRestrictions() == PlaylistInterface::NoSkip ||
|
||||||
m_playlist->skipRestrictions() == PlaylistInterface::NoSkipBackwards )
|
m_playlist.data()->skipRestrictions() == PlaylistInterface::NoSkipBackwards )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
loadPreviousTrack();
|
loadPreviousTrack();
|
||||||
@@ -184,15 +184,15 @@ AudioEngine::next()
|
|||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO;
|
qDebug() << Q_FUNC_INFO;
|
||||||
|
|
||||||
if ( !m_playlist )
|
if ( m_playlist.isNull() )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if ( m_playlist->skipRestrictions() == PlaylistInterface::NoSkip ||
|
if ( m_playlist.data()->skipRestrictions() == PlaylistInterface::NoSkip ||
|
||||||
m_playlist->skipRestrictions() == PlaylistInterface::NoSkipForwards )
|
m_playlist.data()->skipRestrictions() == PlaylistInterface::NoSkipForwards )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if ( !m_currentTrack.isNull() && !m_playlist->hasNextItem() &&
|
if ( !m_currentTrack.isNull() && !m_playlist.data()->hasNextItem() &&
|
||||||
m_currentTrack->id() == m_playlist->currentItem()->id() )
|
m_currentTrack->id() == m_playlist.data()->currentItem()->id() )
|
||||||
{
|
{
|
||||||
//For instance, when doing a catch-up while listening along, but the person
|
//For instance, when doing a catch-up while listening along, but the person
|
||||||
//you're following hasn't started a new track yet...don't do anything
|
//you're following hasn't started a new track yet...don't do anything
|
||||||
@@ -206,10 +206,7 @@ AudioEngine::next()
|
|||||||
void
|
void
|
||||||
AudioEngine::seek( int ms )
|
AudioEngine::seek( int ms )
|
||||||
{
|
{
|
||||||
if ( !m_playlist )
|
if ( !m_playlist.isNull() && m_playlist.data()->seekRestrictions() == PlaylistInterface::NoSeek )
|
||||||
return;
|
|
||||||
|
|
||||||
if ( m_playlist->seekRestrictions() == PlaylistInterface::NoSeek )
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if ( isPlaying() || isPaused() )
|
if ( isPlaying() || isPaused() )
|
||||||
@@ -424,13 +421,13 @@ AudioEngine::loadPreviousTrack()
|
|||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO;
|
qDebug() << Q_FUNC_INFO;
|
||||||
|
|
||||||
if ( !m_playlist )
|
if ( m_playlist.isNull() )
|
||||||
{
|
{
|
||||||
stop();
|
stop();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Tomahawk::result_ptr result = m_playlist->previousItem();
|
Tomahawk::result_ptr result = m_playlist.data()->previousItem();
|
||||||
if ( !result.isNull() )
|
if ( !result.isNull() )
|
||||||
loadTrack( result );
|
loadTrack( result );
|
||||||
else
|
else
|
||||||
@@ -450,16 +447,16 @@ AudioEngine::loadNextTrack()
|
|||||||
result = m_queue->nextItem();
|
result = m_queue->nextItem();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( m_playlist && result.isNull() )
|
if ( !m_playlist.isNull() && result.isNull() )
|
||||||
{
|
{
|
||||||
result = m_playlist->nextItem();
|
result = m_playlist.data()->nextItem();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !result.isNull() )
|
if ( !result.isNull() )
|
||||||
loadTrack( result );
|
loadTrack( result );
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if ( m_playlist && m_playlist->retryMode() == Tomahawk::PlaylistInterface::Retry )
|
if ( !m_playlist.isNull() && m_playlist.data()->retryMode() == Tomahawk::PlaylistInterface::Retry )
|
||||||
m_waitingOnNewTrack = true;
|
m_waitingOnNewTrack = true;
|
||||||
stop();
|
stop();
|
||||||
}
|
}
|
||||||
@@ -471,15 +468,15 @@ AudioEngine::playItem( Tomahawk::PlaylistInterface* playlist, const Tomahawk::re
|
|||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO;
|
qDebug() << Q_FUNC_INFO;
|
||||||
|
|
||||||
if ( m_playlist )
|
if ( !m_playlist.isNull() )
|
||||||
m_playlist->reset();
|
m_playlist.data()->reset();
|
||||||
|
|
||||||
setPlaylist( playlist );
|
setPlaylist( playlist );
|
||||||
m_currentTrackPlaylist = playlist;
|
m_currentTrackPlaylist = playlist->getSharedPointer();
|
||||||
|
|
||||||
if ( !result.isNull() )
|
if ( !result.isNull() )
|
||||||
loadTrack( result );
|
loadTrack( result );
|
||||||
else if ( m_playlist && m_playlist->retryMode() == PlaylistInterface::Retry )
|
else if ( !m_playlist.isNull() && m_playlist.data()->retryMode() == PlaylistInterface::Retry )
|
||||||
{
|
{
|
||||||
m_waitingOnNewTrack = true;
|
m_waitingOnNewTrack = true;
|
||||||
stop();
|
stop();
|
||||||
@@ -557,13 +554,15 @@ AudioEngine::timerTriggered( qint64 time )
|
|||||||
void
|
void
|
||||||
AudioEngine::setPlaylist( PlaylistInterface* playlist )
|
AudioEngine::setPlaylist( PlaylistInterface* playlist )
|
||||||
{
|
{
|
||||||
if ( m_playlist )
|
if ( !m_playlist.isNull() )
|
||||||
m_playlist->reset();
|
m_playlist.data()->reset();
|
||||||
|
|
||||||
m_playlist = playlist;
|
if ( !playlist )
|
||||||
|
return;
|
||||||
|
m_playlist = playlist->getSharedPointer();
|
||||||
|
|
||||||
if ( m_playlist && m_playlist->object() && m_playlist->retryMode() == PlaylistInterface::Retry )
|
if ( m_playlist.data()->object() && m_playlist.data()->retryMode() == PlaylistInterface::Retry )
|
||||||
connect( m_playlist->object(), SIGNAL( nextTrackReady() ), SLOT( playlistNextTrackReady() ) );
|
connect( m_playlist.data()->object(), SIGNAL( nextTrackReady() ), SLOT( playlistNextTrackReady() ) );
|
||||||
|
|
||||||
emit playlistChanged( playlist );
|
emit playlistChanged( playlist );
|
||||||
}
|
}
|
||||||
|
@@ -56,10 +56,10 @@ public:
|
|||||||
bool isPaused() const { return m_mediaObject->state() == Phonon::PausedState; }
|
bool isPaused() const { return m_mediaObject->state() == Phonon::PausedState; }
|
||||||
|
|
||||||
/* Returns the PlaylistInterface of the currently playing track. Note: This might be different to the current playlist! */
|
/* Returns the PlaylistInterface of the currently playing track. Note: This might be different to the current playlist! */
|
||||||
Tomahawk::PlaylistInterface* currentTrackPlaylist() const { return m_currentTrackPlaylist; }
|
Tomahawk::PlaylistInterface* currentTrackPlaylist() const { return m_currentTrackPlaylist.data(); }
|
||||||
|
|
||||||
/* Returns the PlaylistInterface of the current playlist. Note: The currently playing track might still be from a different playlist! */
|
/* Returns the PlaylistInterface of the current playlist. Note: The currently playing track might still be from a different playlist! */
|
||||||
Tomahawk::PlaylistInterface* playlist() const { return m_playlist; }
|
Tomahawk::PlaylistInterface* playlist() const { return m_playlist.data(); }
|
||||||
|
|
||||||
Tomahawk::result_ptr currentTrack() const { return m_currentTrack; }
|
Tomahawk::result_ptr currentTrack() const { return m_currentTrack; }
|
||||||
|
|
||||||
@@ -130,8 +130,8 @@ private:
|
|||||||
|
|
||||||
Tomahawk::result_ptr m_currentTrack;
|
Tomahawk::result_ptr m_currentTrack;
|
||||||
Tomahawk::result_ptr m_lastTrack;
|
Tomahawk::result_ptr m_lastTrack;
|
||||||
Tomahawk::PlaylistInterface* m_playlist;
|
QWeakPointer< Tomahawk::PlaylistInterface > m_playlist;
|
||||||
Tomahawk::PlaylistInterface* m_currentTrackPlaylist;
|
QWeakPointer< Tomahawk::PlaylistInterface > m_currentTrackPlaylist;
|
||||||
Tomahawk::PlaylistInterface* m_queue;
|
Tomahawk::PlaylistInterface* m_queue;
|
||||||
|
|
||||||
Phonon::MediaObject* m_mediaObject;
|
Phonon::MediaObject* m_mediaObject;
|
||||||
|
@@ -19,6 +19,7 @@
|
|||||||
#ifndef PLAYLISTINTERFACE_H
|
#ifndef PLAYLISTINTERFACE_H
|
||||||
#define PLAYLISTINTERFACE_H
|
#define PLAYLISTINTERFACE_H
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
#include <QModelIndex>
|
#include <QModelIndex>
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
|
||||||
@@ -70,6 +71,20 @@ public:
|
|||||||
|
|
||||||
QObject* object() const { return m_object; }
|
QObject* object() const { return m_object; }
|
||||||
|
|
||||||
|
static void dontDelete( Tomahawk::PlaylistInterface* obj )
|
||||||
|
{
|
||||||
|
qDebug() << Q_FUNC_INFO << obj;
|
||||||
|
}
|
||||||
|
virtual Tomahawk::playlistinterface_ptr getSharedPointer()
|
||||||
|
{
|
||||||
|
if ( m_sharedPtr.isNull() )
|
||||||
|
{
|
||||||
|
m_sharedPtr = Tomahawk::playlistinterface_ptr( this, dontDelete );
|
||||||
|
}
|
||||||
|
|
||||||
|
return m_sharedPtr;
|
||||||
|
}
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
virtual void setRepeatMode( RepeatMode mode ) = 0;
|
virtual void setRepeatMode( RepeatMode mode ) = 0;
|
||||||
virtual void setShuffled( bool enabled ) = 0;
|
virtual void setShuffled( bool enabled ) = 0;
|
||||||
@@ -83,6 +98,7 @@ signals:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
QObject* m_object;
|
QObject* m_object;
|
||||||
|
Tomahawk::playlistinterface_ptr m_sharedPtr;
|
||||||
|
|
||||||
QString m_filter;
|
QString m_filter;
|
||||||
};
|
};
|
||||||
|
@@ -282,6 +282,7 @@ Source::getPlaylistInterface()
|
|||||||
return m_playlistInterface;
|
return m_playlistInterface;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Source::onPlaybackStarted( const Tomahawk::query_ptr& query )
|
Source::onPlaybackStarted( const Tomahawk::query_ptr& query )
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user