kingBook

导航

unity 远程音频

using System.Collections;
using System.Collections.Generic;
using UnityEditor.SceneManagement;
using UnityEngine;
using UnityEngine.Networking;

public class TestLoadAudio : MonoBehaviour {
    void Start () {
        StartCoroutine(GetAudioClip());
    }

    IEnumerator GetAudioClip () {
        using (UnityWebRequest www = UnityWebRequestMultimedia.GetAudioClip("https://www.ytmp3.cn/down/76041.mp3", AudioType.MPEG)) {
            yield return www.SendWebRequest();

            if (www.isHttpError || www.isNetworkError) {
                Debug.Log(www.error);
            } else {
                AudioClip myClip = DownloadHandlerAudioClip.GetContent(www);


                var audioSource = gameObject.AddComponent<AudioSource>();
                audioSource.clip = myClip;
                audioSource.Play();
                Debug.Log(myClip);
            }
        }
    }
}

posted on 2022-01-18 23:03  kingBook  阅读(75)  评论(0编辑  收藏  举报