2种方式获取StreamingAssets下音频

第一种 unityWebRequest
var unityWebRequest = UnityWebRequest.GetAudioClip(s, 0);
        yield return unityWebRequest.Send();
        if (unityWebRequest.isError)
        {
            Debug.LogError(unityWebRequest.error);
            yield break;
        }
        AudioClip audioClip = DownloadHandlerAudioClip.GetContent(unityWebRequest);
        Debug.Log((int)audioClip.length);
第二种 WWW
WWW www = new WWW("file://"+s);
        yield return www;
        if (www.error != null)
        {
            Debug.Log(www.error);
        }
        AudioClip ac = www.GetAudioClip(true, true, 0);
        Debug.Log(ac.length);

坑:PC平台下,通过这2种方式获取StreamingAssets下音频时,不支持mp3格式

你可能感兴趣的:(Unity)