Search code examples
iosqtipadmobileqt6

How to store the url to a sound file in ios


I use Qt to develop an IOS application. I can open a sound file using the Qt file picker dialog and then I get the url to that sound file. For example, I get file:///private/var/mobile/Containers/Data/Application/4557D5E4-68BA-4341-9F4F-2A07D5E87B4D/tmp/runsomething.App-Inbox/myaudiofile.wav

So I can at that moment load the audio file into the QAudioPlayer and it works and plays.

I then store this URL in a json file to later retrieve it. And the problem is that this seems to be a sort of temporary file url, because upon restart of my application, that URL does not work anymore.

So, my question is how to handle this? Do I need to copy it myself to my own dir that I can create for example under the "Library/Application Support" path: /var /mobile/Containers/Data/Application/4557D5E4-68BA-4341-9F4F-2A07D5E87B4D/Library/Application Support/App?

Or is there some other way? I saw this post which allows a user to share a file with your application and seems to copy it inside your apps' storage. Then probably it will not be a "tmp" file anymore and the link to that file will work even after application restarts. Is that how you should do it? I don't really like that approach and would like to avoid it if possible.

Thanks for any pointers or help! Best regards


Solution

  • It seems copying the inbox file to a file under the "Library/Application Support" path is indeed needed. However, my error was that I stored the sandbox path, so the full path in my settings file. For example I stored this url:

    file:///var/mobile/Containers/Data/Application/4557D5E4-68BA-4341-9F4F-2A07D5E87B4D/Library/Application Support/App/myaudiofile.wav
    

    But each time the application starts, the absolute path to the sandbox changes, so this part is variable:

    /var/mobile/Containers/Data/Application/4557D5E4-68BA-4341-9F4F-2A07D5E87B4D
    

    So now I store only a relative path, and to load it, I just prepend the "current" sandbox path to the path to get the correct absolute file path.

    And then it all works as expected.