1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-07-31 03:10:12 +02:00

* Fixed AudioEngine's time reporting.

This commit is contained in:
Christian Muehlhaeuser
2011-01-14 15:53:44 +01:00
parent 41512c4b61
commit 876a11a1e4
4 changed files with 25 additions and 17 deletions

View File

@@ -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 );
}

View File

@@ -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 );

View File

@@ -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 );
}

View File

@@ -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();