mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-07-31 19:30:21 +02:00
Fix seeking for local files; also, disable dragging the seek slider if phonon reports that the object cannot be seeked, to not have ugly jumping around.
This commit is contained in:
@@ -126,6 +126,7 @@ AudioControls::AudioControls( QWidget* parent )
|
||||
connect( AudioEngine::instance(), SIGNAL( paused() ), SLOT( onPlaybackPaused() ) );
|
||||
connect( AudioEngine::instance(), SIGNAL( resumed() ), SLOT( onPlaybackResumed() ) );
|
||||
connect( AudioEngine::instance(), SIGNAL( stopped() ), SLOT( onPlaybackStopped() ) );
|
||||
connect( AudioEngine::instance(), SIGNAL( seeked( qint64 ) ), SLOT( onPlaybackSeeked( qint64 ) ) );
|
||||
connect( AudioEngine::instance(), SIGNAL( timerMilliSeconds( qint64 ) ), SLOT( onPlaybackTimer( qint64 ) ) );
|
||||
connect( AudioEngine::instance(), SIGNAL( volumeChanged( int ) ), SLOT( onVolumeChanged( int ) ) );
|
||||
|
||||
@@ -204,6 +205,7 @@ AudioControls::onPlaybackStarted( const Tomahawk::result_ptr& result )
|
||||
m_sliderTimeLine.setDuration( duration );
|
||||
m_sliderTimeLine.setFrameRange( 0, duration );
|
||||
m_sliderTimeLine.setCurrentTime( 0 );
|
||||
m_seekMsecs = -1;
|
||||
|
||||
ui->seekSlider->setVisible( true );
|
||||
|
||||
@@ -328,6 +330,16 @@ AudioControls::onPlaybackResumed()
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
AudioControls::onPlaybackSeeked( qint64 msec )
|
||||
{
|
||||
//tDebug( LOGEXTRA ) << Q_FUNC_INFO << " setting current timer to " << msec;
|
||||
m_sliderTimeLine.setPaused( true );
|
||||
m_sliderTimeLine.setCurrentTime( msec );
|
||||
m_seekMsecs = msec;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
AudioControls::onPlaybackStopped()
|
||||
{
|
||||
@@ -353,6 +365,7 @@ AudioControls::onPlaybackStopped()
|
||||
void
|
||||
AudioControls::onPlaybackTimer( qint64 msElapsed )
|
||||
{
|
||||
//tDebug( LOGEXTRA ) << Q_FUNC_INFO << " msElapsed = " << msElapsed << " and timer current time = " << m_sliderTimeLine.currentTime() << " and m_seekMsecs = " << m_seekMsecs;
|
||||
if ( m_currentTrack.isNull() )
|
||||
return;
|
||||
|
||||
@@ -362,10 +375,23 @@ AudioControls::onPlaybackTimer( qint64 msElapsed )
|
||||
ui->timeLabel->setText( TomahawkUtils::timeToString( seconds ) );
|
||||
ui->timeLeftLabel->setText( "-" + TomahawkUtils::timeToString( m_currentTrack->duration() - seconds ) );
|
||||
|
||||
if ( m_sliderTimeLine.currentTime() > msElapsed )
|
||||
if ( m_sliderTimeLine.currentTime() > msElapsed || ( m_seekMsecs != -1 && m_sliderTimeLine.currentTime() < msElapsed ) )
|
||||
{
|
||||
m_sliderTimeLine.setPaused( true );
|
||||
m_sliderTimeLine.setCurrentTime( msElapsed );
|
||||
else if ( m_sliderTimeLine.duration() > msElapsed && m_sliderTimeLine.state() == QTimeLine::NotRunning )
|
||||
m_seekMsecs = -1;
|
||||
m_sliderTimeLine.resume();
|
||||
}
|
||||
else if ( m_sliderTimeLine.duration() > msElapsed && m_sliderTimeLine.state() == QTimeLine::NotRunning )
|
||||
{
|
||||
ui->seekSlider->setEnabled( AudioEngine::instance()->canSeek() );
|
||||
m_sliderTimeLine.resume();
|
||||
}
|
||||
else if ( m_sliderTimeLine.state() == QTimeLine::Paused && AudioEngine::instance()->state() != AudioEngine::Paused )
|
||||
{
|
||||
ui->seekSlider->setEnabled( AudioEngine::instance()->canSeek() );
|
||||
m_sliderTimeLine.resume();
|
||||
}
|
||||
|
||||
ui->seekSlider->blockSignals( false );
|
||||
}
|
||||
|
@@ -61,6 +61,7 @@ private slots:
|
||||
void onPlaybackLoading( const Tomahawk::result_ptr& result );
|
||||
void onPlaybackPaused();
|
||||
void onPlaybackResumed();
|
||||
void onPlaybackSeeked( qint64 msec );
|
||||
void onPlaybackStopped();
|
||||
|
||||
void onPlaybackTimer( qint64 msElapsed );
|
||||
@@ -91,6 +92,7 @@ private:
|
||||
bool m_shuffled;
|
||||
|
||||
QTimeLine m_sliderTimeLine;
|
||||
qint64 m_seekMsecs;
|
||||
};
|
||||
|
||||
#endif // AUDIOCONTROLS_H
|
||||
|
@@ -244,7 +244,10 @@ AudioEngine::canGoPrevious()
|
||||
bool
|
||||
AudioEngine::canSeek()
|
||||
{
|
||||
return !m_playlist.isNull() && ( m_playlist.data()->seekRestrictions() != PlaylistInterface::NoSeek );
|
||||
bool phononCanSeek = true;
|
||||
if ( m_mediaObject && m_mediaObject->isValid() )
|
||||
phononCanSeek = m_mediaObject->isSeekable();
|
||||
return !m_playlist.isNull() && ( m_playlist.data()->seekRestrictions() != PlaylistInterface::NoSeek ) && phononCanSeek;
|
||||
}
|
||||
|
||||
void
|
||||
|
Reference in New Issue
Block a user