1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-07 14:46:33 +02:00

* Fixed TWK-279 - Play first track of a playlist if play is clicked and nothing is playing yet.

This commit is contained in:
Christian Muehlhaeuser
2011-07-20 01:52:19 +02:00
parent 4a3f157718
commit 6bfbbce05f
4 changed files with 45 additions and 9 deletions

View File

@@ -46,18 +46,18 @@ AudioEngine::instance()
AudioEngine::AudioEngine() AudioEngine::AudioEngine()
: QObject() : QObject()
, m_isPlayingHttp( false ) , m_isPlayingHttp( false )
// , m_playlist( 0 )
// , m_currentTrackPlaylist( 0 )
, m_queue( 0 ) , m_queue( 0 )
, m_timeElapsed( 0 ) , m_timeElapsed( 0 )
, m_expectStop( false ) , m_expectStop( false )
, m_waitingOnNewTrack( false ) , m_waitingOnNewTrack( false )
, m_infoSystemConnected( false ) , m_infoSystemConnected( false )
, m_state( Stopped )
{ {
s_instance = this; s_instance = this;
qDebug() << "Init AudioEngine"; qDebug() << "Init AudioEngine";
qRegisterMetaType< AudioErrorCode >("AudioErrorCode"); qRegisterMetaType< AudioErrorCode >("AudioErrorCode");
qRegisterMetaType< AudioState >("AudioState");
m_mediaObject = new Phonon::MediaObject( this ); m_mediaObject = new Phonon::MediaObject( this );
m_audioOutput = new Phonon::AudioOutput( Phonon::MusicCategory, this ); m_audioOutput = new Phonon::AudioOutput( Phonon::MusicCategory, this );
@@ -130,6 +130,7 @@ AudioEngine::pause()
m_mediaObject->pause(); m_mediaObject->pause();
emit paused(); emit paused();
Tomahawk::InfoSystem::InfoSystem::instance()->pushInfo( s_aeInfoIdentifier, Tomahawk::InfoSystem::InfoNowPaused, QVariant() ); Tomahawk::InfoSystem::InfoSystem::instance()->pushInfo( s_aeInfoIdentifier, Tomahawk::InfoSystem::InfoNowPaused, QVariant() );
} }
@@ -139,6 +140,7 @@ AudioEngine::stop()
{ {
qDebug() << Q_FUNC_INFO; qDebug() << Q_FUNC_INFO;
setState( Stopped );
m_mediaObject->stop(); m_mediaObject->stop();
if ( !m_playlist.isNull() ) if ( !m_playlist.isNull() )
@@ -227,6 +229,7 @@ AudioEngine::setVolume( int percentage )
emit volumeChanged( percentage ); emit volumeChanged( percentage );
} }
void void
AudioEngine::mute() AudioEngine::mute()
{ {
@@ -416,6 +419,7 @@ AudioEngine::loadTrack( const Tomahawk::result_ptr& result )
return true; return true;
} }
void void
AudioEngine::loadPreviousTrack() AudioEngine::loadPreviousTrack()
{ {
@@ -513,6 +517,8 @@ AudioEngine::onStateChanged( Phonon::State newState, Phonon::State oldState )
qDebug() << "Phonon Error:" << m_mediaObject->errorString() << m_mediaObject->errorType(); qDebug() << "Phonon Error:" << m_mediaObject->errorString() << m_mediaObject->errorType();
return; return;
} }
if ( newState == Phonon::PlayingState )
setState( Playing );
if ( !m_expectStop ) if ( !m_expectStop )
return; return;
@@ -527,6 +533,10 @@ AudioEngine::onStateChanged( Phonon::State newState, Phonon::State oldState )
case Phonon::PausedState: case Phonon::PausedState:
{ {
stopped = ( duration - 1000 < m_mediaObject->currentTime() ); stopped = ( duration - 1000 < m_mediaObject->currentTime() );
if ( !stopped )
setState( Paused );
break; break;
} }
case Phonon::StoppedState: case Phonon::StoppedState:
@@ -614,3 +624,13 @@ AudioEngine::isLocalResult( const QString& url ) const
{ {
return url.startsWith( "file://" ); return url.startsWith( "file://" );
} }
void
AudioEngine::setState( AudioState state )
{
AudioState oldState = m_state;
m_state = state;
emit stateChanged( state, oldState );
}

View File

@@ -45,6 +45,7 @@ Q_OBJECT
public: public:
enum AudioErrorCode { StreamReadError, AudioDeviceError, DecodeError }; enum AudioErrorCode { StreamReadError, AudioDeviceError, DecodeError };
enum AudioState { Stopped, Playing, Paused };
static AudioEngine* instance(); static AudioEngine* instance();
@@ -52,8 +53,11 @@ public:
~AudioEngine(); ~AudioEngine();
unsigned int volume() const { return m_audioOutput->volume() * 100.0; } // in percent unsigned int volume() const { return m_audioOutput->volume() * 100.0; } // in percent
bool isPlaying() const { return m_mediaObject->state() == Phonon::PlayingState; }
bool isPaused() const { return m_mediaObject->state() == Phonon::PausedState; } AudioState state() const { return m_state; }
bool isPlaying() const { return m_state == Playing; }
bool isPaused() const { return m_state == Paused; }
bool isStopped() const { return m_state == Stopped; }
/* 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.data(); } Tomahawk::PlaylistInterface* currentTrackPlaylist() const { return m_currentTrackPlaylist.data(); }
@@ -98,6 +102,7 @@ signals:
void paused(); void paused();
void resumed(); void resumed();
void stateChanged( AudioState newState, AudioState oldState );
void volumeChanged( int volume /* in percent */ ); void volumeChanged( int volume /* in percent */ );
void timerMilliSeconds( qint64 msElapsed ); void timerMilliSeconds( qint64 msElapsed );
@@ -120,8 +125,11 @@ private slots:
void setCurrentTrack( const Tomahawk::result_ptr& result ); void setCurrentTrack( const Tomahawk::result_ptr& result );
private: private:
void setState( AudioState state );
bool isHttpResult( const QString& ) const; bool isHttpResult( const QString& ) const;
bool isLocalResult( const QString& ) const; bool isLocalResult( const QString& ) const;
void sendWaitingNotification() const; void sendWaitingNotification() const;
void sendNowPlayingNotification(); void sendNowPlayingNotification();
@@ -142,6 +150,8 @@ private:
bool m_waitingOnNewTrack; bool m_waitingOnNewTrack;
bool m_infoSystemConnected; bool m_infoSystemConnected;
AudioState m_state;
static AudioEngine* s_instance; static AudioEngine* s_instance;
}; };

View File

@@ -55,7 +55,6 @@ namespace Tomahawk
typedef QString QID; //query id typedef QString QID; //query id
typedef QString RID; //result id typedef QString RID; //result id
enum GeneratorMode { enum GeneratorMode {
OnDemand = 0, OnDemand = 0,
Static Static
@@ -64,6 +63,7 @@ namespace Tomahawk
}; // ns }; // ns
typedef int AudioErrorCode; typedef int AudioErrorCode;
typedef int AudioState;
// creates 36char ascii guid without {} around it // creates 36char ascii guid without {} around it
inline static QString uuid() inline static QString uuid()

View File

@@ -410,6 +410,7 @@ ViewManager::showSuperCollection()
return shown; return shown;
} }
void void
ViewManager::playlistInterfaceChanged( Tomahawk::PlaylistInterface* interface ) ViewManager::playlistInterfaceChanged( Tomahawk::PlaylistInterface* interface )
{ {
@@ -570,7 +571,6 @@ ViewManager::setPage( ViewPage* page, bool trackHistory )
// save the old playlist shuffle state in config before we change playlists // save the old playlist shuffle state in config before we change playlists
saveCurrentPlaylistSettings(); saveCurrentPlaylistSettings();
unlinkPlaylist(); unlinkPlaylist();
if ( !m_pageHistory.contains( page ) ) if ( !m_pageHistory.contains( page ) )
@@ -595,8 +595,8 @@ ViewManager::setPage( ViewPage* page, bool trackHistory )
if ( page->isTemporaryPage() ) if ( page->isTemporaryPage() )
emit tempPageActivated( page ); emit tempPageActivated( page );
if ( !AudioEngine::instance()->playlist() ) if ( AudioEngine::instance()->state() == AudioEngine::Stopped )
AudioEngine::instance()->setPlaylist( currentPlaylistInterface() ); AudioEngine::instance()->setPlaylist( page->playlistInterface() );
// UGH! // UGH!
if ( QObject* obj = dynamic_cast< QObject* >( currentPage() ) ) if ( QObject* obj = dynamic_cast< QObject* >( currentPage() ) )
@@ -649,6 +649,7 @@ ViewManager::unlinkPlaylist()
} }
} }
void void
ViewManager::saveCurrentPlaylistSettings() ViewManager::saveCurrentPlaylistSettings()
{ {
@@ -725,6 +726,7 @@ ViewManager::updateView()
loadCurrentPlaylistSettings(); loadCurrentPlaylistSettings();
} }
void void
ViewManager::loadCurrentPlaylistSettings() ViewManager::loadCurrentPlaylistSettings()
{ {
@@ -741,6 +743,7 @@ ViewManager::loadCurrentPlaylistSettings()
} }
} }
void void
ViewManager::onWidgetDestroyed( QWidget* widget ) ViewManager::onWidgetDestroyed( QWidget* widget )
{ {
@@ -815,18 +818,21 @@ ViewManager::createDynamicPlaylist( const Tomahawk::source_ptr& src,
p->reportCreated( p ); p->reportCreated( p );
} }
ViewPage* ViewPage*
ViewManager::pageForCollection( const collection_ptr& col ) const ViewManager::pageForCollection( const collection_ptr& col ) const
{ {
return m_collectionViews.value( col, 0 ); return m_collectionViews.value( col, 0 );
} }
ViewPage* ViewPage*
ViewManager::pageForDynPlaylist(const dynplaylist_ptr& pl) const ViewManager::pageForDynPlaylist(const dynplaylist_ptr& pl) const
{ {
return m_dynamicWidgets.value( pl, 0 ); return m_dynamicWidgets.value( pl, 0 );
} }
ViewPage* ViewPage*
ViewManager::pageForPlaylist(const playlist_ptr& pl) const ViewManager::pageForPlaylist(const playlist_ptr& pl) const
{ {