Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Can't load audio from persistentDataPath with UnityWebRequestMultimedia (404)

Discussion in 'WebGL' started by Dragonic8926, Mar 12, 2022.

  1. Dragonic8926

    Dragonic8926

    Joined:
    Mar 10, 2014
    Posts:
    34
    Hello,

    I have a small WebGL project where I need to download and save multiples (hundreds) small audio files (MP3) from another server into the persistentDataPath, to be used later in the app as AudioClips.

    - download the MP3s from remote server and save audio files in current server with
    Code (CSharp):
    1. System.IO.File.WriteAllBytes(Application.persistentDataPath + "/" + filename, webRequest.downloadHandler.data);
    Working without issue, and I can see the audio files stored in the IndexedDB.

    - retrieving an audio file from persistentDataPath (IndexedDB) :
    Code (CSharp):
    1. System.IO.File.Exists (Application.persistentDataPath + "/" + filename)
    return TRUE

    and

    Code (CSharp):
    1. Byte[] bytes = System.IO.File.ReadAllBytes(Application.persistentDataPath + "/" + filename);
    2. Debug.Log("bytes length : "+bytes.Length);
    return right length of the file

    So I know that my file can be found at the right place in WebGL IndexedDB.

    BUT

    Code (CSharp):
    1. UnityWebRequestMultimedia.GetAudioClip(Application.persistentDataPath + "/" + filename, AudioType.MPEG)
    will get me a 404 because UnityWebRequest will automaticaly add the scheme and host of the path of the website where my WebGL app is loaded.

    So instead of something like that for UnityWebRequest.url :
    /idbfs/eeea60de649e89f719d7cb47c998e012/audio.mp3


    I have a bad URL like this :
    https://mywebsite.com/idbfs/eeea60de649e89f719d7cb47c998e012/audio.mp3


    That's why I get a 404 !

    And because of that I don't know how to get the right URL to retrieve and load the audio files as AudioClip from the persistentDataPath in WebGL (work without issue in Editor, windows Build and Android build).
    Or maybe there is a way to get the AudioClip from the raw bytes ?

    Any help appreciated ^^ !
     
    Last edited: Mar 14, 2022
  2. Dragonic8926

    Dragonic8926

    Joined:
    Mar 10, 2014
    Posts:
    34
    Nobody can help about this issue ?

    I didn't found any alternative and really need to load AudioClips from MP3s in persistentDataPath with WebGL !
     
  3. Dragonic8926

    Dragonic8926

    Joined:
    Mar 10, 2014
    Posts:
    34
    I try one last message to ask for help about this issue !
     
  4. AkshayGhosh

    AkshayGhosh

    Joined:
    Jan 8, 2017
    Posts:
    4
    Did you find any solution or any alternate way of doing it?i am also trying something similar and am stuck in the same issue
     
  5. rgonsalv

    rgonsalv

    Joined:
    Sep 29, 2016
    Posts:
    47
    You can preface the path sent to GetAudioClip with "file://" , that way "http://" won't be prepended.