Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Referencing to a qrc file via QUrl for QAudioDecoder
Forum Updated to NodeBB v4.3 + New Features

Referencing to a qrc file via QUrl for QAudioDecoder

Scheduled Pinned Locked Moved Solved General and Desktop
11 Posts 3 Posters 636 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • SeDiS Offline
    SeDiS Offline
    SeDi
    wrote last edited by SeDi
    #1

    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 directory
    

    or

    Could not open media. FFmpeg error description: Protocol not found
    

    and the QAudiodecoder has always the errorStr():

    Could not open file
    

    But it works with a URL from a local file:

    C:/Users/SeDi/cpp/BrassTutor/percussion/hihat.wav
    

    I'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?

    1 Reply Last reply
    0
    • Christian EhrlicherC Online
      Christian EhrlicherC Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote last edited by
      #2

      Please show your qrc file and CMakeLists.txt

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      SeDiS 1 Reply Last reply
      1
      • Christian EhrlicherC Christian Ehrlicher

        Please show your qrc file and CMakeLists.txt

        SeDiS Offline
        SeDiS Offline
        SeDi
        wrote last edited by
        #3

        @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
        
        
        
        1 Reply Last reply
        0
        • Christian EhrlicherC Online
          Christian EhrlicherC Online
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote last edited by
          #4

          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().

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          1 Reply Last reply
          1
          • SeDiS Offline
            SeDiS Offline
            SeDi
            wrote last edited by SeDi
            #5

            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);
            
            Christian EhrlicherC 1 Reply Last reply
            0
            • SeDiS SeDi

              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);
              
              Christian EhrlicherC Online
              Christian EhrlicherC Online
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote last edited by
              #6

              @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

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              SeDiS 1 Reply Last reply
              1
              • Christian EhrlicherC Christian Ehrlicher

                @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

                SeDiS Offline
                SeDiS Offline
                SeDi
                wrote last edited by
                #7

                @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 EhrlicherC B 2 Replies Last reply
                0
                • SeDiS SeDi

                  @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 EhrlicherC Online
                  Christian EhrlicherC Online
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote last edited by
                  #8

                  @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.

                  Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                  Visit the Qt Academy at https://academy.qt.io/catalog

                  SeDiS 1 Reply Last reply
                  1
                  • SeDiS SeDi

                    @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?

                    B Offline
                    B Offline
                    Bonnie
                    wrote last edited by Bonnie
                    #9

                    @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 QFile in QAudioDecoder::setSourceDevice?
                    This would be my first thought for anything that doesn't support qrc file name but has support for QIODevice.

                    SeDiS 1 Reply Last reply
                    3
                    • Christian EhrlicherC Christian Ehrlicher

                      @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.

                      SeDiS Offline
                      SeDiS Offline
                      SeDi
                      wrote last edited by
                      #10

                      @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!

                      1 Reply Last reply
                      0
                      • B Bonnie

                        @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 QFile in QAudioDecoder::setSourceDevice?
                        This would be my first thought for anything that doesn't support qrc file name but has support for QIODevice.

                        SeDiS Offline
                        SeDiS Offline
                        SeDi
                        wrote last edited by
                        #11

                        @Bonnie This! Yes, this is the easiest drop-in workaround. Just works. Cool, thank you for the idea!

                        1 Reply Last reply
                        0
                        • SeDiS SeDi has marked this topic as solved

                        • Login

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Groups
                        • Search
                        • Get Qt Extensions
                        • Unsolved