QMediaPlayer “Failed to load media” on iOS



  • Hi!

    My application is written using QWidget, no QtQuick, and on iOS 'QMediaPlayer::supportedAudioCodecs()' returns '("audio/pcm")' and 'QMediaPlayer::supportedContainers()' returns ' ("audio/x-wav", "audio/x-raw")'.

    An audio file was recorded at 'QUrl("file:///Users/canellas/Library/Application Support/iPhone Simulator/2.2/Documents/Desktop/28_94_1.wav")', but when I try to play it, QMediaPlayer signals 'error', and the slot I wrote prints the error parameter as 'QMediaPlayer::FormatError', and 'QMediaPlayer::errorString()' prints "Failed to load media".

    The same code works fine on Android and OSX.

    Could the space in 'Application Support' or in 'iPhone Simulator' cause this error? I wonder because the path on OSX or on Android has no spaces. I tried to create a QUrl object using HTML codes for spaces, but, AKAIK, QUrl does not allow it.

    Thanks!


  • Lifetime Qt Champion

    Hi,

    Might be more related to the fact that you are using a simulator. Can you check that again on a real device ?



  • @SGaist

    Unfortunately, not right now... only next Monday... I'll try again, and let you know.

    Thanks!



  • Well, I tried again using a real iPhone, but it did not work.

    I would appreciate very much any other idea...

    Thanks!



  • More and more it seems to have something to do with the path. Running on the iOS simulator, I was able to change the path to "file:///Users/canellas/", and the audio file was recorded and played back normally.

    I'll try to change the path in the iPhone, and compare the results.


  • Lifetime Qt Champion

    Try creating your URL with QUrl::fromLocalFile



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


  • Lifetime Qt Champion

    Did you change the QUrl creation part like suggested ?



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


  • Lifetime Qt Champion

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



  • Yes, it was a valid path.


  • Lifetime Qt Champion

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



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



  • You can try this in the .pro file:

    QTPLUGIN += qtaudio_coreaudio



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



  • 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)


  • Lifetime Qt Champion

    Which version of iOS are you running ?



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

    Thanks!



  • Any update on this?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.