mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-27 15:24:05 +00:00
fix: crash when clicking play audio insanely fast.
This commit is contained in:
parent
ebce607634
commit
97a3824e9f
|
@ -52,11 +52,12 @@ AudioService::~AudioService()
|
||||||
void AudioService::playMemory( const char * ptr, int size )
|
void AudioService::playMemory( const char * ptr, int size )
|
||||||
{
|
{
|
||||||
emit cancelPlaying( false );
|
emit cancelPlaying( false );
|
||||||
|
if ( !thread.isNull() ) {
|
||||||
|
thread->wait();
|
||||||
|
}
|
||||||
QByteArray audioData( ptr, size );
|
QByteArray audioData( ptr, size );
|
||||||
thread = std::make_shared< DecoderThread >( audioData, this );
|
thread.reset( new DecoderThread( audioData, this ) );
|
||||||
connect( this, &AudioService::cancelPlaying, thread.get(), [ this ]( bool waitFinished ) {
|
connect( this, &AudioService::cancelPlaying, thread.get(), &DecoderThread::cancel );
|
||||||
thread->cancel( waitFinished );
|
|
||||||
} );
|
|
||||||
thread->start();
|
thread->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -263,6 +264,11 @@ bool DecoderContext::openOutputDevice( QString & errorString )
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if ( audioOutput == nullptr ) {
|
||||||
|
errorString += QStringLiteral( "Failed to create audioOutput." );
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
audioOutput->setAudioFormat( 44100, codecContext_->channels );
|
audioOutput->setAudioFormat( 44100, codecContext_->channels );
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@ class DecoderThread;
|
||||||
class AudioService: public QObject
|
class AudioService: public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
std::shared_ptr< DecoderThread > thread;
|
QScopedPointer< DecoderThread > thread;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static AudioService & instance();
|
static AudioService & instance();
|
||||||
|
|
Loading…
Reference in a new issue