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 FindMusic(List <string> filelist) { int index = 1; List <Music> TempList = new List <Music>(); foreach (var item in filelist) { FileInfo file = new FileInfo(item); MP3Info m = new MP3Info(); m.GetMP3Info(file.DirectoryName, file.Name); if (file.Extension.Contains(".mp3")) { TempList.Add(new Music() { Title = m.trackName, Size = file.Length, Index = index.ToString(), Url = file.FullName, Album = m.Album, Artist = m.Artist, TimeStr = m.time }); index++; } } if (TempList.Count > 0) { Execute.OnUIThread(() => { foreach (var item in TempList) { if (MusicList.Where(p => p.Title == item.Title).Count() == 0) { MusicList.Add(item); } } //显示歌曲列表 ShowMusicList(); //保存找到的歌曲 Save(); }); } }
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); }
private void btnBrowseAudioFile_Click(object sender, EventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); if (lameExists) { ofd.Filter = "Wave|*.wav|MP3|*.mp3|All|*.wav;*.mp3"; ofd.FilterIndex = 3; } else { ofd.Filter = "Wave|*.wav"; } if (ofd.ShowDialog() == DialogResult.OK) { if (ofd.FileName != tbAudioFile.Text) { btnConvert.Enabled = false; tbarLoopStartSample.Enabled = false; mp3LengthKnown = false; cbSourceSound.Checked = false; tbAudioFile.Text = ofd.FileName; if (ofd.FileName.EndsWith(".wav")) { rbFromAudioFile.Enabled = true; foreach (Label thisLabel in gbWaveInfo.Controls) if (thisLabel.Name.ToLower().Contains("value")) { thisLabel.ForeColor = System.Drawing.Color.Black; thisLabel.Text = "Gathering"; } bwGatherInfo.RunWorkerAsync(ofd.FileName); this.Size = new System.Drawing.Size(gbWaveInfo.Location.X + gbWaveInfo.Size.Width + 15, this.Size.Height); } else if (ofd.FileName.EndsWith(".mp3")) { channelCount = 0; btnConvert.Enabled = true; if (rbFromAudioFile.Checked) rbNone.Checked = true; rbFromAudioFile.Enabled = false; this.Size = new System.Drawing.Size(btnCancel.Location.X + btnCancel.Size.Width + 15, this.Size.Height); try { MP3Info mp3Info = new MP3Info(ofd.FileName); tbarLoopStartSample.Maximum = mp3Info.AudioSamples; mp3LengthKnown = true; if (rbEnterManually.Checked) tbarLoopStartSample.Enabled = true; } catch { } } } } }
public MusicItem AddItem(string name, string listname, bool b = false) { MusicItem se = null; bool Searched = false; foreach (MusicListItem iy in Groups) { if (iy.Name == listname) { Searched = true; } } if (Searched) { if (IsInList(name, listname)) { return(null); } else { int a = 0; for (int i = 0; i < Items.Count; i++) { if (Items[i].Tag != null) { if (Items[i].Tag.ToString() == listname) { a = a + 1; } } } DuiBaseControl ix = null; foreach (DuiBaseControl ixx in Items) { if (ixx.Name.Replace("list_", "") == listname) { ix = ixx; } } if (File.Exists(name)) { #region 本地音乐 Mp3Info info = MP3Info.GetMp3Info(name); string artists = info.Artist; string album = info.Album; string length = info.MusicLength; string title = info.Title; DuiLabel infoforsinger = new DuiLabel(); infoforsinger.TextRenderMode = System.Drawing.Text.TextRenderingHint.AntiAlias; infoforsinger.Size = new Size(140, 20); if (artists != "") { infoforsinger.Text = "-" + artists; } infoforsinger.Location = new Point(160, 4); infoforsinger.ForeColor = Color.FromArgb(220, 220, 220); infoforsinger.Font = new Font("微软雅黑", 9F); infoforsinger.Name = "infoforsinger"; DuiPictureBox albumpic = new DuiPictureBox(); albumpic.Size = new Size(50, 50); albumpic.Location = new Point(5, 0); albumpic.Name = "albumpic"; albumpic.BackgroundImage = Properties.Resources.default_album; albumpic.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; albumpic.Visible = false; DuiLabel infoforTimer = new DuiLabel(); infoforTimer.Size = new Size(70, 20); infoforTimer.Text = length; infoforTimer.Location = new Point(350, 4); infoforTimer.ForeColor = Color.FromArgb(255, 255, 255); infoforTimer.Font = new Font("微软雅黑", 9F); infoforTimer.Name = "infoforTimer"; infoforTimer.TextRenderMode = System.Drawing.Text.TextRenderingHint.AntiAlias; DuiButton btnplay = new DuiButton(); btnplay.Size = new Size(20, 20); btnplay.Location = new Point(295, 3); btnplay.NormalImage = Properties.Resources.list_btn_play_normal; btnplay.HoverImage = Properties.Resources.list_btn_play_hover; btnplay.PressedImage = Properties.Resources.list_btn_play_press; btnplay.MouseClick += Btnplay_MouseDown; btnplay.MouseEnter += Btnplay_MouseEnter; btnplay.MouseLeave += Btnplay_MouseLeave; btnplay.Name = "btnplay"; btnplay.Tag = name; btnplay.Visible = false; DuiButton btnpause = new DuiButton(); btnpause.Size = new Size(20, 20); btnpause.Location = new Point(295, 3); btnpause.NormalImage = Properties.Resources.list_btn_pause_normal; btnpause.HoverImage = Properties.Resources.list_btn_pause_hover; btnpause.PressedImage = Properties.Resources.list_btn_pause_press; btnpause.MouseClick += Btnpause_MouseClick; btnpause.Name = "btnpause"; btnpause.Tag = name; btnpause.MouseEnter += Btnpause_MouseEnter; btnpause.MouseLeave += Btnpause_MouseLeave; btnpause.Visible = false; DuiButton btndel = new DuiButton(); btndel.Size = new Size(20, 20); btndel.Location = new Point(317, 3); btndel.NormalImage = Properties.Resources.btn_del_h; btndel.HoverImage = Properties.Resources.btn_del_n; btndel.PressedImage = Properties.Resources.btn_del_p; btndel.MouseClick += Btndel_MouseClick; btndel.MouseEnter += Btndel_MouseEnter; btndel.MouseLeave += Btndel_MouseLeave; btndel.Name = "btndel"; btndel.Tag = listname; btndel.Visible = false; DuiLabel lbl = new DuiLabel(); lbl.TextRenderMode = System.Drawing.Text.TextRenderingHint.AntiAlias; lbl.Size = new System.Drawing.Size(160, 17); if (Path.GetFileNameWithoutExtension(name).Length > 14) { lbl.Text = Path.GetFileNameWithoutExtension(name).Remove(13).Insert(13, "..."); lbl.Tag = Path.GetFileNameWithoutExtension(name); lbl.MouseEnter += Lbl_MouseEnter; lbl.MouseLeave += Lbl_MouseLeave; } else { lbl.Text = Path.GetFileNameWithoutExtension(name); lbl.Tag = Path.GetFileNameWithoutExtension(name); } lbl.Location = new Point(10, 4); lbl.ForeColor = Color.FromArgb(255, 255, 255); lbl.Font = new Font("微软雅黑", 9F); lbl.Name = "lbl"; DuiBaseControl listx = new DuiBaseControl(); listx.BackColor = Color.FromArgb(0, Color.Black); listx.Width = Width; listx.Height = 25; listx.Controls.Add(lbl); listx.Controls.Add(infoforsinger); listx.Controls.Add(infoforTimer); listx.Controls.Add(btndel); listx.Controls.Add(btnplay); listx.Controls.Add(btnpause); listx.Controls.Add(albumpic); listx.MouseDown += Listx_MouseDown; listx.MouseUp += Listx_MouseUp; listx.MouseMove += Listx_MouseMove; listx.MouseEnter += Listx_MouseEnter; listx.MouseLeave += Listx_MouseLeave; listx.MouseDoubleClick += Listx_MouseDoubleClick; listx.MouseClick += Listx_MouseClick; listx.Name = name; listx.Height = 25; listx.Tag = listname; if (!b) { Items.Add(listx); } else { Items.Insert(Items.IndexOf(ix) + a + 1, listx); } foreach (MusicListItem iy in Groups) { if (iy.Name == listname) { MusicItem m = new MusicItem(); m.Path = name; m.IsOnline = false; m.ParentName = listname; if (title != "") { m.Name = title; } else { m.Name = lbl.Tag.ToString(); } m.Singer = artists; iy.musics.Add(m); } } if (OpenedList == listname) { listx.Visible = true; } else { listx.Visible = false; } #endregion } else { #region 失效音乐 DuiLabel infoforTimer = new DuiLabel(); infoforTimer.Size = new Size(70, 20); infoforTimer.Text = "文件失效"; infoforTimer.Location = new Point(350, 4); infoforTimer.ForeColor = Color.Red; infoforTimer.Font = new Font("微软雅黑", 9F); infoforTimer.Name = "infoforTimer"; infoforTimer.TextRenderMode = System.Drawing.Text.TextRenderingHint.AntiAlias; DuiButton btndel = new DuiButton(); btndel.Size = new Size(20, 20); btndel.Location = new Point(317, 3); btndel.NormalImage = Properties.Resources.btn_del_h; btndel.HoverImage = Properties.Resources.btn_del_n; btndel.PressedImage = Properties.Resources.btn_del_p; btndel.MouseClick += Btndel_MouseClick; btndel.MouseEnter += Btndel_MouseEnter; btndel.MouseLeave += Btndel_MouseLeave; btndel.Name = "btndel"; btndel.Tag = listname; btndel.Visible = false; DuiLabel lbl = new DuiLabel(); lbl.TextRenderMode = System.Drawing.Text.TextRenderingHint.AntiAlias; lbl.Size = new System.Drawing.Size(160, 20); if (Path.GetFileNameWithoutExtension(name).Length > 14) { lbl.Text = Path.GetFileNameWithoutExtension(name).Remove(13).Insert(13, "..."); lbl.MouseEnter += Lbl_MouseEnter; } else { lbl.Text = Path.GetFileNameWithoutExtension(name); } lbl.Location = new Point(10, 4); lbl.ForeColor = Color.Red; lbl.Font = new Font("微软雅黑", 9F); lbl.Name = "lbl"; lbl.Tag = Path.GetFileNameWithoutExtension(name); lbl.MouseLeave += Lbl_MouseLeave; DuiBaseControl listx = new DuiBaseControl(); listx.BackColor = Color.FromArgb(0, Color.Black); listx.Width = Width; listx.Height = 25; listx.Controls.Add(lbl); listx.Controls.Add(infoforTimer); listx.Controls.Add(btndel); listx.MouseMove += Listx_MouseMove; listx.MouseDown += Listx_MouseDown; listx.MouseUp += Listx_MouseUp; listx.MouseEnter += Listx_MouseEnterLose; listx.MouseLeave += Listx_MouseLeaveLose; listx.Name = name; listx.Height = 25; listx.Tag = listname; if (!b) { Items.Add(listx); } else { Items.Insert(Items.IndexOf(ix) + a + 1, listx); } foreach (MusicListItem iy in Groups) { if (iy.Name == listname) { MusicItem m = new MusicItem(); m.Path = name; m.IsOnline = false; iy.musics.Add(m); } } if (OpenedList == listname) { listx.Visible = true; } else { listx.Visible = false; } #endregion } a = a + 1; if (a == 0) { ((DuiLabel)ix.FindControl("Count")[0]).Text = "[这个列表没有歌曲,可以直接把歌曲拖到这里来哦]"; } else { ((DuiLabel)ix.FindControl("Count")[0]).Text = "[" + a.ToString() + "]"; } RefreshList(); } } GC.Collect(); return(se); }
private void btnBrowseAudioFile_Click(object sender, EventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); if (lameExists) { ofd.Filter = "Wave|*.wav|MP3|*.mp3|All|*.wav;*.mp3"; ofd.FilterIndex = 3; } else { ofd.Filter = "Wave|*.wav"; } if (ofd.ShowDialog() == DialogResult.OK) { if (ofd.FileName != tbAudioFile.Text) { btnConvert.Enabled = false; tbarLoopStartSample.Enabled = false; mp3LengthKnown = false; cbSourceSound.Checked = false; tbAudioFile.Text = ofd.FileName; if (ofd.FileName.EndsWith(".wav")) { rbFromAudioFile.Enabled = true; foreach (Label thisLabel in gbWaveInfo.Controls) { if (thisLabel.Name.ToLower().Contains("value")) { thisLabel.ForeColor = System.Drawing.Color.Black; thisLabel.Text = "Gathering"; } } bwGatherInfo.RunWorkerAsync(ofd.FileName); this.Size = new System.Drawing.Size(gbWaveInfo.Location.X + gbWaveInfo.Size.Width + 15, this.Size.Height); } else if (ofd.FileName.EndsWith(".mp3")) { channelCount = 0; btnConvert.Enabled = true; if (rbFromAudioFile.Checked) { rbNone.Checked = true; } rbFromAudioFile.Enabled = false; this.Size = new System.Drawing.Size(btnCancel.Location.X + btnCancel.Size.Width + 15, this.Size.Height); try { MP3Info mp3Info = new MP3Info(ofd.FileName); tbarLoopStartSample.Maximum = mp3Info.AudioSamples; mp3LengthKnown = true; if (rbEnterManually.Checked) { tbarLoopStartSample.Enabled = true; } } catch { } } } } }