mirror of
https://github.com/overte-org/overte.git
synced 2025-06-17 14:40:46 +02:00
Audio Handler fix
This commit is contained in:
parent
b890a29b3a
commit
e02e810399
1 changed files with 37 additions and 32 deletions
|
@ -121,10 +121,10 @@ uint64_t uvec2ToUint64(const uvec2& v) {
|
|||
class AudioHandler : public QObject, QRunnable {
|
||||
Q_OBJECT
|
||||
public:
|
||||
AudioHandler(QObject* container, const QString& deviceName, int runDelayMs = 0, QObject* parent = nullptr) : QObject(parent) {
|
||||
_container = container;
|
||||
AudioHandler(OffscreenQmlSurface* surface, const QString& deviceName, int runDelayMs = 0, QObject* parent = nullptr) : QObject(parent) {
|
||||
_newTargetDevice = deviceName;
|
||||
_runDelayMs = runDelayMs;
|
||||
_surface = surface;
|
||||
setAutoDelete(true);
|
||||
QThreadPool::globalInstance()->start(this);
|
||||
}
|
||||
|
@ -139,7 +139,10 @@ public:
|
|||
QThread::msleep(_runDelayMs);
|
||||
}
|
||||
auto audioIO = DependencyManager::get<AudioClient>();
|
||||
for (auto player : _container->findChildren<QMediaPlayer*>()) {
|
||||
|
||||
auto rootItem = _surface->getRootItem();
|
||||
if (rootItem) {
|
||||
for (auto player : rootItem->findChildren<QMediaPlayer*>()) {
|
||||
auto mediaState = player->state();
|
||||
QMediaService *svc = player->service();
|
||||
if (nullptr == svc) {
|
||||
|
@ -166,16 +169,18 @@ public:
|
|||
// this will reset it back to a paused state
|
||||
if (mediaState == QMediaPlayer::State::PausedState) {
|
||||
player->pause();
|
||||
} else if (mediaState == QMediaPlayer::State::StoppedState) {
|
||||
}
|
||||
else if (mediaState == QMediaPlayer::State::StoppedState) {
|
||||
player->stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
qDebug() << "QML Audio changed to " << _newTargetDevice;
|
||||
}
|
||||
|
||||
private:
|
||||
QString _newTargetDevice;
|
||||
QObject* _container;
|
||||
OffscreenQmlSurface* _surface;
|
||||
int _runDelayMs;
|
||||
};
|
||||
|
||||
|
@ -701,7 +706,7 @@ void OffscreenQmlSurface::forceQmlAudioOutputDeviceUpdate() {
|
|||
QString deviceName = audioIO->getActiveAudioDevice(QAudio::AudioOutput).deviceName();
|
||||
int waitForAudioQmlMs = 200;
|
||||
// The audio device need to be change using oth
|
||||
new AudioHandler(_rootItem, deviceName, waitForAudioQmlMs);
|
||||
new AudioHandler(this, deviceName, waitForAudioQmlMs);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue