public MP3Info getTag() { string filename = currentFile; try { TagLib.File tagFile = TagLib.File.Create(filename); MP3Info info = new MP3Info(); info.Length = tagFile.Properties.Duration; info.Bitrate = tagFile.Properties.AudioBitrate; info.Samplerate = tagFile.Properties.AudioSampleRate; if (info.Length == null) info.Length = TimeSpan.FromSeconds(0); info.Artist = tagFile.Tag.FirstPerformer; info.Title = tagFile.Tag.Title; info.Year = (int)tagFile.Tag.Year; info.Comment = tagFile.Tag.Comment; info.Album = tagFile.Tag.Album; info.Tracknumber = (int)tagFile.Tag.Track; info.Genre = tagFile.Tag.FirstGenre; info.AlbumArtist = tagFile.Tag.FirstAlbumArtist; if (info.Artist == null) info.Artist = ""; if (info.Title == null) info.Title = ""; if (info.Comment == null) info.Comment = ""; if (info.Album == null) info.Album = ""; if (info.Genre == null) info.Genre = ""; if (info.AlbumArtist == null) info.AlbumArtist = ""; return info; } catch (Exception) { return null; } }
protected void loadMP3Info(MP3Info info) { checkBoxAlbum.Checked = false; checkBoxAlbumArtist.Checked = false; checkBoxArtist.Checked = false; checkBoxComment.Checked = false; checkBoxGenre.Checked = false; checkBoxTitle.Checked = false; checkBoxTrackNumber.Checked = false; checkBoxYear.Checked = false; if (info != null) { textBoxAlbum.Text = info.Album; textBoxAlbumArtist.Text = info.AlbumArtist; textBoxArtist.Text = info.Artist; labelBitrate.Text = "Bit Rate: " + info.Bitrate + "kbps"; textBoxComment.Text = info.Comment; textBoxGenre.Text = info.Genre; labelDuration.Text = "Duration: " + (info.Length.Hours * 60 + info.Length.Minutes).ToString() + ":" + String.Format("{0:00}", info.Length.Seconds) + "." + info.Length.Milliseconds / 10; labelSamplerate.Text = "Sample Rate: " + String.Format("{0:#,##0}", info.Samplerate) + "Hz"; textBoxTitle.Text = info.Title; textBoxTrackNumber.Text = info.Tracknumber.ToString(); textBoxYear.Text = info.Year.ToString(); } else { textBoxAlbum.Text = ""; textBoxAlbumArtist.Text = ""; textBoxArtist.Text = ""; labelBitrate.Text = "Bit Rate: "; textBoxComment.Text = ""; textBoxGenre.Text = ""; labelDuration.Text = "Duration: "; labelSamplerate.Text = "Sample Rate: "; textBoxTitle.Text = ""; textBoxTrackNumber.Text = ""; textBoxYear.Text = ""; } }
protected void saveMP3Info() { var info = new MP3Info(); info.Album = checkBoxAlbum.Checked ? textBoxAlbum.Text : null; info.AlbumArtist = checkBoxAlbumArtist.Checked ? textBoxAlbumArtist.Text : null; info.Artist = checkBoxArtist.Checked ? textBoxArtist.Text : null; info.Comment = checkBoxComment.Checked ? textBoxComment.Text : null; info.Genre = checkBoxGenre.Checked ? textBoxGenre.Text : null; info.Title = checkBoxTitle.Checked ? textBoxTitle.Text : null; info.Tracknumber = checkBoxTrackNumber.Checked ? (int?)Convert.ToInt32(textBoxTrackNumber.Text) : null; info.Year = checkBoxYear.Checked ? (int?)Convert.ToInt32(textBoxYear.Text) : null; ctrl.setTag(info); }
public bool setTag(MP3Info info) { string filename = currentFile; TagLib.File tagFile = TagLib.File.Create(filename); if (info.Artist != null) tagFile.Tag.Performers = new string[1] { info.Artist }; if (info.Title != null) tagFile.Tag.Title = info.Title; if (info.Year != null) tagFile.Tag.Year = (uint)info.Year; if (info.Comment != null) tagFile.Tag.Comment = info.Comment; if (info.Album != null) tagFile.Tag.Album = info.Album; if (info.Tracknumber != null) tagFile.Tag.Track = (uint)info.Tracknumber; if (info.Genre != null) tagFile.Tag.Genres = new string[1] { info.Genre }; if (info.AlbumArtist != null) tagFile.Tag.AlbumArtists = new string[1] { info.AlbumArtist }; var pos = getPos(); stop(); tagFile.Save(); loadFile(currentFile); play(pos); return true; }