Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. QMediaPlayer “Failed to load media” on iOS
Qt 6.11 is out! See what's new in the release blog

QMediaPlayer “Failed to load media” on iOS

Scheduled Pinned Locked Moved Mobile and Embedded
19 Posts 4 Posters 5.9k Views 4 Watching
  • 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.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #6

    Try creating your URL with QUrl::fromLocalFile

    Interested in AI ? www.idiap.ch
    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

    1 Reply Last reply
    0
    • canellasC Offline
      canellasC Offline
      canellas
      wrote on last edited by canellas
      #7

      SGaist,

      I really appreciate your help. Thanks a lot!

      I wrote a slot for 'error' signal from QAudioRecorder, which is actually inherited from QMediaRecorder, and it revealed the 'QMediaRecorder::ResourceError'.

      That happens in the simulator as well as on the iPhone.

      I am searching the web, but no luck so far.

      Any ideas?

      Thanks!

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #8

        Did you change the QUrl creation part like suggested ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • canellasC Offline
          canellasC Offline
          canellas
          wrote on last edited by
          #9

          Sorry, I forgot to report that I've changed the QUrl construction, as you suggested, but with no different results

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #10

            Did you check that it's valid just in case ?

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • canellasC Offline
              canellasC Offline
              canellas
              wrote on last edited by
              #11

              Yes, it was a valid path.

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #12

                I meant: did you validate that with QUrl ? With isValid and isLocalFile ?

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                0
                • canellasC Offline
                  canellasC Offline
                  canellas
                  wrote on last edited by
                  #13

                  I believe it is.

                  The following code

                  void Gravar::h6() {
                  
                      qDebug() << "h6 >>>";
                  
                      try {
                          set_current(playing);
                  
                          qDebug() << "m_audio_recorder->outputLocation() = " << m_audio_recorder->outputLocation();
                  
                          QString _path = m_audio_recorder->outputLocation().path();
                          qDebug() << "_path = " << _path;
                  
                          QUrl _url (QUrl::fromLocalFile(_path));
                          qDebug() << "url = " << _url;
                  
                          if  (!_url.isValid()) {
                              qDebug() << "INVALID URL!";
                              return;
                          }
                  
                          qDebug() << "valid url";
                  
                          if (!_url.isLocalFile()) {
                              qDebug() << "NOT A LOCAL FILE!";
                              return;
                          }
                  
                          qDebug() << "local file";
                  
                          QMediaContent _content(_url);
                          qDebug() << "h6-content '" << _content.canonicalUrl() << "'\n";
                  
                          m_player->setMedia(_content);
                          m_player->setVolume(100);
                          m_player->play();
                      }
                      catch (std::exception & _ex) {
                          qDebug() << "FATAL: '" << _ex.what() << "'\n";
                          state_transition(reset);
                      }
                  
                      qDebug() << "h6 <<<";
                  }
                  

                  prints this output:

                  h6 >>>
                  m_audio_recorder->outputLocation() =  QUrl("file:///var/mobile/Containers/Data/Application/CBAAF069-4B9B-4521-9BB2-0754DBA3E24F/Documents/Music/28_94_1.wav")
                  _path =  "/var/mobile/Containers/Data/Application/CBAAF069-4B9B-4521-9BB2-0754DBA3E24F/Documents/Music/28_94_1.wav"
                  url =  QUrl("file:///var/mobile/Containers/Data/Application/CBAAF069-4B9B-4521-9BB2-0754DBA3E24F/Documents/Music/28_94_1.wav")
                  valid url
                  local file
                  h6-content ' QUrl("file:///var/mobile/Containers/Data/Application/CBAAF069-4B9B-4521-9BB2-0754DBA3E24F/Documents/Music/28_94_1.wav") '
                  
                  h6 <<<
                  

                  I think it is very important to notice that when I call 'm_audio_recorder->record()', a slot I wrote for 'error' signal from QAudioRecorder prints 'Recording error: QMediaRecorder::ResourceError', and from there on, no signal is emitted anymore.

                  Again, thanks a lot for your help.

                  1 Reply Last reply
                  0
                  • NickVN Offline
                    NickVN Offline
                    NickV
                    wrote on last edited by
                    #14

                    You can try this in the .pro file:

                    QTPLUGIN += qtaudio_coreaudio

                    1 Reply Last reply
                    0
                    • canellasC Offline
                      canellasC Offline
                      canellas
                      wrote on last edited by
                      #15

                      I've already tried that, and I can do it again, but only tomorrow, because today I am trying to solve the problem of pausing the voice recording in Android.

                      I'll let you know the results.

                      Thanks!

                      1 Reply Last reply
                      0
                      • canellasC Offline
                        canellasC Offline
                        canellas
                        wrote on last edited by
                        #16

                        I found what is causing the error!

                        Running the app on a iPhone 5 real device, when I print the standard paths, I get:

                        DesktopLocation = "/var/mobile/Containers/Data/Application/D424B7BE-6230-4868-8B85-09324C845738/Documents/Desktop"
                        DocumentsLocation = "/var/mobile/Containers/Data/Application/D424B7BE-6230-4868-8B85-09324C845738/Documents"
                        ApplicationsLocation = ""
                        MusicLocation = "/var/mobile/Containers/Data/Application/D424B7BE-6230-4868-8B85-09324C845738/Documents/Music"
                        MoviesLocation = "/var/mobile/Containers/Data/Application/D424B7BE-6230-4868-8B85-09324C845738/Documents/Movies"
                        PicturesLocation = "/var/mobile/Containers/Data/Application/D424B7BE-6230-4868-8B85-09324C845738/Documents/Pictures"
                        TempLocation = "/private/var/mobile/Containers/Data/Application/D424B7BE-6230-4868-8B85-09324C845738/tmp"
                        HomeLocation = "/private/var/mobile/Containers/Data/Application/D424B7BE-6230-4868-8B85-09324C845738"
                        DataLocation = "/var/mobile/Containers/Data/Application/D424B7BE-6230-4868-8B85-09324C845738/Library/Application Support/perinatal__app__app_mae"
                        CacheLocation = "/var/mobile/Containers/Data/Application/D424B7BE-6230-4868-8B85-09324C845738/Library/Caches/perinatal__app__app_mae"
                        GenericDataLocation = "/var/mobile/Containers/Data/Application/D424B7BE-6230-4868-8B85-09324C845738/Library/Application Support"
                        RuntimeLocation = "/var/mobile/Containers/Data/Application/D424B7BE-6230-4868-8B85-09324C845738/Library/Application Support"
                        ConfigLocation = "/var/mobile/Containers/Data/Application/D424B7BE-6230-4868-8B85-09324C845738/Library/Preferences"
                        GenericConfigLocation = "/var/mobile/Containers/Data/Application/D424B7BE-6230-4868-8B85-09324C845738/Library/Preferences"
                        DownloadLocation = "/var/mobile/Containers/Data/Application/D424B7BE-6230-4868-8B85-09324C845738/Documents/Downloads"
                        GenericCacheLocation = "/var/mobile/Containers/Data/Application/D424B7BE-6230-4868-8B85-09324C845738/Library/Caches"
                        AppDataLocation = "/var/mobile/Containers/Data/Application/D424B7BE-6230-4868-8B85-09324C845738/Library/Application Support/perinatal__app__app_mae"
                        AppLocalDataLocation = "/var/mobile/Containers/Data/Application/D424B7BE-6230-4868-8B85-09324C845738/Library/Application Support/perinatal__app__app_mae"
                        AppConfigLocation = "/var/mobile/Containers/Data/Application/D424B7BE-6230-4868-8B85-09324C845738/Library/Preferences/perinatal__app__app_mae"

                        The first problem is that the all the paths starting with '/var/' are wrong, the actual path is '/private/var'. So, when I try to use 'MusicLocation', in the slot for the 'error' signal, 'QAudioRecorder::errorString' prints "Can't open output location". I can not prefix 'MusicLocation' with '/private' because this location changes between versions of iPhone.

                        Running the 'Examples/multimedia/audiorecorder' example, it is possible to navigate in the file system of the iPhone 5, and one can see that the '/var' directory is actually a link, but when you enter the directory, although one could expect to see the 'mobile' sub directory, there is nothing there.

                        The documentation for 'QStandardPaths::writableLocation(StandardLocation type)' says "Note: The storage location returned can be a directory that does not exist; i.e., it may need to be created by the system or the user.", but I can not create any directory below '/var', where ever it really is.

                        In the iPhone 6 simulator, the 'MusicLocation' is "/Users/canellas/Library/Application Support/iPhone Simulator/2.2/Documents/Music", wich does not exist, but I could create it. I do not know if I would be able to create it, if it was a real iPhone device.

                        I could not create the audio file at 'HomeLocation'. The only path that worked was 'TempLocation', on the iPhone 5 cell, and on the iPhone 6 simulator.

                        Does anyone know how correctly use 'QStandardPaths'? Or am I using it right, and there is a bug there?

                        Thanks a lot for reading all this! 8)

                        1 Reply Last reply
                        0
                        • SGaistS Offline
                          SGaistS Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on last edited by
                          #17

                          Which version of iOS are you running ?

                          Interested in AI ? www.idiap.ch
                          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                          1 Reply Last reply
                          0
                          • canellasC Offline
                            canellasC Offline
                            canellas
                            wrote on last edited by
                            #18

                            On the iPhone 5 it is 9.3.3 (13G34). On the iPhone 6s simulator it is 9.3 (13E30).

                            Thanks!

                            1 Reply Last reply
                            0
                            • G Offline
                              G Offline
                              GBergamo
                              wrote on last edited by
                              #19

                              Any update on this?

                              1 Reply Last reply
                              0

                              • Login

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