简体   繁体   中英

Unity Add mp3 file from persistentDataPath

need your help with turn on mp3 file(with wav and ogg file all is ok) from persistentDataPath in Unity. I have this code to find audio file in persistentDataPath and turn on as AudioClip

public void StartAudio()
{
    StartCoroutine(PlayAudioClip());
}

IEnumerator PlayAudioClip()
{
    UnityWebRequest www = UnityWebRequestMultimedia.GetAudioClip(Application.persistentDataPath + "/" + "_song", AudioType.MPEG);
    yield return www.Send();
    //WWW testrequest = new WWW(Application.persistentDataPath + "/" + "_song.mp3");
    if (www.isNetworkError)
        Debug.Log("play error: " + www.error);
    else
    {
        AudioClip audioTrack = DownloadHandlerAudioClip.GetContent(www);
        audio.clip = audioTrack;
        audio.Play();
    }
}

But when I tried to turn on mp3 file I had this error

Streaming of 'mpeg' on this platform is not supported
UnityEngine.Networking.DownloadHandlerAudioClip:GetContent(UnityWebRequest)

好吧,我又在谷歌上搜索了一段时间并创建了这个qa ,所以它真的很不真实-(

Upgrading Unity to 2020.1.14f1 and above should play mp3 audio clips. Unity Answers .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM