mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-08 07:07:05 +02:00
Fix some corner cases affecting the time slider, such as when the streaming fails
This commit is contained in:
@@ -98,9 +98,12 @@ AudioControls::AudioControls( QWidget* parent )
|
|||||||
ui->volumeSlider->setRange( 0, 100 );
|
ui->volumeSlider->setRange( 0, 100 );
|
||||||
ui->volumeSlider->setValue( AudioEngine::instance()->volume() );
|
ui->volumeSlider->setValue( AudioEngine::instance()->volume() );
|
||||||
|
|
||||||
|
m_phononTickCheckTimer.setSingleShot( true );
|
||||||
|
|
||||||
m_sliderTimeLine.setCurveShape( QTimeLine::LinearCurve );
|
m_sliderTimeLine.setCurveShape( QTimeLine::LinearCurve );
|
||||||
ui->seekSlider->setTimeLine( &m_sliderTimeLine );
|
ui->seekSlider->setTimeLine( &m_sliderTimeLine );
|
||||||
|
|
||||||
|
connect( &m_phononTickCheckTimer, SIGNAL( timeout() ), SLOT( phononTickCheckTimeout() ) );
|
||||||
connect( &m_sliderTimeLine, SIGNAL( frameChanged( int ) ), ui->seekSlider, SLOT( setValue( int ) ) );
|
connect( &m_sliderTimeLine, SIGNAL( frameChanged( int ) ), ui->seekSlider, SLOT( setValue( int ) ) );
|
||||||
|
|
||||||
connect( ui->seekSlider, SIGNAL( valueChanged( int ) ), AudioEngine::instance(), SLOT( seek( int ) ) );
|
connect( ui->seekSlider, SIGNAL( valueChanged( int ) ), AudioEngine::instance(), SLOT( seek( int ) ) );
|
||||||
@@ -176,6 +179,13 @@ AudioControls::changeEvent( QEvent* e )
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
AudioControls::phononTickCheckTimeout()
|
||||||
|
{
|
||||||
|
onPlaybackTimer( m_lastSliderCheck );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
AudioControls::onVolumeChanged( int volume )
|
AudioControls::onVolumeChanged( int volume )
|
||||||
{
|
{
|
||||||
@@ -204,6 +214,8 @@ AudioControls::onPlaybackStarted( const Tomahawk::result_ptr& result )
|
|||||||
ui->seekSlider->setRange( 0, duration );
|
ui->seekSlider->setRange( 0, duration );
|
||||||
ui->seekSlider->setValue( 0 );
|
ui->seekSlider->setValue( 0 );
|
||||||
|
|
||||||
|
m_phononTickCheckTimer.stop();
|
||||||
|
|
||||||
m_sliderTimeLine.stop();
|
m_sliderTimeLine.stop();
|
||||||
m_sliderTimeLine.setDuration( duration );
|
m_sliderTimeLine.setDuration( duration );
|
||||||
m_sliderTimeLine.setFrameRange( 0, duration );
|
m_sliderTimeLine.setFrameRange( 0, duration );
|
||||||
@@ -344,6 +356,7 @@ AudioControls::onPlaybackSeeked( qint64 msec )
|
|||||||
tDebug( LOGEXTRA ) << Q_FUNC_INFO << " setting current timer to " << msec;
|
tDebug( LOGEXTRA ) << Q_FUNC_INFO << " setting current timer to " << msec;
|
||||||
m_sliderTimeLine.setPaused( true );
|
m_sliderTimeLine.setPaused( true );
|
||||||
m_sliderTimeLine.setCurrentTime( msec );
|
m_sliderTimeLine.setCurrentTime( msec );
|
||||||
|
m_lastSliderCheck = msec;
|
||||||
m_seekMsecs = msec;
|
m_seekMsecs = msec;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -373,16 +386,22 @@ AudioControls::onPlaybackStopped()
|
|||||||
void
|
void
|
||||||
AudioControls::onPlaybackTimer( qint64 msElapsed )
|
AudioControls::onPlaybackTimer( qint64 msElapsed )
|
||||||
{
|
{
|
||||||
// tDebug( LOGEXTRA ) << Q_FUNC_INFO << "msElapsed =" << msElapsed << "and timer current time =" << m_sliderTimeLine.currentTime() << "and m_seekMsecs =" << m_seekMsecs;
|
//tDebug( LOGEXTRA ) << Q_FUNC_INFO << "msElapsed =" << msElapsed << "and timer current time =" << m_sliderTimeLine.currentTime() << "and m_seekMsecs =" << m_seekMsecs;
|
||||||
if ( msElapsed > 0 && msElapsed - 500 < m_lastSliderCheck )
|
if ( msElapsed > 0 && msElapsed != m_lastSliderCheck && m_seekMsecs == -1 && msElapsed - 500 < m_lastSliderCheck )
|
||||||
return;
|
return;
|
||||||
m_lastSliderCheck = msElapsed;
|
m_lastSliderCheck = msElapsed;
|
||||||
|
|
||||||
if ( m_currentTrack.isNull() )
|
if ( m_currentTrack.isNull() )
|
||||||
|
{
|
||||||
|
m_sliderTimeLine.stop();
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
ui->seekSlider->blockSignals( true );
|
ui->seekSlider->blockSignals( true );
|
||||||
|
|
||||||
|
if ( sender() != &m_phononTickCheckTimer )
|
||||||
|
m_phononTickCheckTimer.start( 1000 );
|
||||||
|
|
||||||
const int seconds = msElapsed / 1000;
|
const int seconds = msElapsed / 1000;
|
||||||
ui->timeLabel->setText( TomahawkUtils::timeToString( seconds ) );
|
ui->timeLabel->setText( TomahawkUtils::timeToString( seconds ) );
|
||||||
ui->timeLeftLabel->setText( "-" + TomahawkUtils::timeToString( m_currentTrack->duration() - seconds ) );
|
ui->timeLeftLabel->setText( "-" + TomahawkUtils::timeToString( m_currentTrack->duration() - seconds ) );
|
||||||
@@ -391,7 +410,10 @@ AudioControls::onPlaybackTimer( qint64 msElapsed )
|
|||||||
{
|
{
|
||||||
if ( m_sliderTimeLine.currentTime() != msElapsed )
|
if ( m_sliderTimeLine.currentTime() != msElapsed )
|
||||||
{
|
{
|
||||||
|
m_sliderTimeLine.setPaused( true );
|
||||||
m_noTimeChange = false;
|
m_noTimeChange = false;
|
||||||
|
m_sliderTimeLine.setCurrentTime( msElapsed );
|
||||||
|
m_seekMsecs = -1;
|
||||||
m_sliderTimeLine.resume();
|
m_sliderTimeLine.resume();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -405,10 +427,10 @@ AudioControls::onPlaybackTimer( qint64 msElapsed )
|
|||||||
|
|
||||||
m_sliderTimeLine.setCurrentTime( msElapsed );
|
m_sliderTimeLine.setCurrentTime( msElapsed );
|
||||||
m_seekMsecs = -1;
|
m_seekMsecs = -1;
|
||||||
if ( AudioEngine::instance()->state() != AudioEngine::Paused )
|
if ( AudioEngine::instance()->state() != AudioEngine::Paused && sender() != &m_phononTickCheckTimer )
|
||||||
m_sliderTimeLine.resume();
|
m_sliderTimeLine.resume();
|
||||||
}
|
}
|
||||||
else if ( m_sliderTimeLine.duration() > msElapsed && m_sliderTimeLine.state() == QTimeLine::NotRunning )
|
else if ( m_sliderTimeLine.duration() > msElapsed && m_sliderTimeLine.state() == QTimeLine::NotRunning && AudioEngine::instance()->state() == AudioEngine::Playing )
|
||||||
{
|
{
|
||||||
ui->seekSlider->setEnabled( AudioEngine::instance()->canSeek() );
|
ui->seekSlider->setEnabled( AudioEngine::instance()->canSeek() );
|
||||||
m_sliderTimeLine.start();
|
m_sliderTimeLine.start();
|
||||||
|
@@ -20,6 +20,7 @@
|
|||||||
#define AUDIOCONTROLS_H
|
#define AUDIOCONTROLS_H
|
||||||
|
|
||||||
#include <QtGui/QWidget>
|
#include <QtGui/QWidget>
|
||||||
|
#include <QtCore/QTimer>
|
||||||
#include <QtCore/QTimeLine>
|
#include <QtCore/QTimeLine>
|
||||||
|
|
||||||
#include "result.h"
|
#include "result.h"
|
||||||
@@ -59,6 +60,8 @@ protected:
|
|||||||
void dropEvent ( QDropEvent* );
|
void dropEvent ( QDropEvent* );
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
void phononTickCheckTimeout();
|
||||||
|
|
||||||
void onPlaybackStarted( const Tomahawk::result_ptr& result );
|
void onPlaybackStarted( const Tomahawk::result_ptr& result );
|
||||||
void onPlaybackLoading( const Tomahawk::result_ptr& result );
|
void onPlaybackLoading( const Tomahawk::result_ptr& result );
|
||||||
void onPlaybackPaused();
|
void onPlaybackPaused();
|
||||||
@@ -93,6 +96,7 @@ private:
|
|||||||
Tomahawk::PlaylistInterface::RepeatMode m_repeatMode;
|
Tomahawk::PlaylistInterface::RepeatMode m_repeatMode;
|
||||||
bool m_shuffled;
|
bool m_shuffled;
|
||||||
|
|
||||||
|
QTimer m_phononTickCheckTimer;
|
||||||
QTimeLine m_sliderTimeLine;
|
QTimeLine m_sliderTimeLine;
|
||||||
qint64 m_seekMsecs;
|
qint64 m_seekMsecs;
|
||||||
qint64 m_lastSliderCheck;
|
qint64 m_lastSliderCheck;
|
||||||
|
Reference in New Issue
Block a user