Question by
arinozkinay · Feb 19, 2018 at 01:30 AM ·
audiowwwnot workingclip
WWW Audio - 404 Not Found (WWW.error)
private void Start()
{
urls = (Application.dataPath + "/MainMenu.ogg");
StartCoroutine(Sound(urls));
}
IEnumerator Sound(string url)
{
WWW www = new WWW(url);
yield return www;
AudioSource audio = GetComponent<AudioSource>();
audio.clip = www.GetAudioClip(false, false);
audio.Play();
if (!string.IsNullOrEmpty(www.error))
Debug.Log(www.error);
}
When i try mp3, it says "not supported" but what is happening now with 404 Not Found?
Thanks
Comment
It says "404 Not Found" even if i try mp3 but it also says that it's not supported. The problem is that i can see that audiosource has something but it's empty.
Best Answer
Answer by arinozkinay · Feb 19, 2018 at 02:27 AM
This Works
public string url;
AudioSource audio;
private void Start()
{
audio = GetComponent<AudioSource>();
url = ("file:///" + Application.persistentDataPath + "/MainMenu.ogg");
print(url);
StartCoroutine(DownloadAndPlay(url));
}
IEnumerator DownloadAndPlay(string url)
{
WWW www = new WWW(url);
yield return www;
audio = GetComponent<AudioSource>();
audio.clip = www.GetAudioClip(false, stream: false, audioType: AudioType.OGGVORBIS);
audio.Play();
if (!string.IsNullOrEmpty(www.error))
Debug.Log(www.error);
}
Your answer
Follow this Question
Related Questions
audio.play does not work 1 Answer
[HELP] Audio does not play in inspector, game mode, or in build. Unity 5.6.2 0 Answers
Audio doesnt play in the phone but play on the editor 0 Answers
Creating a Custom Music folder - Works inside the editor - Issues with build. 0 Answers
Play audio once not working 0 Answers