Cannot Load AudioClip from file on android

I’m trying to load an AudioClip from a .wav file.
It works in the editor but doesn’t work on Android, and I didn’t check it on iOS yet.
I tried loading using the Application.persistentDataPath but when I debug the game on Android Studio I get this error:

E/Unity: Curl error 7: Failed to connect to localhost port 80: Connection refused

Basically I need to save and load wav files in runtime on Android and iOS. They should be saved as .wav files somewhere on the device.

I tried this, this, this and this.

Any idea? Thanks!

same here

This one worked for me:
Both “file://” and “file:///” worked for me as well.
Notice that sometimes I used streamingAssetsPath and sometimes persistentDataPath.

#if UNITY_EDITOR || UNITY_ANDROID
            XDirectory = Application.streamingAssetsPath + "/X/";
            YDirectory = Application.streamingAssetsPath + "/Y/";
            ZDirectory = Application.streamingAssetsPath + "/Z/";
#elif UNITY_IOS
            XDirectory= "file://" + Application.streamingAssetsPath + "/X/";
            YDirectory= "file://" + Application.streamingAssetsPath + "/Y/";
            ZDirectory= "file://" + Application.streamingAssetsPath + "/Z/";
#endif

// Use this when you need to approach that file (delete, rename...)
            RecordingsDirectoryWithoutPrefix = Application.persistentDataPath + "/W/";
// Use this when you need to approach that file from your app (load image, text, audio...)
            RecordingsDirectoryWithPrefix = "file:///" + Application.persistentDataPath + "/W/";

I hope this helped you!

1 Like

@ghgfhj OMG thank you! i’ve looked everywhere to find a solution even chatgtp could not help :smile: Genius its just “file:///” to add and its working :smile: