mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-24 00:14:06 +00:00
fix: repeat play the first played sound
This commit is contained in:
parent
bd736d7f37
commit
ac59713ed0
|
@ -29,14 +29,14 @@ MultimediaAudioPlayer::MultimediaAudioPlayer()
|
|||
QString MultimediaAudioPlayer::play( const char * data, int size )
|
||||
{
|
||||
stop();
|
||||
|
||||
audioBuffer.setData( data, size );
|
||||
if( !audioBuffer.open( QIODevice::ReadOnly ) )
|
||||
audioBuffer = new QBuffer();
|
||||
audioBuffer->setData( data, size );
|
||||
if( !audioBuffer->open( QIODevice::ReadOnly ) )
|
||||
return tr( "Couldn't open audio buffer for reading." );
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(6,0,0))
|
||||
player.setSourceDevice (&audioBuffer );
|
||||
#if( QT_VERSION >= QT_VERSION_CHECK( 6, 0, 0 ) )
|
||||
player.setSourceDevice( audioBuffer );
|
||||
#else
|
||||
player.setMedia( QMediaContent(), &audioBuffer );
|
||||
player.setMedia( QMediaContent(), audioBuffer );
|
||||
#endif
|
||||
player.play();
|
||||
return QString();
|
||||
|
@ -48,8 +48,12 @@ void MultimediaAudioPlayer::stop()
|
|||
#if (QT_VERSION < QT_VERSION_CHECK(6,0,0))
|
||||
player.setMedia( QMediaContent() ); // Forget about audioBuffer.
|
||||
#endif
|
||||
audioBuffer.close();
|
||||
audioBuffer.setData( QByteArray() ); // Free memory.
|
||||
if( audioBuffer )
|
||||
{
|
||||
audioBuffer->close();
|
||||
audioBuffer->setData( QByteArray() ); // Free memory.
|
||||
audioBuffer.clear();
|
||||
}
|
||||
}
|
||||
|
||||
void MultimediaAudioPlayer::onMediaPlayerError()
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#if (QT_VERSION >= QT_VERSION_CHECK(6,0,0))
|
||||
#include <QAudioOutput>
|
||||
#endif
|
||||
#include <QPointer>
|
||||
|
||||
class MultimediaAudioPlayer : public AudioPlayerInterface
|
||||
{
|
||||
|
@ -26,7 +27,7 @@ private slots:
|
|||
void onMediaPlayerError();
|
||||
|
||||
private:
|
||||
QBuffer audioBuffer;
|
||||
QPointer<QBuffer> audioBuffer;
|
||||
QMediaPlayer player; ///< Depends on audioBuffer.
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(6,0,0))
|
||||
QAudioOutput audioOutput;
|
||||
|
|
Loading…
Reference in a new issue