mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-27 15: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()
|
void Request::finish()
|
||||||
{
|
{
|
||||||
if ( !Utils::AtomicInt::loadAcquire( isFinishedFlag ) ) {
|
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 ) )
|
#if ( QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 ) )
|
||||||
#include <QMediaContent>
|
#include <QMediaContent>
|
||||||
#endif
|
#endif
|
||||||
|
#if ( QT_VERSION > QT_VERSION_CHECK( 6, 2, 0 ) )
|
||||||
|
#include <QAudioDevice>
|
||||||
|
#endif
|
||||||
#include "multimediaaudioplayer.hh"
|
#include "multimediaaudioplayer.hh"
|
||||||
|
|
||||||
MultimediaAudioPlayer::MultimediaAudioPlayer()
|
MultimediaAudioPlayer::MultimediaAudioPlayer()
|
||||||
|
@ -26,6 +29,15 @@ MultimediaAudioPlayer::MultimediaAudioPlayer()
|
||||||
|
|
||||||
connect( &player, &QMediaPlayer::errorChanged, this, &MultimediaAudioPlayer::onMediaPlayerError );
|
connect( &player, &QMediaPlayer::errorChanged, this, &MultimediaAudioPlayer::onMediaPlayerError );
|
||||||
#endif
|
#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 )
|
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." );
|
return tr( "Couldn't open audio buffer for reading." );
|
||||||
#if ( QT_VERSION >= QT_VERSION_CHECK( 6, 0, 0 ) )
|
#if ( QT_VERSION >= QT_VERSION_CHECK( 6, 0, 0 ) )
|
||||||
player.setSourceDevice( audioBuffer );
|
player.setSourceDevice( audioBuffer );
|
||||||
|
#if ( QT_VERSION > QT_VERSION_CHECK( 6, 2, 0 ) )
|
||||||
|
audioOutput.setDevice( QMediaDevices::defaultAudioOutput() );
|
||||||
|
player.setAudioOutput( &audioOutput );
|
||||||
|
#endif
|
||||||
#else
|
#else
|
||||||
player.setMedia( QMediaContent(), audioBuffer );
|
player.setMedia( QMediaContent(), audioBuffer );
|
||||||
#endif
|
#endif
|
||||||
player.play();
|
player.play();
|
||||||
return QString();
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
void MultimediaAudioPlayer::stop()
|
void MultimediaAudioPlayer::stop()
|
||||||
|
|
|
@ -12,6 +12,9 @@
|
||||||
#if ( QT_VERSION >= QT_VERSION_CHECK( 6, 0, 0 ) )
|
#if ( QT_VERSION >= QT_VERSION_CHECK( 6, 0, 0 ) )
|
||||||
#include <QAudioOutput>
|
#include <QAudioOutput>
|
||||||
#endif
|
#endif
|
||||||
|
#if ( QT_VERSION >= QT_VERSION_CHECK( 6, 2, 0 ) )
|
||||||
|
#include <QMediaDevices>
|
||||||
|
#endif
|
||||||
#include <QPointer>
|
#include <QPointer>
|
||||||
|
|
||||||
class MultimediaAudioPlayer: public AudioPlayerInterface
|
class MultimediaAudioPlayer: public AudioPlayerInterface
|
||||||
|
@ -26,13 +29,18 @@ public:
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onMediaPlayerError();
|
void onMediaPlayerError();
|
||||||
|
void audioOutputChange();
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QPointer< QBuffer > audioBuffer;
|
QPointer< QBuffer > audioBuffer;
|
||||||
QMediaPlayer player; ///< Depends on 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;
|
QAudioOutput audioOutput;
|
||||||
#endif
|
#endif
|
||||||
|
#if ( QT_VERSION >= QT_VERSION_CHECK( 6, 2, 0 ) )
|
||||||
|
QMediaDevices mediaDevices;
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MAKE_QTMULTIMEDIA_PLAYER
|
#endif // MAKE_QTMULTIMEDIA_PLAYER
|
||||||
|
|
Loading…
Reference in a new issue