Referencing to a qrc file via QUrl for QAudioDecoder
-
Hi,
i have to decode a wave file. As long as I reference to it directly, it works: no error message and I can decode the file.
Referencing from qrc I do not find the correct way.With qrc I either get
Could not open media. FFmpeg error description: No such file or directoryor
Could not open media. FFmpeg error description: Protocol not foundand the QAudiodecoder has always the errorStr():
Could not open fileBut it works with a URL from a local file:
C:/Users/SeDi/cpp/BrassTutor/percussion/hihat.wavI've tried it in a lot of ways. Here's my testing code, m_audioDecoder is a QAudioDecoder:
QStringList urlList; urlList << "C:/Users/SeDi/cpp/BrassTutor/percussion/hihat.wav"; //this works! // urlList << ":/percussion/hihat.wav"; //error messages regarding preceding ":" // urlList << ":/percussion/percussion/hihat.wav"; // urlList << ":/sounds/percussion/hihat.wav"; // urlList << ":/sounds/percussion/percussion/hihat.wav"; urlList << "/percussion/hihat.wav"; urlList << "/percussion/percussion/hihat.wav"; urlList << "/sounds/percussion/hihat.wav"; urlList << "/sounds/percussion/percussion/hihat.wav"; urlList << "percussion/hihat.wav"; urlList << "percussion/percussion/hihat.wav"; urlList << "sounds/percussion/hihat.wav"; urlList << "sounds/percussion/percussion/hihat.wav"; urlList << "qrc:///percussion/hihat.wav"; //tried with single slash as well urlList << "qrc:///percussion/percussion/hihat.wav"; urlList << "qrc:///sounds/percussion/hihat.wav"; urlList << "qrc:///sounds/percussion/percussion/hihat.wav"; for (auto &u: std::as_const(urlList)) { url = QUrl(u); qDebug()<< "--- " << u << ": "<< (url.isValid() ? "valid" : "invalid!!") << url.errorString() << " ------------------------"; m_audioDecoder.setSource(url); m_audioDecoder.start(); if (m_audioDecoder.errorString().isEmpty()) { qDebug()<<"^^^^^^^^^^^^^^NO ERROR^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"; } else { qDebug()<<"Error: "<<m_audioDecoder.errorString(); } qDebug()<<""; } // and the same code again with url = QUrl::fromLocalFile(u);The result, in detail:
qt.multimedia.ffmpeg: Using Qt multimedia with FFmpeg version 7.1.1 LGPL version 2.1 or later --- "C:/Users/SeDi/cpp/BrassTutor/percussion/hihat.wav" : valid "" ------------------------ ^^^^^^^^^^^^^^NO ERROR^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ --- "/percussion/hihat.wav" : valid "" ------------------------ qt.multimedia.ffmpeg.mediadataholder: Could not open media. FFmpeg error description: No such file or directory Error: "Could not open file" --- "/percussion/percussion/hihat.wav" : valid "" ------------------------ qt.multimedia.ffmpeg.mediadataholder: Could not open media. FFmpeg error description: No such file or directory Error: "Could not open file" --- "/sounds/percussion/hihat.wav" : valid "" ------------------------ qt.multimedia.ffmpeg.mediadataholder: Could not open media. FFmpeg error description: No such file or directory Error: "Could not open file" --- "/sounds/percussion/percussion/hihat.wav" : valid "" ------------------------ qt.multimedia.ffmpeg.mediadataholder: Could not open media. FFmpeg error description: No such file or directory Error: "Could not open file" --- "percussion/hihat.wav" : valid "" ------------------------ qt.multimedia.ffmpeg.mediadataholder: Could not open media. FFmpeg error description: No such file or directory Error: "Could not open file" --- "percussion/percussion/hihat.wav" : valid "" ------------------------ qt.multimedia.ffmpeg.mediadataholder: Could not open media. FFmpeg error description: No such file or directory Error: "Could not open file" --- "sounds/percussion/hihat.wav" : valid "" ------------------------ qt.multimedia.ffmpeg.mediadataholder: Could not open media. FFmpeg error description: No such file or directory Error: "Could not open file" --- "sounds/percussion/percussion/hihat.wav" : valid "" ------------------------ qt.multimedia.ffmpeg.mediadataholder: Could not open media. FFmpeg error description: No such file or directory Error: "Could not open file" --- "qrc:///percussion/hihat.wav" : valid "" ------------------------ qt.multimedia.ffmpeg.mediadataholder: Could not open media. FFmpeg error description: Protocol not found Error: "Could not open file" --- "qrc:///percussion/percussion/hihat.wav" : valid "" ------------------------ qt.multimedia.ffmpeg.mediadataholder: Could not open media. FFmpeg error description: Protocol not found Error: "Could not open file" --- "qrc:///sounds/percussion/hihat.wav" : valid "" ------------------------ qt.multimedia.ffmpeg.mediadataholder: Could not open media. FFmpeg error description: Protocol not found Error: "Could not open file" --- "qrc:///sounds/percussion/percussion/hihat.wav" : valid "" ------------------------ qt.multimedia.ffmpeg.mediadataholder: Could not open media. FFmpeg error description: Protocol not found Error: "Could not open file" fromLocalFile: --- "C:/Users/SeDi/cpp/BrassTutor/percussion/hihat.wav" : valid "" ------------------------ ^^^^^^^^^^^^^^NO ERROR^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ --- "/percussion/hihat.wav" : valid "" ------------------------ qt.multimedia.ffmpeg.mediadataholder: Could not open media. FFmpeg error description: No such file or directory Error: "Could not open file" --- "/percussion/percussion/hihat.wav" : valid "" ------------------------ qt.multimedia.ffmpeg.mediadataholder: Could not open media. FFmpeg error description: No such file or directory Error: "Could not open file" --- "/sounds/percussion/hihat.wav" : valid "" ------------------------ qt.multimedia.ffmpeg.mediadataholder: Could not open media. FFmpeg error description: No such file or directory Error: "Could not open file" --- "/sounds/percussion/percussion/hihat.wav" : valid "" ------------------------ qt.multimedia.ffmpeg.mediadataholder: Could not open media. FFmpeg error description: No such file or directory Error: "Could not open file" --- "percussion/hihat.wav" : valid "" ------------------------ qt.multimedia.ffmpeg.mediadataholder: Could not open media. FFmpeg error description: No such file or directory Error: "Could not open file" --- "percussion/percussion/hihat.wav" : valid "" ------------------------ qt.multimedia.ffmpeg.mediadataholder: Could not open media. FFmpeg error description: No such file or directory Error: "Could not open file" --- "sounds/percussion/hihat.wav" : valid "" ------------------------ qt.multimedia.ffmpeg.mediadataholder: Could not open media. FFmpeg error description: No such file or directory Error: "Could not open file" --- "sounds/percussion/percussion/hihat.wav" : valid "" ------------------------ qt.multimedia.ffmpeg.mediadataholder: Could not open media. FFmpeg error description: No such file or directory Error: "Could not open file" --- "qrc:///percussion/hihat.wav" : valid "" ------------------------ qt.multimedia.ffmpeg.mediadataholder: Could not open media. FFmpeg error description: Protocol not found Error: "Could not open file" --- "qrc:///percussion/percussion/hihat.wav" : valid "" ------------------------ qt.multimedia.ffmpeg.mediadataholder: Could not open media. FFmpeg error description: Protocol not found Error: "Could not open file" --- "qrc:///sounds/percussion/hihat.wav" : valid "" ------------------------ qt.multimedia.ffmpeg.mediadataholder: Could not open media. FFmpeg error description: Protocol not found Error: "Could not open file" --- "qrc:///sounds/percussion/percussion/hihat.wav" : valid "" ------------------------ qt.multimedia.ffmpeg.mediadataholder: Could not open media. FFmpeg error description: Protocol not found Error: "Could not open file"I have tried to find information and tried the triple slash version as well as proposed here, but to no avail.
Where's my mistake? Any ideas how to fix this?
-
Please show your qrc file and CMakeLists.txt
-
Please show your qrc file and CMakeLists.txt
@Christian-Ehrlicher
Thank you for reacting!My "sounds.qrc" is this:
<RCC> <qresource prefix="/percussion"> <file>percussion/hihat.wav</file> <file>percussion/kick2.wav</file> <file>percussion/snare.wav</file> <file>percussion/woodblock1.wav</file> <file>percussion/woodblock2.wav</file> <file>percussion/cowbell.wav</file> <file>percussion/hihat.mp3</file> </qresource> <qresource prefix="/trumpet"> <file>trumpet/53.wav</file> <file>trumpet/54.wav</file> <file>trumpet/55.wav</file> <file>trumpet/56.wav</file> <file>trumpet/57.wav</file> <file>trumpet/58.wav</file> <file>trumpet/59.wav</file> <file>trumpet/60.wav</file> <file>trumpet/61.wav</file> <file>trumpet/62.wav</file> <file>trumpet/63.wav</file> <file>trumpet/64.wav</file> <file>trumpet/65.wav</file> <file>trumpet/66.wav</file> <file>trumpet/67.wav</file> <file>trumpet/68.wav</file> <file>trumpet/69.wav</file> <file>trumpet/70.wav</file> <file>trumpet/71.wav</file> <file>trumpet/72.wav</file> <file>trumpet/73.wav</file> <file>trumpet/74.wav</file> <file>trumpet/75.wav</file> <file>trumpet/76.wav</file> <file>trumpet/77.wav</file> <file>trumpet/78.wav</file> <file>trumpet/79.wav</file> <file>trumpet/80.wav</file> <file>trumpet/81.wav</file> <file>trumpet/82.wav</file> <file>trumpet/52.wav</file> </qresource> </RCC>As it is a project that I had started long ago, that I am pickung up again just now, it is still qmake based. However, my .pro file is here:
QT += quick multimedia CONFIG += c++17 # The following define makes your compiler emit warnings if you use # any Qt feature that has been marked deprecated (the exact warnings # depend on your compiler). Refer to the documentation for the # deprecated API to know how to port your code away from it. DEFINES += QT_DEPRECATED_WARNINGS # You can also make your code fail to compile if it uses deprecated APIs. # In order to do so, uncomment the following line. # You can also select to disable deprecated APIs only up to a certain version of Qt. DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 SOURCES += \ audiosinkplayer.cpp \ controller.cpp \ instrument.cpp \ main.cpp \ note.cpp \ percussionworker.cpp \ task.cpp \ waveformgenerator.cpp RESOURCES += qml.qrc \ images.qrc \ sounds.qrc TRANSLATIONS += \ BrassTutor_de_DE.ts # Additional import path used to resolve QML modules in Qt Creator's code model QML_IMPORT_PATH = # Additional import path used to resolve QML modules just for Qt Quick Designer QML_DESIGNER_IMPORT_PATH = # Default rules for deployment. qnx: target.path = /tmp/$${TARGET}/bin else: unix:!android: target.path = /opt/$${TARGET}/bin !isEmpty(target.path): INSTALLS += target HEADERS += \ audiosinkplayer.h \ controller.h \ instrument.h \ note.h \ percussionworker.h \ task.h \ waveformgenerator.h -
Your CMakeLists.txt is not complete so I can only guess. The path for the way file must be qrc://percussion/percusiion/hihat.wav if you did not do anything else in the CMakeLists.txt as you can see here:
<qresource prefix="/percussion"> <file>percussion/hihat.wav</file>You can check it with QFile::exists().
-
I have no CMakeLists.txt because I don't use cmake. Is there an alternative place in qmake based project where I could have messed something up? On the other hand, the file does exist:
QString name = ":/percussion/percussion/hihat.wav"; qDebug()<<"QFile::exists(name): "<<QFile::exists(name); url = QUrl("qrc"+name); qDebug()<< "QUrl is: " << (url.isValid() ? "valid" : "invalid!!"); m_audioDecoder.setSource(url); m_audioDecoder.start(); qDebug()<< "m_audioDecoder.errorString(): "<<m_audioDecoder.errorString();gives this application output
qt.multimedia.ffmpeg: Using Qt multimedia with FFmpeg version 7.1.1 LGPL version 2.1 or later QFile::exists(name): true QUrl is: valid qt.multimedia.ffmpeg.mediadataholder: Could not open media. FFmpeg error description: Protocol not found m_audioDecoder.errorString(): "Could not open file"I've also tried it with two slashes, same result:
QString name = "percussion/percussion/hihat.wav"; qDebug()<<"QFile::exists(':/'+name): "<<QFile::exists(":/"+name); // url = QUrl("qrc://percussion/percussion/hihat.wav"); url = QUrl("qrc://"+name); -
I have no CMakeLists.txt because I don't use cmake. Is there an alternative place in qmake based project where I could have messed something up? On the other hand, the file does exist:
QString name = ":/percussion/percussion/hihat.wav"; qDebug()<<"QFile::exists(name): "<<QFile::exists(name); url = QUrl("qrc"+name); qDebug()<< "QUrl is: " << (url.isValid() ? "valid" : "invalid!!"); m_audioDecoder.setSource(url); m_audioDecoder.start(); qDebug()<< "m_audioDecoder.errorString(): "<<m_audioDecoder.errorString();gives this application output
qt.multimedia.ffmpeg: Using Qt multimedia with FFmpeg version 7.1.1 LGPL version 2.1 or later QFile::exists(name): true QUrl is: valid qt.multimedia.ffmpeg.mediadataholder: Could not open media. FFmpeg error description: Protocol not found m_audioDecoder.errorString(): "Could not open file"I've also tried it with two slashes, same result:
QString name = "percussion/percussion/hihat.wav"; qDebug()<<"QFile::exists(':/'+name): "<<QFile::exists(":/"+name); // url = QUrl("qrc://percussion/percussion/hihat.wav"); url = QUrl("qrc://"+name);@SeDi said in Referencing to a qrc file via QUrl for QAudioDecoder:
I have no CMakeLists.txt because I don't use cmake.
sorry, I did not see that this is a pro file.
It looks like QAudioDecoder does not (yet) support streaming from resources for ffmpeg backend. You might open a bug report for this
-
@SeDi said in Referencing to a qrc file via QUrl for QAudioDecoder:
I have no CMakeLists.txt because I don't use cmake.
sorry, I did not see that this is a pro file.
It looks like QAudioDecoder does not (yet) support streaming from resources for ffmpeg backend. You might open a bug report for this
@Christian-Ehrlicher
Thank you for your patience!
Oh my. That would be a show stopper for any android based app that needs to decode a wav file, wouldn't it?
Do you have any idea for a workaround?
Could it be a good idea I bring this up on the [interest] list? -
@Christian-Ehrlicher
Thank you for your patience!
Oh my. That would be a show stopper for any android based app that needs to decode a wav file, wouldn't it?
Do you have any idea for a workaround?
Could it be a good idea I bring this up on the [interest] list?@SeDi said in Referencing to a qrc file via QUrl for QAudioDecoder:
Do you have any idea for a workaround?
Yes, save it to a local file before using
Could it be a good idea I bring this up on the [interest] list?
Why? Create a bug report.
-
@Christian-Ehrlicher
Thank you for your patience!
Oh my. That would be a show stopper for any android based app that needs to decode a wav file, wouldn't it?
Do you have any idea for a workaround?
Could it be a good idea I bring this up on the [interest] list?@SeDi said in Referencing to a qrc file via QUrl for QAudioDecoder:
Do you have any idea for a workaround?
I haven't tried this but maybe using
QFileinQAudioDecoder::setSourceDevice?
This would be my first thought for anything that doesn't support qrc file name but has support forQIODevice. -
@SeDi said in Referencing to a qrc file via QUrl for QAudioDecoder:
Do you have any idea for a workaround?
Yes, save it to a local file before using
Could it be a good idea I bring this up on the [interest] list?
Why? Create a bug report.
@Christian-Ehrlicher I'll try to open a bug report, though I am still struggling on making a minimal example from a console application. The workaround with copying to a local file works perfectly!
Thank you very much for your time and effort!
-
@SeDi said in Referencing to a qrc file via QUrl for QAudioDecoder:
Do you have any idea for a workaround?
I haven't tried this but maybe using
QFileinQAudioDecoder::setSourceDevice?
This would be my first thought for anything that doesn't support qrc file name but has support forQIODevice. -
S SeDi has marked this topic as solved