[Unity] Play Streaming Music From Server
Unity3D/Extensions / 2018. 2. 6. 10:36
유니티에서 스트리밍 방식으로 미리듣기를 재생하기 위해 처리.
[Engine] Unity v5.6.5f1
IEnumerator LoadPreListening_Streaming_Server() { AudioSource asPreListening = new AudioSource(); WWW www = new WWW("URL"); while (www.progress < 0.01) { Debug.Log(www.progress); yield return null; } if (!string.IsNullOrEmpty(www.error)) { Debug.Log(www.error); yield break; } else { yield return null; //asPreListening.clip = WWWAudioExtensions.GetAudioClip(www, false, true, AudioType.MPEG); // MP3 asPreListening.clip = WWWAudioExtensions.GetAudioClip(www, false, true, AudioType.OGGVORBIS); // OGG while (asPreListening.clip.loadState == AudioDataLoadState.Failed || asPreListening.clip.loadState == AudioDataLoadState.Unloaded || asPreListening.clip.loadState == AudioDataLoadState.Loading) { yield return null; } if (asPreListening.clip.loadState == AudioDataLoadState.Loaded) { // Play PreListening asPreListening.time = 0f; asPreListening.volume = 0f; asPreListening.loop = true; asPreListening.Play(); } } }
[참조]
반응형
'Unity3D > Extensions' 카테고리의 다른 글
[펌] Unity – How to copy a string to Clipboard (0) | 2022.07.19 |
---|---|
[펌] Find objects with DontDestroyOnLoad (0) | 2021.11.26 |
[펌] ADDING TO UNITY'S BUILT-IN CLASSES USING EXTENSION METHODS (0) | 2016.10.20 |
일괄적으로 Texture Import Setting 변경 (0) | 2015.01.30 |
Extension Methods (0) | 2014.08.18 |