mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-30 13:24:05 +00:00
fix: audio device change handled (#1242)
* fix: audio device change handled * [autofix.ci] apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
parent
0fbcdda72f
commit
5de4690b2d
|
@ -40,11 +40,13 @@ void Request::update()
|
|||
void Request::finish()
|
||||
{
|
||||
if ( !Utils::AtomicInt::loadAcquire( isFinishedFlag ) ) {
|
||||
isFinishedFlag.ref();
|
||||
emit finished();
|
||||
{
|
||||
QMutexLocker _( &dataMutex );
|
||||
isFinishedFlag.ref();
|
||||
|
||||
QMutexLocker _( &dataMutex );
|
||||
cond.wakeAll();
|
||||
cond.wakeAll();
|
||||
}
|
||||
emit finished();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -7,6 +7,9 @@
|
|||
#if ( QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 ) )
|
||||
#include <QMediaContent>
|
||||
#endif
|
||||
#if ( QT_VERSION > QT_VERSION_CHECK( 6, 2, 0 ) )
|
||||
#include <QAudioDevice>
|
||||
#endif
|
||||
#include "multimediaaudioplayer.hh"
|
||||
|
||||
MultimediaAudioPlayer::MultimediaAudioPlayer()
|
||||
|
@ -26,6 +29,15 @@ MultimediaAudioPlayer::MultimediaAudioPlayer()
|
|||
|
||||
connect( &player, &QMediaPlayer::errorChanged, this, &MultimediaAudioPlayer::onMediaPlayerError );
|
||||
#endif
|
||||
|
||||
#if ( QT_VERSION > QT_VERSION_CHECK( 6, 2, 0 ) )
|
||||
connect( &mediaDevices, &QMediaDevices::audioOutputsChanged, this, &MultimediaAudioPlayer::audioOutputChange );
|
||||
#endif
|
||||
}
|
||||
|
||||
void MultimediaAudioPlayer::audioOutputChange()
|
||||
{
|
||||
qDebug() << "audio device changed";
|
||||
}
|
||||
|
||||
QString MultimediaAudioPlayer::play( const char * data, int size )
|
||||
|
@ -37,11 +49,15 @@ QString MultimediaAudioPlayer::play( const char * data, int size )
|
|||
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, 2, 0 ) )
|
||||
audioOutput.setDevice( QMediaDevices::defaultAudioOutput() );
|
||||
player.setAudioOutput( &audioOutput );
|
||||
#endif
|
||||
#else
|
||||
player.setMedia( QMediaContent(), audioBuffer );
|
||||
#endif
|
||||
player.play();
|
||||
return QString();
|
||||
return {};
|
||||
}
|
||||
|
||||
void MultimediaAudioPlayer::stop()
|
||||
|
|
|
@ -12,6 +12,9 @@
|
|||
#if ( QT_VERSION >= QT_VERSION_CHECK( 6, 0, 0 ) )
|
||||
#include <QAudioOutput>
|
||||
#endif
|
||||
#if ( QT_VERSION >= QT_VERSION_CHECK( 6, 2, 0 ) )
|
||||
#include <QMediaDevices>
|
||||
#endif
|
||||
#include <QPointer>
|
||||
|
||||
class MultimediaAudioPlayer: public AudioPlayerInterface
|
||||
|
@ -26,13 +29,18 @@ public:
|
|||
|
||||
private slots:
|
||||
void onMediaPlayerError();
|
||||
void audioOutputChange();
|
||||
|
||||
|
||||
private:
|
||||
QPointer< QBuffer > audioBuffer;
|
||||
QMediaPlayer player; ///< Depends on audioBuffer.
|
||||
#if ( QT_VERSION >= QT_VERSION_CHECK( 6, 0, 0 ) )
|
||||
#if ( QT_VERSION >= QT_VERSION_CHECK( 6, 2, 0 ) )
|
||||
QAudioOutput audioOutput;
|
||||
#endif
|
||||
#if ( QT_VERSION >= QT_VERSION_CHECK( 6, 2, 0 ) )
|
||||
QMediaDevices mediaDevices;
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif // MAKE_QTMULTIMEDIA_PLAYER
|
||||
|
|
Loading…
Reference in a new issue