From 876a11a1e44a6d6a952831bcb9cff5aa0eceefdd Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Fri, 14 Jan 2011 15:53:44 +0100 Subject: [PATCH] * Fixed AudioEngine's time reporting. --- src/audio/audioengine.cpp | 28 +++++++++++++++++----------- src/audio/audioengine.h | 3 ++- src/audiocontrols.cpp | 9 +++++---- src/audiocontrols.h | 2 +- 4 files changed, 25 insertions(+), 17 deletions(-) diff --git a/src/audio/audioengine.cpp b/src/audio/audioengine.cpp index fb3a82d17..fe54605d6 100644 --- a/src/audio/audioengine.cpp +++ b/src/audio/audioengine.cpp @@ -24,7 +24,8 @@ AudioEngine::AudioEngine() m_audioOutput = new Phonon::AudioOutput( Phonon::MusicCategory, this ); Phonon::createPath( m_mediaObject, m_audioOutput ); - // connect( m_audio, SIGNAL( timeElapsed( unsigned int ) ), SLOT( timerTriggered( unsigned int ) ), Qt::DirectConnection ); + m_mediaObject->setTickInterval( 150 ); + connect( m_mediaObject, SIGNAL( tick( qint64 ) ), SLOT( timerTriggered( qint64 ) ) ); } @@ -237,19 +238,24 @@ AudioEngine::playItem( PlaylistInterface* playlist, const Tomahawk::result_ptr& void -AudioEngine::timerTriggered( unsigned int seconds ) +AudioEngine::timerTriggered( qint64 time ) { - m_timeElapsed = seconds; - emit timerSeconds( seconds ); + if ( m_timeElapsed != time / 1000 ) + { + m_timeElapsed = time / 1000; + emit timerSeconds( m_timeElapsed ); - if ( m_currentTrack->duration() == 0 ) - { - emit timerPercentage( 0 ); - } - else - { - emit timerPercentage( (unsigned int)( seconds / m_currentTrack->duration() ) ); + if ( m_currentTrack->duration() == 0 ) + { + emit timerPercentage( 0 ); + } + else + { + emit timerPercentage( ( (double)m_timeElapsed / (double)m_currentTrack->duration() ) * 100.0 ); + } } + + emit timerMilliSeconds( time ); } diff --git a/src/audio/audioengine.h b/src/audio/audioengine.h index 1dd0d981a..5236307df 100644 --- a/src/audio/audioengine.h +++ b/src/audio/audioengine.h @@ -63,6 +63,7 @@ signals: void volumeChanged( int volume /* in percent */ ); + void timerMilliSeconds( qint64 msElapsed ); void timerSeconds( unsigned int secondsElapsed ); void timerPercentage( unsigned int percentage ); @@ -73,7 +74,7 @@ private slots: void loadPreviousTrack(); void loadNextTrack(); - void timerTriggered( unsigned int seconds ); + void timerTriggered( qint64 time ); void setCurrentTrack( const Tomahawk::result_ptr& result ); diff --git a/src/audiocontrols.cpp b/src/audiocontrols.cpp index deb883d09..48b84cb58 100644 --- a/src/audiocontrols.cpp +++ b/src/audiocontrols.cpp @@ -133,7 +133,7 @@ AudioControls::AudioControls( QWidget* parent ) connect( (QObject*)APP->audioEngine(), SIGNAL( paused() ), SLOT( onPlaybackPaused() ) ); connect( (QObject*)APP->audioEngine(), SIGNAL( resumed() ), SLOT( onPlaybackResumed() ) ); connect( (QObject*)APP->audioEngine(), SIGNAL( stopped() ), SLOT( onPlaybackStopped() ) ); - connect( (QObject*)APP->audioEngine(), SIGNAL( timerSeconds( unsigned int ) ), SLOT( onPlaybackTimer( unsigned int ) ) ); + connect( (QObject*)APP->audioEngine(), SIGNAL( timerMilliSeconds( qint64 ) ), SLOT( onPlaybackTimer( qint64 ) ) ); connect( (QObject*)APP->audioEngine(), SIGNAL( volumeChanged( int ) ), SLOT( onVolumeChanged( int ) ) ); m_defaultCover = QPixmap( RESPATH "images/no-album-art-placeholder.png" ) @@ -240,7 +240,7 @@ AudioControls::onPlaybackLoading( const Tomahawk::result_ptr& result ) if ( ui->timeLeftLabel->text().isEmpty() ) ui->timeLeftLabel->setText( "-" + TomahawkUtils::timeToString( result->duration() ) ); - ui->seekSlider->setRange( 0, m_currentTrack->duration() ); + ui->seekSlider->setRange( 0, m_currentTrack->duration() * 1000 ); ui->seekSlider->setVisible( true ); /* m_playAction->setEnabled( false ); @@ -303,14 +303,15 @@ AudioControls::onPlaybackStopped() void -AudioControls::onPlaybackTimer( unsigned int seconds ) +AudioControls::onPlaybackTimer( qint64 msElapsed ) { if ( m_currentTrack.isNull() ) return; + const int seconds = msElapsed / 1000; ui->timeLabel->setText( TomahawkUtils::timeToString( seconds ) ); ui->timeLeftLabel->setText( "-" + TomahawkUtils::timeToString( m_currentTrack->duration() - seconds ) ); - ui->seekSlider->setValue( seconds ); + ui->seekSlider->setValue( msElapsed ); } diff --git a/src/audiocontrols.h b/src/audiocontrols.h index 2ba63eeed..2280d0d0f 100644 --- a/src/audiocontrols.h +++ b/src/audiocontrols.h @@ -33,7 +33,7 @@ private slots: void onPlaybackResumed(); void onPlaybackStopped(); - void onPlaybackTimer( unsigned int seconds ); + void onPlaybackTimer( qint64 msElapsed ); void onVolumeChanged( int volume ); void onRepeatClicked();