History

Force synchronous loading of clips in JS

Brad Davis committed 10 years ago

Commit cc2a7cb1 parent 00c8ccb2 files · +14 −8Browse files

Showing the changes to libraries/script-engine/src/RecordingScriptingInterface.cpp (1 of 2 files). Show all

Unified · Split

libraries/script-engine/src/RecordingScriptingInterface.cpp+13−7
@@ -44,19 +44,25 @@ float RecordingScriptingInterface::playerLength() const { · 43 unmodified lines
44 return _player->length();44 return _player->length();
45}45}
46 46
47void RecordingScriptingInterface::loadRecording(const QString& url) {47bool RecordingScriptingInterface::loadRecording(const QString& url) {
48 using namespace recording;48 using namespace recording;
49 49
50 if (QThread::currentThread() != thread()) {50 auto loader = ClipCache::instance().getClipLoader(url);
51 QMetaObject::invokeMethod(this, "loadRecording", Qt::BlockingQueuedConnection,51 QEventLoop loop;
52 Q_ARG(QString, url));52 QObject::connect(loader.data(), &Resource::loaded, &loop, &QEventLoop::quit);
53 return;53 QObject::connect(loader.data(), &Resource::failed, &loop, &QEventLoop::quit);
54 loop.exec();
55
56 if (!loader->isLoaded()) {
57 qWarning() << "Clip failed to load from " << url;
58 return false;
54 }59 }
55 60
56 // FIXME make blocking and force off main thread?61 _player->queueClip(loader->getClip());
57 _player->queueClip(ClipCache::instance().getClipLoader(url)->getClip());62 return true;
58}63}
59 64
65
60void RecordingScriptingInterface::startPlaying() {66void RecordingScriptingInterface::startPlaying() {
61 if (QThread::currentThread() != thread()) {67 if (QThread::currentThread() != thread()) {
62 QMetaObject::invokeMethod(this, "startPlaying", Qt::BlockingQueuedConnection);68 QMetaObject::invokeMethod(this, "startPlaying", Qt::BlockingQueuedConnection);