mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-24 01:39:42 +01:00
* Fixed TWK-279 - Play first track of a playlist if play is clicked and nothing is playing yet.
This commit is contained in:
parent
4a3f157718
commit
6bfbbce05f
@ -46,18 +46,18 @@ AudioEngine::instance()
|
||||
AudioEngine::AudioEngine()
|
||||
: QObject()
|
||||
, m_isPlayingHttp( false )
|
||||
// , m_playlist( 0 )
|
||||
// , m_currentTrackPlaylist( 0 )
|
||||
, m_queue( 0 )
|
||||
, m_timeElapsed( 0 )
|
||||
, m_expectStop( false )
|
||||
, m_waitingOnNewTrack( false )
|
||||
, m_infoSystemConnected( false )
|
||||
, m_state( Stopped )
|
||||
{
|
||||
s_instance = this;
|
||||
qDebug() << "Init AudioEngine";
|
||||
|
||||
qRegisterMetaType< AudioErrorCode >("AudioErrorCode");
|
||||
qRegisterMetaType< AudioState >("AudioState");
|
||||
|
||||
m_mediaObject = new Phonon::MediaObject( this );
|
||||
m_audioOutput = new Phonon::AudioOutput( Phonon::MusicCategory, this );
|
||||
@ -130,6 +130,7 @@ AudioEngine::pause()
|
||||
|
||||
m_mediaObject->pause();
|
||||
emit paused();
|
||||
|
||||
Tomahawk::InfoSystem::InfoSystem::instance()->pushInfo( s_aeInfoIdentifier, Tomahawk::InfoSystem::InfoNowPaused, QVariant() );
|
||||
}
|
||||
|
||||
@ -139,6 +140,7 @@ AudioEngine::stop()
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
|
||||
setState( Stopped );
|
||||
m_mediaObject->stop();
|
||||
|
||||
if ( !m_playlist.isNull() )
|
||||
@ -227,6 +229,7 @@ AudioEngine::setVolume( int percentage )
|
||||
emit volumeChanged( percentage );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
AudioEngine::mute()
|
||||
{
|
||||
@ -416,6 +419,7 @@ AudioEngine::loadTrack( const Tomahawk::result_ptr& result )
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
AudioEngine::loadPreviousTrack()
|
||||
{
|
||||
@ -513,6 +517,8 @@ AudioEngine::onStateChanged( Phonon::State newState, Phonon::State oldState )
|
||||
qDebug() << "Phonon Error:" << m_mediaObject->errorString() << m_mediaObject->errorType();
|
||||
return;
|
||||
}
|
||||
if ( newState == Phonon::PlayingState )
|
||||
setState( Playing );
|
||||
|
||||
if ( !m_expectStop )
|
||||
return;
|
||||
@ -527,6 +533,10 @@ AudioEngine::onStateChanged( Phonon::State newState, Phonon::State oldState )
|
||||
case Phonon::PausedState:
|
||||
{
|
||||
stopped = ( duration - 1000 < m_mediaObject->currentTime() );
|
||||
|
||||
if ( !stopped )
|
||||
setState( Paused );
|
||||
|
||||
break;
|
||||
}
|
||||
case Phonon::StoppedState:
|
||||
@ -614,3 +624,13 @@ AudioEngine::isLocalResult( const QString& url ) const
|
||||
{
|
||||
return url.startsWith( "file://" );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
AudioEngine::setState( AudioState state )
|
||||
{
|
||||
AudioState oldState = m_state;
|
||||
m_state = state;
|
||||
|
||||
emit stateChanged( state, oldState );
|
||||
}
|
||||
|
@ -45,6 +45,7 @@ Q_OBJECT
|
||||
|
||||
public:
|
||||
enum AudioErrorCode { StreamReadError, AudioDeviceError, DecodeError };
|
||||
enum AudioState { Stopped, Playing, Paused };
|
||||
|
||||
static AudioEngine* instance();
|
||||
|
||||
@ -52,8 +53,11 @@ public:
|
||||
~AudioEngine();
|
||||
|
||||
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! */
|
||||
Tomahawk::PlaylistInterface* currentTrackPlaylist() const { return m_currentTrackPlaylist.data(); }
|
||||
@ -98,6 +102,7 @@ signals:
|
||||
void paused();
|
||||
void resumed();
|
||||
|
||||
void stateChanged( AudioState newState, AudioState oldState );
|
||||
void volumeChanged( int volume /* in percent */ );
|
||||
|
||||
void timerMilliSeconds( qint64 msElapsed );
|
||||
@ -120,8 +125,11 @@ private slots:
|
||||
void setCurrentTrack( const Tomahawk::result_ptr& result );
|
||||
|
||||
private:
|
||||
void setState( AudioState state );
|
||||
|
||||
bool isHttpResult( const QString& ) const;
|
||||
bool isLocalResult( const QString& ) const;
|
||||
|
||||
void sendWaitingNotification() const;
|
||||
void sendNowPlayingNotification();
|
||||
|
||||
@ -142,6 +150,8 @@ private:
|
||||
bool m_waitingOnNewTrack;
|
||||
bool m_infoSystemConnected;
|
||||
|
||||
AudioState m_state;
|
||||
|
||||
static AudioEngine* s_instance;
|
||||
};
|
||||
|
||||
|
@ -55,7 +55,6 @@ namespace Tomahawk
|
||||
typedef QString QID; //query id
|
||||
typedef QString RID; //result id
|
||||
|
||||
|
||||
enum GeneratorMode {
|
||||
OnDemand = 0,
|
||||
Static
|
||||
@ -64,6 +63,7 @@ namespace Tomahawk
|
||||
}; // ns
|
||||
|
||||
typedef int AudioErrorCode;
|
||||
typedef int AudioState;
|
||||
|
||||
// creates 36char ascii guid without {} around it
|
||||
inline static QString uuid()
|
||||
|
@ -410,6 +410,7 @@ ViewManager::showSuperCollection()
|
||||
return shown;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
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
|
||||
saveCurrentPlaylistSettings();
|
||||
|
||||
unlinkPlaylist();
|
||||
|
||||
if ( !m_pageHistory.contains( page ) )
|
||||
@ -592,11 +592,11 @@ ViewManager::setPage( ViewPage* page, bool trackHistory )
|
||||
qDebug() << "View page shown:" << page->title();
|
||||
emit viewPageActivated( page );
|
||||
|
||||
if( page->isTemporaryPage() )
|
||||
if ( page->isTemporaryPage() )
|
||||
emit tempPageActivated( page );
|
||||
|
||||
if ( !AudioEngine::instance()->playlist() )
|
||||
AudioEngine::instance()->setPlaylist( currentPlaylistInterface() );
|
||||
if ( AudioEngine::instance()->state() == AudioEngine::Stopped )
|
||||
AudioEngine::instance()->setPlaylist( page->playlistInterface() );
|
||||
|
||||
// UGH!
|
||||
if ( QObject* obj = dynamic_cast< QObject* >( currentPage() ) )
|
||||
@ -649,6 +649,7 @@ ViewManager::unlinkPlaylist()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ViewManager::saveCurrentPlaylistSettings()
|
||||
{
|
||||
@ -725,6 +726,7 @@ ViewManager::updateView()
|
||||
loadCurrentPlaylistSettings();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ViewManager::loadCurrentPlaylistSettings()
|
||||
{
|
||||
@ -741,6 +743,7 @@ ViewManager::loadCurrentPlaylistSettings()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ViewManager::onWidgetDestroyed( QWidget* widget )
|
||||
{
|
||||
@ -815,18 +818,21 @@ ViewManager::createDynamicPlaylist( const Tomahawk::source_ptr& src,
|
||||
p->reportCreated( p );
|
||||
}
|
||||
|
||||
|
||||
ViewPage*
|
||||
ViewManager::pageForCollection( const collection_ptr& col ) const
|
||||
{
|
||||
return m_collectionViews.value( col, 0 );
|
||||
}
|
||||
|
||||
|
||||
ViewPage*
|
||||
ViewManager::pageForDynPlaylist(const dynplaylist_ptr& pl) const
|
||||
{
|
||||
return m_dynamicWidgets.value( pl, 0 );
|
||||
}
|
||||
|
||||
|
||||
ViewPage*
|
||||
ViewManager::pageForPlaylist(const playlist_ptr& pl) const
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user