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
4444 return _player->length();
4545 }
4646
47−void RecordingScriptingInterface::loadRecording(const QString& url) {
47+bool RecordingScriptingInterface::loadRecording(const QString& url) {
4848 using namespace recording;
4949
50− if (QThread::currentThread() != thread()) {
51− QMetaObject::invokeMethod(this, "loadRecording", Qt::BlockingQueuedConnection,
52− Q_ARG(QString, url));
53− return;
50+ auto loader = ClipCache::instance().getClipLoader(url);
51+ QEventLoop loop;
52+ QObject::connect(loader.data(), &Resource::loaded, &loop, &QEventLoop::quit);
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;
5459 }
5560
56− // FIXME make blocking and force off main thread?
57− _player->queueClip(ClipCache::instance().getClipLoader(url)->getClip());
61+ _player->queueClip(loader->getClip());
62+ return true;
5863 }
5964
65+
6066 void RecordingScriptingInterface::startPlaying() {
6167 if (QThread::currentThread() != thread()) {
6268 QMetaObject::invokeMethod(this, "startPlaying", Qt::BlockingQueuedConnection);