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. How to reference bundled files on ios?
Forum Update on Monday, May 27th 2025

How to reference bundled files on ios?

Scheduled Pinned Locked Moved Solved Mobile and Embedded
iosbundlemobileaudioqml
10 Posts 2 Posters 2.0k 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.
  • H Offline
    H Offline
    Hitokage
    wrote on 3 Jun 2020, 10:27 last edited by Hitokage 6 Mar 2020, 13:42
    #1

    Hey, from here and hereI got the way to make the files bundled in the project so I can see them in "Bundle data" folder (without the audio folder) in Xcode environment. How do I correctly reference them in qml?

    In my pro file I have this:

    ios: {
        BUNDLE_DATA.files = $$files($$PWD/audio/*.mp3)
        QMAKE_BUNDLE_DATA += BUNDLE_DATA
    }
    

    Seems to work...

    But in my qml I have tried all of these but none seems to be working:

    qrc:/audio/file.mp3  //this is the default one that works on other platforms without the need to bundle anything
    file:/audio/file.mp3
    audio/file.mp3
    file.mp3
    

    Thanks and have a great day!

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 3 Jun 2020, 18:59 last edited by
      #2

      Hi,

      Based on your first link, your forgot the

      BUNDLE_DATA.path = Documents
      

      line.

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

      H 1 Reply Last reply 5 Jun 2020, 07:27
      1
      • S SGaist
        3 Jun 2020, 18:59

        Hi,

        Based on your first link, your forgot the

        BUNDLE_DATA.path = Documents
        

        line.

        H Offline
        H Offline
        Hitokage
        wrote on 5 Jun 2020, 07:27 last edited by Hitokage 6 May 2020, 08:58
        #3

        @SGaist Thank you for your reply! I added the Documents path (also forgot to include the plugin so did that too) but now when leaving the url like

        qrc:/audio/file.mp3
        

        I am getting Failed to load media error

        I tried to change the url in the same way as in the first link to simply:

        file.mp3
        or
        qrc:/file.mp3
        

        and then I am getting Attempting to play invalid QT resource

        I believe that it simply cannot be found. In Xcode I see the file in Bundle data folder without the original audio subfolder. So how to tell qml that we are referring to that location? Maybe the first one actually finds the file but doesn't load it for some reason?

        EDIT: I also found possibly relevant answer here but I am not sure if the bundle data is behaving as normal qrc resource or not or how to locate it properly.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 5 Jun 2020, 19:57 last edited by
          #4

          qrc:// is for Qt's resource system which are built in your executable.

          Can you check the content of your app bundle ? It should give you an idea of where the file is located.

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

          H 1 Reply Last reply 6 Jun 2020, 08:00
          0
          • S SGaist
            5 Jun 2020, 19:57

            qrc:// is for Qt's resource system which are built in your executable.

            Can you check the content of your app bundle ? It should give you an idea of where the file is located.

            H Offline
            H Offline
            Hitokage
            wrote on 6 Jun 2020, 08:00 last edited by Hitokage 6 Jun 2020, 08:28
            #5

            @SGaist Thank you! I have inspected the package according to this. When I open the package I see the Documents folder (probably the one I defined in the path variable) where the mp3 file is (so package/Documents/file.mp3).
            So I have tried:

            file:/Documents/file.mp3 - Failed to load media (this message is shown even if I write bad path on purpose)
            Documents/file.mp3 - Attempting to play invalid QT resource
            

            This is really strange. The guy in the first link even omitted the "Documents". I have no idea how he made it work. The path should be relative to the root of the package right? One idea I got is, should I use C++ helper function to somehow get absolute path on the device? Not sure how would I reference the file in C++ either.

            1 Reply Last reply
            0
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 6 Jun 2020, 17:14 last edited by
              #6

              Can you show what the folder tree looks like exactly ?

              One thing you can try is to go from the exec folder and move up enough to accent Documents.

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

              H 1 Reply Last reply 6 Jun 2020, 19:08
              0
              • S SGaist
                6 Jun 2020, 17:14

                Can you show what the folder tree looks like exactly ?

                One thing you can try is to go from the exec folder and move up enough to accent Documents.

                H Offline
                H Offline
                Hitokage
                wrote on 6 Jun 2020, 19:08 last edited by
                #7

                @SGaist When I open the package file in the simulator folder I see this (you can see also how the mp3 file is present in Xcode).
                I got this idea to use my file picker that I have in the app using FolderListModel. I tried to set the start dir to "./" and I ended up in qrc:/ system seeing the qml modules. When I set it to "file:/./" I end up in some folder with Application, Library, System and Users subfolders. The conclusion is that whenever I use simply a path string in points to path relative to qrc cache.
                I got the idea to use StandardPaths.AppDataLocation and yea I can see the Documents folder there! So tried to use the same in the MediaPlayer:

                StandardPaths.locate(StandardPaths.AppDataLocation, "file.mp3", StandardPaths.LocateFile)
                

                And it actually finds the file! The only problem is that i had to remove the "path" variable from pro file since the locate function probably doesn't work recursively. Without the path the files are places in the root folder of the package. When I print the url I see an absolute path leading to the mp3 file.
                One last problem, the MediaPlayer is still not working...Failed to load media.... :-/
                But maybe this is a different problem. I am creating the ios builds on virtual machine where sound is not working for some reason and now I found out that I cannot play any mp3 files on that machine. I might try this on some real devices now cause I think that the file is now properly found and passed to the MediaPlayer.
                What do you think?

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 6 Jun 2020, 19:12 last edited by
                  #8

                  I'd change as well. If no audio hardware is detected, I would think it's normal that the media player fails.

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

                  H 1 Reply Last reply 7 Jun 2020, 05:52
                  0
                  • S SGaist
                    6 Jun 2020, 19:12

                    I'd change as well. If no audio hardware is detected, I would think it's normal that the media player fails.

                    H Offline
                    H Offline
                    Hitokage
                    wrote on 7 Jun 2020, 05:52 last edited by
                    #9

                    @SGaist OK thank you so much! I'll mark the thread as resolved if I make it work on other devices.

                    1 Reply Last reply
                    0
                    • H Offline
                      H Offline
                      Hitokage
                      wrote on 19 Jul 2020, 17:32 last edited by Hitokage
                      #10

                      @SGaist Hey so the reference problem is solved. Seems like the file can be opened, the player works but there is no sound :-/. I'll probably open another thread for this issue. Thanks for the help again!
                      EDIT: Or maybe it's working :D. On other devices I got a report that the sound is OK. Will investigate that further!

                      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