2

includes/audio/bird.mp3 is bundled up with the app.

var file:File = File.applicationDirectory.resolvePath("includes/audio/bird.mp3");
                    
trace("file",file.exists);
trace("file",file.nativePath);
trace("file",file.url);

outputs
file true
file
file app:/includes/audio/bird.mp3
crooksy88
  • 3,849
  • 1
  • 24
  • 30
  • 3
    Just a guess. The installation process on **Android** does not unpack the **APK** and the bundled files exist within the app's own internal filesystem. Thus, no **nativePath**. Then, you don't actually need the **nativePath** to read files, and you are not allowed to write them anyway, so there's no problem the way the things are. – Organis Nov 23 '21 at 17:40
  • 2
    It seems my guess was correct. Here's the **APK** installation process explained, and there's no unpacking to the native filesystem mentioned: https://stackoverflow.com/a/32067673/4687633 – Organis Nov 24 '21 at 02:54

1 Answers1

3

This is expected.

Files packaged in the applicationDirectory are compressed as part of the APK and don't have a direct file system path. You will need to extract them to an accessible location, (applicationStorageDirectory).

In AIR simply copy the File reference to the File.applicationStorageDirectory and then you should have a native path reference if you really need that.

var file:File = File.applicationDirectory.resolvePath("includes/audio/bird.mp3");
var fileAccessible:File = File.applicationStorageDirectory.resolvePath("bird.mp3");

file.copyTo( fileAccessible );

trace( fileAccessible.nativePath );
Michael
  • 3,776
  • 1
  • 16
  • 27
  • As this mp3 is accessed by Starling (using AssetManager.playSound("bird")) am I correct in assuming Starling extracts the mp3 and stores it somewhere ready for reading? If so, does anyone know where this is? – crooksy88 Nov 24 '21 at 08:31
  • Pretty sure you pass the path to files into the AssetManager and it will read them directly. I don't think it will copy the mp3 anywhere else. It will most likely load the mp3 into a Sound object and store that in memory. – Michael Nov 26 '21 at 00:37
  • Ah. The reason for asking is that Distriqt.AudioPlayer requires a nativePath. So am I correct in thinking that as the AudioPlayer is using an external, native player, it cannot access the bundled mp3. – crooksy88 Nov 26 '21 at 12:26