Fixes on web and QML audio sync

This commit is contained in:
luiscuenca 2017-11-29 18:16:21 -07:00
parent 8eb8cb0994
commit b817143e2e
2 changed files with 14 additions and 10 deletions

View file

@ -65,21 +65,26 @@ var EventBridge;
// we need to listen to events that might precede the addition of this elements. // we need to listen to events that might precede the addition of this elements.
// A more robust hack will be to add a setInterval that look for DOM changes every 100-300 ms (low performance?) // A more robust hack will be to add a setInterval that look for DOM changes every 100-300 ms (low performance?)
window.onload = function(){ window.addEventListener("load",function(event) {
setTimeout(function() { setTimeout(function() {
EventBridge.forceHtmlAudioOutputDeviceUpdate(); EventBridge.forceHtmlAudioOutputDeviceUpdate();
console.log(":: Window Loaded");
}, 1200); }, 1200);
}; }, false);
document.onclick = function(){
document.addEventListener("click",function(){
setTimeout(function() { setTimeout(function() {
EventBridge.forceHtmlAudioOutputDeviceUpdate(); EventBridge.forceHtmlAudioOutputDeviceUpdate();
console.log(":: Window Clicked");
}, 1200); }, 1200);
}; }, false);
document.onchange = function(){
document.addEventListener("change",function(){
setTimeout(function() { setTimeout(function() {
EventBridge.forceHtmlAudioOutputDeviceUpdate(); EventBridge.forceHtmlAudioOutputDeviceUpdate();
console.log(":: Window Changes");
}, 1200); }, 1200);
}; }, false);
tempEventBridge._callbacks.forEach(function (callback) { tempEventBridge._callbacks.forEach(function (callback) {
EventBridge.scriptEventReceived.connect(callback); EventBridge.scriptEventReceived.connect(callback);

View file

@ -139,7 +139,6 @@ public:
QThread::msleep(_runDelayMs); QThread::msleep(_runDelayMs);
} }
auto audioIO = DependencyManager::get<AudioClient>(); auto audioIO = DependencyManager::get<AudioClient>();
QString deviceName = audioIO->getActiveAudioDevice(QAudio::AudioOutput).deviceName();
for (auto player : _container->findChildren<QMediaPlayer*>()) { for (auto player : _container->findChildren<QMediaPlayer*>()) {
auto mediaState = player->state(); auto mediaState = player->state();
QMediaService *svc = player->service(); QMediaService *svc = player->service();
@ -156,7 +155,7 @@ public:
for (int i = 0; i < outputs.size(); i++) { for (int i = 0; i < outputs.size(); i++) {
QString output = outputs[i]; QString output = outputs[i];
QString description = out->outputDescription(output); QString description = out->outputDescription(output);
if (description == deviceName) { if (description == _newTargetDevice) {
deviceOuput = output; deviceOuput = output;
break; break;
} }
@ -171,7 +170,7 @@ public:
player->stop(); player->stop();
} }
} }
qDebug() << "QML Audio changed to " << deviceName; qDebug() << "QML Audio changed to " << _newTargetDevice;
} }
private: private:
@ -700,7 +699,7 @@ void OffscreenQmlSurface::forceQmlAudioOutputDeviceUpdate() {
} else { } else {
auto audioIO = DependencyManager::get<AudioClient>(); auto audioIO = DependencyManager::get<AudioClient>();
QString deviceName = audioIO->getActiveAudioDevice(QAudio::AudioOutput).deviceName(); QString deviceName = audioIO->getActiveAudioDevice(QAudio::AudioOutput).deviceName();
int waitForAudioQmlMs = 500; 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(_rootItem, deviceName, waitForAudioQmlMs);
} }