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); }
// return: xml public ActionResult GetList(string id) { string serverPath = Server.MapPath("/Content/Music/" + id); if (!Directory.Exists(serverPath)) { return(null); } string[] files = Directory.GetFiles(serverPath); playlist list = new playlist(); list.title = "flanker music playlist"; list.info = "http://fengzhichao.cn"; list.trackList = new List <track>(); foreach (string s in files) { if (s.ToLower().EndsWith(".mp3")) { MP3 m = new MP3(); m.fileComplete = s; MP3Helper.readMP3Tag(ref m); track t = new track(); t.annotation = m.ArtistTitle; int index = m.fileComplete.IndexOf("\\Content\\Music"); t.location = m.fileComplete.Substring(index).Replace('\\', '/'); t.info = ""; t.image = ""; list.trackList.Add(t); } } return(new XmlResult(list, list.GetType())); }