IEnumerator GetAudioClipAsStream() { WWW www = new WWW(url); yield return(www); if (www.error != null) { Debug.Log(www.error); yield break; } Stream stream = new MemoryStream(www.bytes); MP3Info info = MP3Helper.ReadMP3Info(stream); audioSource.clip = Mp3Loader.LoadMp3(stream); if (audioSource.clip.length > 1) // check if the clip is loaded, mybe not that clever,ha.. { msg.text = "MP3 has been Loaded .. "; button.interactable = true; } if (!string.IsNullOrEmpty(info.Title)) // fill the title text { Debug.Log(info.ToString()); string name = info.Title.Trim(); title.text = name; detail.text = info.ToString(); } }
void Start() { audioSource = GetComponent <AudioSource>(); MP3Info info = MP3Helper.ReadMP3Info(Path); audioSource.clip = Mp3Loader.LoadMp3(Path); if (!string.IsNullOrEmpty(info.Title)) { Debug.Log(info.ToString()); } //StartCoroutine(GetAudioClipAsStream()); }
private void LoadMp3File() { string Path = System.IO.Path.Combine(Application.dataPath, path); msg.text = "Start Load MP3 .."; MP3Info info = MP3Helper.ReadMP3Info(Path); audioSource.clip = Mp3Loader.LoadMp3(Path); if (audioSource.clip.length > 1) // check if the clip is loaded, mybe not that clever,ha.. { msg.text = "MP3 has been Loaded .. "; button.interactable = true; } if (!string.IsNullOrEmpty(info.Title)) // fill the title text { Debug.Log(info.ToString()); title.text = info.Title; detail.text = info.ToString(); } }
public static AudioClip LoadMp3(Stream stream) { MP3Info info = MP3Helper.ReadMP3Info(stream); string musicName = "DefaultName"; if (!string.IsNullOrEmpty(info.Title)) { musicName = info.Title; } MpegFile mpegFile = new MpegFile(stream); // assign samples into AudioClip AudioClip ac = AudioClip.Create(musicName, (int)(mpegFile.Length / sizeof(float) / mpegFile.Channels), mpegFile.Channels, mpegFile.SampleRate, true, data => { int actualReadCount = mpegFile.ReadSamples(data, 0, data.Length); } //p=> { Debug.Log(p.ToString()); }//position => { mpegFile = new MpegFile(filePath); } ); return(ac); }