Created
February 18, 2020 02:55
-
-
Save IJEMIN/f445458748d003d8f2201981776ec6d8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.IO; | |
using UnityEngine; | |
using UnityEngine.Networking; | |
public class WebAudioImporter : MonoBehaviour | |
{ | |
private MobileImporter mobileImporter; | |
private void Start() | |
{ | |
mobileImporter = GetComponent<MobileImporter>(); | |
mobileImporter.Loaded += OnAudioLoaded; | |
StartCoroutine(DownloadAndLoadAudio()); | |
} | |
private IEnumerator DownloadAndLoadAudio() | |
{ | |
var req = UnityWebRequest.Get("https://file-examples.com/wp-content/uploads/2017/11/file_example_MP3_700KB.mp3"); | |
yield return req.SendWebRequest(); | |
var downloadedBytes = req.downloadHandler.data; | |
var savePath = Path.Combine(Application.temporaryCachePath, "downloadedAudio.mp3"); | |
File.WriteAllBytes(savePath, downloadedBytes); | |
mobileImporter.Import(savePath); | |
} | |
private void OnAudioLoaded(AudioClip audioClip) | |
{ | |
Debug.Log(audioClip.length); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment