mirror of
https://github.com/overte-org/overte.git
synced 2025-06-16 17:40:28 +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 {
|
class AudioHandler : public QObject, QRunnable {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
AudioHandler(QObject* container, const QString& deviceName, int runDelayMs = 0, QObject* parent = nullptr) : QObject(parent) {
|
AudioHandler(OffscreenQmlSurface* surface, const QString& deviceName, int runDelayMs = 0, QObject* parent = nullptr) : QObject(parent) {
|
||||||
_container = container;
|
|
||||||
_newTargetDevice = deviceName;
|
_newTargetDevice = deviceName;
|
||||||
_runDelayMs = runDelayMs;
|
_runDelayMs = runDelayMs;
|
||||||
|
_surface = surface;
|
||||||
setAutoDelete(true);
|
setAutoDelete(true);
|
||||||
QThreadPool::globalInstance()->start(this);
|
QThreadPool::globalInstance()->start(this);
|
||||||
}
|
}
|
||||||
|
@ -139,35 +139,40 @@ public:
|
||||||
QThread::msleep(_runDelayMs);
|
QThread::msleep(_runDelayMs);
|
||||||
}
|
}
|
||||||
auto audioIO = DependencyManager::get<AudioClient>();
|
auto audioIO = DependencyManager::get<AudioClient>();
|
||||||
for (auto player : _container->findChildren<QMediaPlayer*>()) {
|
|
||||||
auto mediaState = player->state();
|
auto rootItem = _surface->getRootItem();
|
||||||
QMediaService *svc = player->service();
|
if (rootItem) {
|
||||||
if (nullptr == svc) {
|
for (auto player : rootItem->findChildren<QMediaPlayer*>()) {
|
||||||
return;
|
auto mediaState = player->state();
|
||||||
}
|
QMediaService *svc = player->service();
|
||||||
QAudioOutputSelectorControl *out = qobject_cast<QAudioOutputSelectorControl *>
|
if (nullptr == svc) {
|
||||||
(svc->requestControl(QAudioOutputSelectorControl_iid));
|
return;
|
||||||
if (nullptr == out) {
|
}
|
||||||
return;
|
QAudioOutputSelectorControl *out = qobject_cast<QAudioOutputSelectorControl *>
|
||||||
}
|
(svc->requestControl(QAudioOutputSelectorControl_iid));
|
||||||
QString deviceOuput;
|
if (nullptr == out) {
|
||||||
auto outputs = out->availableOutputs();
|
return;
|
||||||
for (int i = 0; i < outputs.size(); i++) {
|
}
|
||||||
QString output = outputs[i];
|
QString deviceOuput;
|
||||||
QString description = out->outputDescription(output);
|
auto outputs = out->availableOutputs();
|
||||||
if (description == _newTargetDevice) {
|
for (int i = 0; i < outputs.size(); i++) {
|
||||||
deviceOuput = output;
|
QString output = outputs[i];
|
||||||
break;
|
QString description = out->outputDescription(output);
|
||||||
|
if (description == _newTargetDevice) {
|
||||||
|
deviceOuput = output;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
out->setActiveOutput(deviceOuput);
|
||||||
|
svc->releaseControl(out);
|
||||||
|
// if multimedia was paused, it will start playing automatically after changing audio device
|
||||||
|
// this will reset it back to a paused state
|
||||||
|
if (mediaState == QMediaPlayer::State::PausedState) {
|
||||||
|
player->pause();
|
||||||
|
}
|
||||||
|
else if (mediaState == QMediaPlayer::State::StoppedState) {
|
||||||
|
player->stop();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
out->setActiveOutput(deviceOuput);
|
|
||||||
svc->releaseControl(out);
|
|
||||||
// if multimedia was paused, it will start playing automatically after changing audio device
|
|
||||||
// this will reset it back to a paused state
|
|
||||||
if (mediaState == QMediaPlayer::State::PausedState) {
|
|
||||||
player->pause();
|
|
||||||
} else if (mediaState == QMediaPlayer::State::StoppedState) {
|
|
||||||
player->stop();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
qDebug() << "QML Audio changed to " << _newTargetDevice;
|
qDebug() << "QML Audio changed to " << _newTargetDevice;
|
||||||
|
@ -175,7 +180,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString _newTargetDevice;
|
QString _newTargetDevice;
|
||||||
QObject* _container;
|
OffscreenQmlSurface* _surface;
|
||||||
int _runDelayMs;
|
int _runDelayMs;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -701,7 +706,7 @@ void OffscreenQmlSurface::forceQmlAudioOutputDeviceUpdate() {
|
||||||
QString deviceName = audioIO->getActiveAudioDevice(QAudio::AudioOutput).deviceName();
|
QString deviceName = audioIO->getActiveAudioDevice(QAudio::AudioOutput).deviceName();
|
||||||
int waitForAudioQmlMs = 200;
|
int waitForAudioQmlMs = 200;
|
||||||
// The audio device need to be change using oth
|
// 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