Unity3d动态加载本地音乐,UnityWebRequestMultimedia不卡顿
private AudioSource aud; private void Awake() { aud = GetComponent<AudioSource>(); } //filepath 绝对路径 安卓sdcard 或者PC 绝对路径 public IEnumerator LoadMusic(string filepath) { filepath = "file://" + filepath; using (var uwr = UnityWebRequestMultimedia.GetAudioClip(filepath, AudioType.UNKNOWN)) { //不卡顿的2行代码 ((DownloadHandlerAudioClip)uwr.downloadHandler).compressed = false; ((DownloadHandlerAudioClip)uwr.downloadHandler).streamAudio = true; yield return uwr.SendWebRequest(); if (uwr.isNetworkError) { Debug.LogError(uwr.error); } else { AudioClip clip = DownloadHandlerAudioClip.GetContent(uwr); if (aud.clip!=null) //释放上次的 { AudioClip.Destroy(aud.clip); } aud.clip = clip; aud.Play();//播放 } } }