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:
xiaoyifang 2023-10-15 23:15:45 +08:00 committed by GitHub
parent 0fbcdda72f
commit 5de4690b2d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 6 deletions

View file

@ -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();
}
}

View file

@ -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()

View file

@ -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