Import audio from persistentDataPath in Android with Unity

Viewed 21

Thanks in advance to everybody. I had a weird problem trying to reproduce audio files in Android devices. I use the same system for HL2 and it works. I import audio files from the persistentDataPath and the .clip is found. I show the name and checked if it’s different to null and everything is good.The problem is when you want to play it nothing sounds. I tested if the AudioSource has some type of priorisation conflict but when I added a clip manually it Works perfectly. ¿Does someone have any idea what could be the reason?

Here you can find the code:

//PART OF IMPORT AUDIO

private IEnumerator LoadAudioWAV(string Path, string audioName)
{
    WWW request = GetAudioFromFile(Path);
    yield return request;

    audioClip = request.GetAudioClip();
    audioClip.name = audioName;
    if (audioClip != null)
    {
        debug.text += audioClip.name;
    }
    SaveAudioFile();
}

[Obsolete]
private WWW GetAudioFromFile(string path)
{

    WWW request = new WWW(path);
    return request;
}

private void SaveAudioFile()
{
    audioSourcesToPlay.Add(audioClip);
}

//PART OF REPRODUCE

void Play()
{
    int indexList = audioSourcesToPlay.FindIndex(x => x.ToString().Contains(AudioName));

    if (indexList >= 0)
    {
        AudioToPlay.clip = audioSourcesToPlay[indexList];
        debug.text += "//" + "Playing " + AudioToPlay.clip.name + "//";
        AudioToPlay.Play();
    }

}
0 Answers
Related