1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-23 01:09:42 +01:00

* Ok, let's try that publicly. AudioState queue to work around the Phonon state mess.

This commit is contained in:
Christian Muehlhaeuser 2012-05-24 10:44:33 +02:00
parent 3225407118
commit b51e7390ba
2 changed files with 63 additions and 10 deletions

View File

@ -133,9 +133,7 @@ AudioEngine::play()
if ( isPaused() )
{
setVolume( m_volume );
m_mediaObject->play();
setVolume( m_volume );
queueState( Playing );
emit resumed();
sendNowPlayingNotification( Tomahawk::InfoSystem::InfoNowResumed );
@ -151,7 +149,8 @@ AudioEngine::pause()
tDebug( LOGEXTRA ) << Q_FUNC_INFO;
m_volume = volume();
m_mediaObject->pause();
queueState( Paused );
emit paused();
Tomahawk::InfoSystem::InfoSystem::instance()->pushInfo( Tomahawk::InfoSystem::InfoPushData( s_aeInfoIdentifier, Tomahawk::InfoSystem::InfoNowPaused, QVariant(), Tomahawk::InfoSystem::PushNoFlag ) );
@ -185,7 +184,6 @@ AudioEngine::stop( AudioErrorCode errorCode )
sendWaitingNotification();
Tomahawk::InfoSystem::InfoPushData pushData( s_aeInfoIdentifier, Tomahawk::InfoSystem::InfoNowStopped, QVariant(), Tomahawk::InfoSystem::PushNoFlag );
Tomahawk::InfoSystem::InfoSystem::instance()->pushInfo( pushData );
}
@ -485,8 +483,7 @@ AudioEngine::loadTrack( const Tomahawk::result_ptr& result )
m_input.clear();
}
m_input = io;
m_mediaObject->play();
queueState( Playing );
emit started( m_currentTrack );
if ( TomahawkSettings::instance()->privateListeningMode() != TomahawkSettings::FullyPrivate )
@ -734,6 +731,16 @@ AudioEngine::onStateChanged( Phonon::State newState, Phonon::State oldState )
}
}
}
if ( newState == Phonon::PausedState || newState == Phonon::PlayingState )
{
tDebug() << "Phonon state now:" << newState;
if ( m_stateQueue.count() )
{
AudioState qState = m_stateQueue.dequeue();
checkStateQueue();
}
}
}
@ -835,6 +842,47 @@ AudioEngine::isLocalResult( const QString& url ) const
}
void
AudioEngine::checkStateQueue()
{
if ( m_stateQueue.count() )
{
AudioState state = m_stateQueue.head();
tDebug() << "Applying state command:" << state;
switch ( state )
{
case Playing:
{
setVolume( m_volume );
m_mediaObject->play();
setVolume( m_volume );
}
case Paused:
{
m_mediaObject->pause();
}
}
}
else
tDebug() << "Queue is empty";
}
void
AudioEngine::queueState( AudioState state )
{
tDebug() << "Enqueuing state command:" << state << m_stateQueue.count();
m_stateQueue.enqueue( state );
if ( m_stateQueue.count() == 1 )
{
checkStateQueue();
}
}
void
AudioEngine::setState( AudioState state )
{

View File

@ -22,6 +22,7 @@
#include <QtCore/QObject>
#include <QtCore/QTimer>
#include <QtCore/QQueue>
#include <phonon/MediaObject>
#include <phonon/AudioOutput>
@ -29,13 +30,12 @@
#include "libtomahawk/infosystem/InfoSystem.h"
#include "Result.h"
#include "Typedefs.h"
#include "Result.h"
#include "PlaylistInterface.h"
#include "DllMacro.h"
class DLLEXPORT AudioEngine : public QObject
{
Q_OBJECT
@ -139,6 +139,9 @@ private slots:
void sendWaitingNotification() const;
private:
void checkStateQueue();
void queueState( AudioState state );
void setState( AudioState state );
bool isHttpResult( const QString& ) const;
@ -162,9 +165,11 @@ private:
bool m_waitingOnNewTrack;
mutable QStringList m_supportedMimeTypes;
AudioState m_state;
unsigned int m_volume;
AudioState m_state;
QQueue< AudioState > m_stateQueue;
static AudioEngine* s_instance;
};