/// <summary> /// 保存MP3ID3V2TAG /// </summary> /// <param name="filePath"></param> private void SaveMP3TagInfo(string filePath) { try { ID3V2Tag tag = new ID3V2Tag(filePath); //曲名 tag.TrackTitleName = TrackNameTextBox.Text; //艺术家 tag.ArtistName = ArtistTextBox.Text; //专辑 tag.AlbumName = AlbumNameTextBox.Text; //音轨 tag.TrackNo = TrackNoTextBox.Text; //碟号 tag.DiscNo = DiscNoTextBox.Text; tag.Save(filePath); } catch (Exception ex) { MsgBox.Show(MSG_COMMON_001, ex.ToString()); } }
/// <summary> /// 显示当前曲目信息 /// </summary> /// <param name="TrackID"></param> private void ShowCurrentInfo(string TrackID) { TrackCurInfo.Clear(); ArtistCurInfo.Clear(); ResourceCurInfo.Clear(); trackInfoDataGridView.Rows.Clear(); artistInfoDataGridView.Rows.Clear(); //选中曲目 var targetTrack = from track in this.TrackInfo where track.TrackID.Equals(TrackID) select track; foreach (MusicDataSet.TrackInfoRow trackRow in targetTrack) { TrackCurInfo.ImportRow(trackRow); } //选中艺术家 var targetArtist = from artist in this.ArtistInfo join track in this.TrackInfo on artist.ArtistID equals track.ArtistID where track.TrackID.Equals(TrackID) select artist; foreach (MusicDataSet.ArtistInfoRow artistRow in targetArtist) { ArtistCurInfo.ImportRow(artistRow); } //选中资源 var targetResource = from resource in this.ResourceInfo join trackresource in this.TrackResourceInfo on resource.ResourceID equals trackresource.ResourceID join track in this.TrackInfo on trackresource.TrackID equals track.TrackID where track.TrackID.Equals(TrackID) select resource; foreach (MusicDataSet.ResourceInfoRow resourceRow in targetResource) { ResourceCurInfo.ImportRow(resourceRow); } //封面 var targetMusic = from resource in this.ResourceCurInfo where resource.ResourceTypeID.Equals("1") select resource; foreach (MusicDataSet.ResourceInfoRow music in targetMusic) { ID3V2Tag tag = new ID3V2Tag(music.ResourcePath); foreach (Image img in tag.TrackImages) { AlbumJacketBox.Image = img; break; } break; } ShowDicDataGridViewInfo(); }
/// <summary> /// 显示指定路径的MP3Tag信息 /// </summary> /// <param name="filePath">文件路径</param> public void ShowMP3TagInfo(string filePath) { if (filePath == null || filePath.ToString().Equals(string.Empty)) { TrackNameTextBox.Text = string.Empty; ArtistTextBox.Text = string.Empty; AlbumNameTextBox.Text = string.Empty; TrackNoTextBox.Text = string.Empty; DiscNoTextBox.Text = string.Empty; AlbumPictureBox.Image = null; return; } try { ID3V2Tag tag = new ID3V2Tag(filePath); //封面 foreach (Image img in tag.TrackImages) { AlbumPictureBox.Image = img; } //曲名 TrackNameTextBox.Text = tag.TrackTitleName; //艺术家 ArtistTextBox.Text = tag.ArtistName; //专辑 AlbumNameTextBox.Text = tag.AlbumName; //音轨 TrackNoTextBox.Text = tag.TrackNo; //碟号 DiscNoTextBox.Text = tag.DiscNo; } catch (Exception ex) { MsgBox.Show(MSG_COMMON_001, ex.ToString()); } }
/// <summary> /// 展示导入的音乐 /// </summary> /// <param name="musicPath">音乐路径数组</param> private void ShowMusicInfo(string[] musicPath) { //导入列表 MusicDataSet.ImportMusicListDataTable importList = new MusicDataSet.ImportMusicListDataTable(); for (int i = 0; i < musicPath.Length; i++) { if (!System.IO.File.Exists(musicPath[i])) { MsgBox.Show(MSG_IMPORTMUSIC_001, musicPath[i]); continue; } //------做成新曲目 开始------ MusicDataSet.ImportMusicListRow importRow = importList.NewImportMusicListRow(); //FilePath importRow.FilePath = musicPath[i]; ID3V2Tag tag = new ID3V2Tag(importRow.FilePath); //TrackID 仮采番 importRow.TrackID = service.GetNextTrackID(); //AlbumID 仮采番 importRow.AlbumID = service.GetAlbumIDFromAlbumTitleName(tag.AlbumName); //TrackTypeID //DiscNo importRow.DiscNo = tag.DiscNo; //TrackNo importRow.TrackNo = tag.TrackNo; //OldTrackNo //AlbumTitleName importRow.AlbumTitleName = tag.AlbumName.Replace('�', char.MinValue); //TrackTitleName importRow.TrackTitleName = tag.TrackTitleName.Replace('�', char.MinValue); //ArtistName importRow.ArtistName = tag.ArtistName.Replace('�', char.MinValue); //ArtistID //AnimeNo //SalesYear importRow.SalesYear = tag.SalesYear.Replace('�', char.MinValue); //TrackLength importRow.TrackLength = tag.TrackLength.Replace('�', char.MinValue); //BitRate importRow.BitRate = tag.BitRate.TrimEnd('\0'); importList.AddImportMusicListRow(importRow); } importList.AcceptChanges(); DataView dv = importList.DefaultView; dv.Sort = "AlbumID asc , DiscNo asc , TrackNo asc"; MusicDataSet.ImportMusicListDataTable newImportList = new MusicDataSet.ImportMusicListDataTable(); newImportList.Merge(dv.ToTable()); foreach (MusicDataSet.ImportMusicListRow ir in newImportList.Rows) { DataGridViewRow dr = MusicDataGridView.Rows[MusicDataGridView.Rows.Add()]; dr.Cells[TRACKIDCLN].Value = ir.TrackID; if (ir.TrackTitleName != null) { dr.Cells[TRACKNAMECLN].Value = ir.TrackTitleName.Replace('�', char.MinValue).Trim('\0'); } dr.Cells[ALBUMIDCLN].Value = ir.AlbumID; if (ir.AlbumTitleName != null) { dr.Cells[ALBUMNAMECLN].Value = ir.AlbumTitleName.Replace('�', char.MinValue).Trim('\0'); } if (ir.ArtistName != null) { dr.Cells[ARTISTNAMECLN].Value = ir.ArtistName.Replace('�', char.MinValue).Trim('\0'); } if (ir.DiscNo != null) { dr.Cells[DISCNOCLN].Value = ir.DiscNo.Replace('�', char.MinValue).Trim('\0'); } if (ir.TrackNo != null) { dr.Cells[TRACKNOCLN].Value = ir.TrackNo.Replace('�', char.MinValue).Trim('\0'); } if (!ir.IsSalesYearNull()) { dr.Cells[YEARCLN].Value = ir.SalesYear.Replace('�', char.MinValue).Trim('\0'); } if (!ir.IsDescriptionNull()) { dr.Cells[DESCRIPTIONCLN].Value = ir.Description; } if (!ir.IsBitRateNull()) { dr.Cells[BITRATECLN].Value = ir.BitRate; } if (!ir.IsTrackLengthNull()) { dr.Cells[TRACKTIMELENGTHCLN].Value = ir.TrackLength; } dr.Cells[RESOURCEPATHCLN].Value = ir.FilePath; //艺术家处理 //Todo:预留同名artist处理机制:复数artist int artistID = service.GetArtistIDFromArtistName(ir.ArtistName); if (artistID > 0) { //不在dic,在DB中存在名称完全相同,加入dic dr.Cells[ARTISTIDCLN].Value = artistID; } SetArtistCellStyle(dr.Cells[ARTISTNAMECLN], ir.ArtistName); //MusicDataGridView.Sort(MusicDataGridView.Columns[ALBUMIDCLN], ListSortDirection.Ascending); } dgvStyle.SetDataGridViewColumnWidch(MusicDataGridView, new int[] { 120, //OldTrackNo 100, //TrackNo 200, //TrackName 80, //TrackType 100, //AlbumNo 200, //AlbumName 80, //AlbumType 200, //ArtistName 120, //AnimeCHNName 80, //BitRate 70, //DiscNo 70, //TrackNo 120, //Year 100, //TrackLength 300, //ResourcePath 200 //Description }); string firstRowPath = null; if (MusicDataGridView.Rows.Count != 0) { firstRowPath = MusicDataGridView.Rows[0].Cells[RESOURCEPATHCLN].Value.ToString(); ShowMP3TagInfo(firstRowPath); } }