Home > Enterprise >  Read And Write Mp3 File Android Unity
Read And Write Mp3 File Android Unity

Time:06-01

I want to download a song from an online server and save it in the device memory. Then recall the saved song from the device memory. This is done correctly with the following code in Windows, but in the Android platform, only the file is saved correctly, but the file is not called and executed from the device memory and gives an error.

    private void Start()
{
    Adress = new WWW("**WebAdress**");
}
public void DownloadButton()
{
    StartCoroutine(LoadMp3FromWeb());
}
IEnumerator LoadMp3FromWeb()
{
    WWW www = Adress;
    Adress = www;
    yield return www;
    System.IO.File.WriteAllBytes((Application.persistentDataPath   ".mp3"), www.bytes);
}


public void LoadButton()
{
    StartCoroutine(LoadAudioClip());
}
IEnumerator LoadAudioClip()
{
    using (UnityWebRequest uwr = UnityWebRequestMultimedia.GetAudioClip((Application.persistentDataPath   ".mp3"), AudioType.MPEG))
    {
        yield return uwr.SendWebRequest();
        Musics = DownloadHandlerAudioClip.GetContent(uwr);    
        myClip.clip = Musics;
        myClip.Play();
    }
}

}

CodePudding user response:

For loading the clip from memory you don't need to send WebRequests to the persistent data path. As that path doesn't exist in the web, it exists on your device only. use System.IO.File.ReadAllBytes instead.

CodePudding user response:

How can I put System.IO.File.ReadAllBytes in my code To Load Mp3 File f?

  • Related