/// <summary> /// Воспроизвести трек /// </summary> /// <param name="url">Путь к треку</param> private void PlayTrack(string url) { WMPlayer.URL = url; //записать путь к треку в плеер TagLib.File song = TagLib.File.Create(WMPlayer.URL); //создать файл с тегами трека FullDurationLabel.Text = SecondsToTime((int)song.Properties.Duration.TotalSeconds); //выводим длительность трека TitleLabel.Text = song.Tag.Title; //выводим название трека ArtistLabel.Text = song.Tag.FirstPerformer; //выводим исполнителя трека timer1.Enabled = true; //включаем таймер для ползунка длительности PlayButton.Image = Properties.Resources.Пауза; //меняем изображение кнопки Play на паузу Player.Current = Player.Tracks.Find(track => track.FullName == url); //записываем текущий трек LikeButton.Image = Player.Current.IsLike ? Properties.Resources.Лайк : Properties.Resources.Дизлайк; WMPlayer.controls.play(); //включаем воспроизведение CoverBox.Image = Properties.Resources.cover; TagLib.File f = new TagLib.Mpeg.AudioFile(url); if (f.Tag.Pictures.Length > 0) { TagLib.IPicture pic = f.Tag.Pictures[0]; MemoryStream ms = new MemoryStream(pic.Data.Data); if (ms != null && ms.Length > 4096) { CoverBox.Image = Image.FromStream(ms).GetThumbnailImage(240, 240, null, IntPtr.Zero); } ms.Close(); } }
/// <summary> /// Saves <see cref="TagLib.IPicture"/> to the disk as file /// </summary> /// <param name="picture"></param> /// <param name="fileName"></param> /// <param name="fileMode"></param> public static void Save(this TagLib.IPicture picture, string fileName, FileMode fileMode = FileMode.OpenOrCreate) { using FileStream fs = new(fileName, fileMode); fs.Write(picture.Data.Data, 0, picture.Data.Data.Length); fs.Flush(); }
private void Forward_Click(object sender, RoutedEventArgs e) { playlist.SelectedIndex += 1; mediaElement.Stop(); mediaElement.Position = TimeSpan.FromSeconds(0); mediaElement.Source = new Uri(playlist.SelectedValue as string); mediaElement.Play(); TagLib.File tagFile = TagLib.File.Create(playlist.SelectedValue as string); MusicName.Content = tagFile.Tag.Title; ArtistName.Content = tagFile.Tag.FirstAlbumArtist; if (tagFile.Tag.Pictures != null && tagFile.Tag.Pictures.Length > 0) { TagLib.IPicture picture = tagFile.Tag.Pictures[0]; var sys = new System.IO.MemoryStream(picture.Data.Data); sys.Seek(0, System.IO.SeekOrigin.Begin); BitmapImage albumArt = new BitmapImage(); albumArt.BeginInit(); albumArt.StreamSource = sys; albumArt.EndInit(); Cover.Source = albumArt; } }
/// <summary> /// 获取本地MP3封面 /// </summary> /// <param name="path"></param> public static BitmapImage GetImageFromMp3(string path) { BitmapImage bitmap = null; TagLib.File file = TagLib.File.Create(path); var pics = file.Tag.Pictures; // Load you image data in MemoryStream if (pics != null && pics.Length > 0) { TagLib.IPicture pic = pics[0]; using (var stream = new MemoryStream(pic.Data.Data)) { stream.Seek(0, SeekOrigin.Begin); bitmap = new BitmapImage(); bitmap.BeginInit(); bitmap.CacheOption = BitmapCacheOption.OnLoad; bitmap.StreamSource = stream; bitmap.EndInit(); bitmap.Freeze(); } return(bitmap); } else { return(new BitmapImage(new Uri("pack://application:,,,/images/default_cover.jpg", UriKind.Absolute))); } }
/// <summary> /// /// </summary> public void SaveThumb() { StringBuilder sb = GetThumbPath(); if (sb == null) { return; } // 最も小さいものをサムネイルとして保存する int minDataSize = int.MaxValue; TagLib.IPicture targetPic = null; foreach (TagLib.IPicture pic in Tag.Pictures) { if (pic.Data.Count < minDataSize) { minDataSize = pic.Data.Count; targetPic = pic; } } if (targetPic == null) { return; } string strPath = sb.ToString(); if (!System.IO.Directory.Exists(ThumbFileDir)) { System.IO.Directory.CreateDirectory(ThumbFileDir); } System.IO.BinaryWriter bw = new System.IO.BinaryWriter(System.IO.File.Open(strPath, System.IO.FileMode.Create)); bw.Write(targetPic.Data.Data); bw.Close(); }
public BitmapImage GetAlbumImage(string path) { TagLib.File file = TagLib.File.Create(path); BitmapImage bitmap = new BitmapImage(new Uri("Images/default-album-artwork.png", UriKind.Relative)); if (file != null && file.Tag.Pictures.Length > 0) { // Load you image data in MemoryStream TagLib.IPicture pic = file.Tag.Pictures[0]; MemoryStream ms = new MemoryStream(pic.Data.Data); ms.Seek(0, SeekOrigin.Begin); // ImageSource for System.Windows.Controls.Image bitmap = new BitmapImage(); bitmap.BeginInit(); bitmap.StreamSource = ms; bitmap.DecodePixelHeight = 512; bitmap.DecodePixelWidth = 512; bitmap.EndInit(); } bitmap.Freeze(); return(bitmap); }
private void coverArtToolStripMenuItem_Click(object sender, EventArgs e) { try { TagLib.File f = TagLib.File.Create(OFD.FileNames[playlist]); TagLib.IPicture pic = f.Tag.Pictures[0]; MemoryStream ms = new MemoryStream(pic.Data.Data); ms.Seek(0, SeekOrigin.Begin); coverArt.Image = null; coverArt.Refresh(); coverArt.Image = Image.FromStream(ms); } catch { MessageBox.Show("There is no cover to set!", "Cover", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } switch (coverArt.Visible) { case false: coverArt.Visible = true; coverArtToolStripMenuItem.Text = "Hide cover art"; break; default: coverArt.Visible = false; coverArtToolStripMenuItem.Text = "Show cover art"; break; } }
/// <summary> /// set selected rating /// </summary> /// <param name="item">the item</param> private void SetSelectedPicture(TagLib.IPicture pic) { // select first pic //TagLib.IPicture pic = item.Tag as TagLib.IPicture; if (pic != null) { if (pic.MimeType.StartsWith("image/")) { byte[] data = new byte[pic.Data.Count]; pic.Data.CopyTo(data, 0); MemoryStream stream = null; try { stream = new MemoryStream(data); Image img = Image.FromStream(stream); pictureBox.Image = img; } catch (ArgumentException) { pictureBox.Image = null; } finally { if (stream != null) { stream.Close(); } } } } }
public void ApplyMetadata(string file, string[] metadata, bool save, bool setImage) { TagLib.File musicFile = TagLib.File.Create(file); musicFile.Tag.Title = metadata[0]; musicFile.Tag.Performers = new string[] { metadata[1] }; musicFile.Tag.Comment += metadata[2] + metadata[3]; if (setImage) { TagLib.IPicture[] pictures = new TagLib.IPicture[musicFile.Tag.Pictures.Length + 1]; try { for (int i = 1; i <= musicFile.Tag.Pictures.Length; i++) //add the pictures already present in the music file { pictures[i] = musicFile.Tag.Pictures[i - 1]; } pictures[0] = new TagLib.Picture(metadata[4]); musicFile.Tag.Pictures = pictures; } catch (Exception PictureException) { MessageBox.Show(String.Format("There was an issue setting the image. {0}", PictureException.Message), file); } } if (save) { musicFile.Save(); } }
private void descriptionSong(object s, RoutedEventArgs e) { Button bt = (Button)s; var res = from a in songs where a.Id == (int)bt.DataContext select a; Song so = res.ToList <Song>()[0]; var file = TagLib.File.Create(so.Path); TagLib.IPicture pic = file.Tag.Pictures[0]; MemoryStream ms = new MemoryStream(pic.Data.Data); ms.Seek(0, SeekOrigin.Begin); BitmapImage bitmap = new BitmapImage(); bitmap.BeginInit(); bitmap.StreamSource = ms; bitmap.EndInit(); des_title.Text = file.Tag.Title; des_Artist.Text = file.Tag.Artists[0]; des_duration.Text = file.Properties.Duration.Minutes + ":" + file.Properties.Duration.Seconds; des_genre.Text = file.Tag.Genres[0]; des_album.Text = file.Tag.Album; des_year.Text = "" + file.Tag.Year; des_image.Source = bitmap; }
private void ResetPictureBox() { TagLib.IPicture picture = ChosenObject as TagLib.IPicture; if (pictureBox1.Image != null) { pictureBox1.Image.Dispose(); } pictureBox1.Image = null; pictureBox1.ImageLocation = null; using (MemoryStream imageStream = new MemoryStream(picture.Data.Data, 0, picture.Data.Count)) try { var image = Image.FromStream(imageStream); if (imageRotation != RotateFlipType.RotateNoneFlipNone) { image.RotateFlip(imageRotation); } if (cropAlign == CropAlign.None && trimEdge == 0) { pictureBox1.Image = image; return; } var width = image.Width; var height = image.Height; var sz = Math.Min(width, height); Rectangle dstRect = cropAlign == CropAlign.None ? Rectangle.FromLTRB(0, 0, width - 2 * trimEdge, height - 2 * trimEdge) : Rectangle.FromLTRB(0, 0, sz - 2 * trimEdge, sz - 2 * trimEdge); Rectangle srcRect = cropAlign == CropAlign.None ? Rectangle.FromLTRB(trimEdge, trimEdge, width - trimEdge, height - trimEdge) : cropAlign == CropAlign.TopLeft ? Rectangle.FromLTRB(trimEdge, trimEdge, sz - trimEdge, sz - trimEdge) : //cropAlign == CropAlign.BottomRight ? Rectangle.FromLTRB(width - sz + trimEdge, height - sz + trimEdge, width - trimEdge, height - trimEdge); var mode = System.Drawing.Drawing2D.InterpolationMode.Default; if (dstRect.Width > config.maxAlbumArtSize || dstRect.Height > config.maxAlbumArtSize) { dstRect = cropAlign != CropAlign.None ? Rectangle.FromLTRB(0, 0, config.maxAlbumArtSize, config.maxAlbumArtSize) : width > height?Rectangle.FromLTRB(0, 0, config.maxAlbumArtSize, (height - 2 * trimEdge) *config.maxAlbumArtSize / (width - 2 * trimEdge)) : Rectangle.FromLTRB(0, 0, (width - 2 * trimEdge) * config.maxAlbumArtSize / (height - 2 * trimEdge), config.maxAlbumArtSize); mode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; } Bitmap b = new Bitmap(dstRect.Width, dstRect.Height); pictureBox1.Image = b; using (Graphics g = Graphics.FromImage((Image)b)) { g.InterpolationMode = mode; g.DrawImage(image, dstRect, srcRect, GraphicsUnit.Pixel); } image.Dispose(); } catch { } }
public BitmapImage LoadImage() { if (SelectedSongFile == null) { return(null); } try { var file = TagLib.File.Create(SelectedSong.Ref); TagLib.IPicture pic = file.Tag.Pictures[0]; MemoryStream ms = new MemoryStream(pic.Data.Data); ms.Seek(0, SeekOrigin.Begin); BitmapImage bitmap = new BitmapImage(); bitmap.BeginInit(); bitmap.StreamSource = ms; bitmap.EndInit(); return(bitmap); } catch (Exception ex) { if (ex is NotSupportedException || ex is IndexOutOfRangeException) { return(null); } } return(null); }
private void TrimMp3(string inputPath, string outputPath, TimeSpan start, TimeSpan end) { using (var reader = new Mp3FileReader(inputPath)) using (var writer = File.Create(outputPath)) { Mp3Frame frame; while ((frame = reader.ReadNextFrame()) != null) { if (reader.CurrentTime >= start) { if (reader.CurrentTime <= end) { writer.Write(frame.RawData, 0, frame.RawData.Length); } else { break; } } } } using (var inputTags = TagLib.File.Create(inputPath)) using (var outputTags = TagLib.File.Create(outputPath)) { inputTags.Tag.CopyTo(outputTags.Tag, true); var pictures = new TagLib.IPicture[inputTags.Tag.Pictures.Length]; inputTags.Tag.Pictures.CopyTo(pictures, 0); outputTags.Tag.Pictures = pictures; outputTags.Save(); } }
void InitSong() { FileInfo = TagLib.File.Create(MP3[Index]); Bar.Max = FileInfo.Properties.Duration.TotalSeconds; Name.Text = (FileInfo.Tag.Title != null) ? FileInfo.Tag.Title : " "; Artists.Text = (FileInfo.Tag.FirstAlbumArtist != null) ? FileInfo.Tag.FirstAlbumArtist : " "; Album.Text = (FileInfo.Tag.Album != null) ? FileInfo.Tag.Album : " "; Number.Text = (Index + 1).ToString() + "/" + MP3.Count.ToString(); mediaPlayer.Open(new Uri(MP3[Index], UriKind.Absolute)); Play.Text = "Pause"; mediaPlayer.Play(); bitmap = null; if (FileInfo.Tag.Pictures.Length != 0) { TagLib.IPicture pic = FileInfo.Tag.Pictures[0]; MemoryStream ms = new MemoryStream(pic.Data.Data); ms.Seek(0, SeekOrigin.Begin); bitmap = new BitmapImage(); bitmap.BeginInit(); bitmap.StreamSource = ms; bitmap.EndInit(); } img.Picture = bitmap; }
public Bitmap GetCoverFromFile() { try { if (IsFileExists()) { TagLib.File file = TagLib.File.Create(FilePath); TagLib.IPicture pic = file.Tag.Pictures.First(); return(Cover = new Bitmap(new MemoryStream(pic.Data.Data))); } } catch (TagLib.CorruptFileException) { try { File.Delete(FilePath); } catch { } } catch (Exception e) { throw e; } return(null); }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnExtract_Click(object sender, EventArgs e) { string art = string.Empty; byte[] data = null; TagLib.IPicture pic = GetSelectedPicture(); if (pic != null) { if (pic.MimeType.StartsWith("image/")) { art = "picture" + pic.MimeType.Replace("image/", "."); data = new byte[pic.Data.Count]; pic.Data.CopyTo(data, 0); } SaveFileDialog dlg = new SaveFileDialog(); dlg.OverwritePrompt = true; dlg.FileName = art; if (dlg.ShowDialog() == DialogResult.OK) { // write file to art location System.IO.File.WriteAllBytes(dlg.FileName, data); } } else { MessageBox.Show("No picture selected"); } }
void BrowseButton_Click(object sender, RoutedEventArgs e) { ImageSource Cover = null; string Title = null; string Artist = null; string Album = null; var screen = new Microsoft.Win32.OpenFileDialog(); screen.Filter = "Audio File|*.mp3;*.m4a"; screen.Multiselect = true; if (screen.ShowDialog() == true) { var filenames = screen.FileNames; browseButton.Visibility = Visibility.Hidden; BrowseListView.Visibility = Visibility.Visible; foreach (var filename in filenames) { TagLib.File file = TagLib.File.Create(filename); if (file.Tag.Pictures.Length >= 1) { TagLib.IPicture pic = file.Tag.Pictures[0]; System.IO.MemoryStream stream = new System.IO.MemoryStream(pic.Data.Data); BitmapFrame bmp = BitmapFrame.Create(stream); Cover = bmp; } else { BitmapImage bi = new BitmapImage(); bi.BeginInit(); bi.UriSource = new Uri("/Icon/disc.png", UriKind.Relative); bi.EndInit(); Cover = bi; } Title = file.Tag.Title; if (file.Tag.AlbumArtists.Length >= 1) { Artist = file.Tag.AlbumArtists[0].ToString(); } else { Artist = "Unknown"; } Album = file.Tag.Album; MainWindow._infoList.Add(new Info(Cover, Title, Artist, Album, filename)); } BrowseListView.ItemsSource = MainWindow._infoList; } }
public ActionResult GetCoverArt(int id) { MediaLibraryEntry entry = Index.GetEntry(id); bool originalIsFolder = entry.IsFolder; if (!originalIsFolder) { using (var id3File = TagLib.File.Create(entry.Path)) { TagLib.IPicture image = id3File.Tag.Pictures .OrderByDescending(i => i.Type == TagLib.PictureType.FrontCover) .FirstOrDefault(); if (image != null) { return(new FileContentResult(image.Data.Data, image.MimeType)); } } // Nothing in the MP3 file, so let's try to get an image from the parent folder entry = Index.GetFolder(entry.ParentId); } Debug.Assert(entry.IsFolder); FileInfo file = new DirectoryInfo(entry.Path) .EnumerateFiles("*.jpg") .FirstOrDefault(); if (file == null) { // If the request was for a folder and there is no image file, // try to find an image in the MP3 files if (originalIsFolder) { entry = Index.GetChildFiles(entry.Id) .FirstOrDefault(); using (var id3File = TagLib.File.Create(entry.Path)) { TagLib.IPicture image = id3File.Tag.Pictures .OrderByDescending(i => i.Type == TagLib.PictureType.FrontCover) .FirstOrDefault(); if (image != null) { return(new FileContentResult(image.Data.Data, image.MimeType)); } } // Nothing in the MP3 file either } return(new FileContentResult(Array.Empty <byte>(), "image/jpeg")); } return(new FileStreamResult(file.OpenRead(), "image/jpeg")); }
private void listChoices_SelectedIndexChanged(object sender, EventArgs e) { object item = ChosenObject; if (item != null && item is TagLib.IPicture) { TagLib.IPicture picture = item as TagLib.IPicture; using (MemoryStream imageStream = new MemoryStream(picture.Data.Data, 0, picture.Data.Count)) try { pictureBox1.Image = Image.FromStream(imageStream); } catch { } textBox1.Hide(); pictureBox1.Show(); tableLayoutPanelMeta.Hide(); tableLayoutPanel1.SetRowSpan(pictureBox1, 2); } else if (item != null && item is CUEToolsSourceFile) { textBox1.Text = (item as CUEToolsSourceFile).contents.Replace("\r\n", "\n").Replace("\r", "\n").Replace("\n", "\r\n"); } else if (item != null && item is CUEMetadataEntry) { CUEMetadataEntry r = (item as CUEMetadataEntry); dataGridViewTracks.SuspendLayout(); dataGridViewTracks.Rows.Clear(); foreach (CUETrackMetadata track in r.metadata.Tracks) { int no = dataGridViewTracks.Rows.Count; dataGridViewTracks.Rows.Add( (no + 1).ToString(), track.Title, r.TOC[no + r.TOC.FirstAudio].StartMSF, r.TOC[no + r.TOC.FirstAudio].LengthMSF ); } dataGridViewTracks.ResumeLayout(); dataGridViewMetadata.Rows.Clear(); dataGridViewMetadata.Rows.Add("Artist", r.metadata.Artist); dataGridViewMetadata.Rows.Add("Album", r.metadata.Title); dataGridViewMetadata.Rows.Add("Date", r.metadata.Year); dataGridViewMetadata.Rows.Add("Genre", r.metadata.Genre); dataGridViewMetadata.Rows.Add("Disc Number", r.metadata.DiscNumber); dataGridViewMetadata.Rows.Add("Total Discs", r.metadata.TotalDiscs); dataGridViewMetadata.Rows.Add("Disc Name", r.metadata.DiscName); dataGridViewMetadata.Rows.Add("Label", r.metadata.Label); dataGridViewMetadata.Rows.Add("Label#", r.metadata.LabelNo); dataGridViewMetadata.Rows.Add("Country", r.metadata.Country); dataGridViewMetadata.Rows.Add("Release Date", r.metadata.ReleaseDate); dataGridViewMetadata.Rows.Add("Barcode", r.metadata.Barcode); dataGridViewMetadata.Rows.Add("Comment", r.metadata.Comment); } else { dataGridViewMetadata.Rows.Clear(); dataGridViewTracks.Rows.Clear(); textBox1.Text = ""; } }
private void Check_PropertyChanged(object sender, PropertyChangedEventArgs e) { TagLib.File file = TagLib.File.Create(MainWindow.GetNowPlaying()); if (file.Tag.Pictures.Length >= 1) { TagLib.IPicture pic = file.Tag.Pictures[0]; System.IO.MemoryStream stream = new System.IO.MemoryStream(pic.Data.Data); BitmapFrame bmp = BitmapFrame.Create(stream); cover.Source = bmp; } else { BitmapImage bi = new BitmapImage(); bi.BeginInit(); bi.UriSource = new Uri("/Icon/disc.png", UriKind.Relative); bi.EndInit(); cover.Source = bi; } string title = file.Tag.Title; Title.Text = title; if (file.Tag.AlbumArtists.Length >= 1) { string[] artist = file.Tag.AlbumArtists; Artist.Text = "Artist \t" + artist[0].ToString(); } else { Artist.Text = "Artist \t" + "Unknown"; } string album = file.Tag.Album; Album.Text = "Album \t" + album; if (file.Tag.Genres.Length >= 1) { string[] genre = file.Tag.Genres; Genre.Text = "Genre \t" + genre[0].ToString(); } else { Genre.Text = "Genre \t" + "Unknown"; } if (file.Tag.Year != 0) { uint year = file.Tag.Year; Year.Text = "Year \t" + year.ToString(); } else { Year.Text = "Year \t" + "Unknown"; } }
/// <summary> /// generate file name for picture /// </summary> /// <param name="pic"></param> /// <returns></returns> private string GenerateFileName(TagLib.IPicture pic) { Guid guid = Guid.NewGuid(); string exp = @"[\w\\]*(?<ext>(jpg)|(jpeg)|(png)|(gif)|(bmp))"; Regex regex = new Regex(exp, RegexOptions.IgnoreCase); Match m = regex.Match(pic.MimeType); string ext = m.Groups["ext"].Value.ToLower(); // name blank mime_type jpg extension ext = ext == string.Empty ? "jpg" : ext; return(guid.ToString("B") + "." + ext); }
public static void GenerateImageOverlay(string currentSong, string nextSong) { string SONG_NAME = "SONG NAME"; string ARTIST_NAME = "ARTIST NAME"; string NEXT_SONG_STRING = ""; TagLib.File currentSongFile = TagLib.File.Create(currentSong); TagLib.File nextSongFile = TagLib.File.Create(nextSong); if (currentSongFile.Tag.Title != null) { SONG_NAME = currentSongFile.Tag.Title; } if (currentSongFile.Tag.AlbumArtists.Length > 0) { ARTIST_NAME = currentSongFile.Tag.AlbumArtists[0]; } Image returnImage; if (currentSongFile.Tag.Pictures.Length != 0) { TagLib.IPicture albumPicture = currentSongFile.Tag.Pictures[0]; //filepath is audio file location MemoryStream memStream = new MemoryStream(albumPicture.Data.Data); //creates image in memory stream returnImage = Image.FromStream(memStream); } else { returnImage = null; } if (nextSongFile.Tag.AlbumArtists.Length > 0) { NEXT_SONG_STRING = nextSongFile.Tag.AlbumArtists[0] + " - "; } else { NEXT_SONG_STRING = "SONG ARTIST - "; } if (nextSongFile.Tag.Title != null) { NEXT_SONG_STRING += nextSongFile.Tag.Title; } else { NEXT_SONG_STRING += "SONG NAME"; } ImageGenerator(returnImage, SONG_NAME, ARTIST_NAME, NEXT_SONG_STRING); }
void setCoverArt() { try { TagLib.File f = TagLib.File.Create(OFD.FileNames[playlist]); TagLib.IPicture pic = f.Tag.Pictures[0]; MemoryStream ms = new MemoryStream(pic.Data.Data); ms.Seek(0, SeekOrigin.Begin); coverArt.Image = Image.FromStream(ms); coverArt.Refresh(); } catch { } }
public static Image GetCover(string MusicPath) { try { TagLib.IPicture pic = TagLib.File.Create(MusicPath).Tag.Pictures[0]; //pic contains data for image. MemoryStream stream = new MemoryStream(pic.Data.Data); // create an image in memory stream return(new Bitmap(stream)); } catch { return(Properties.Resources.MusicTon); } }
public BitmapImage IpicToBitmap(TagLib.IPicture pic) { using (MemoryStream ms = new MemoryStream(pic.Data.Data)) { BitmapImage bitmap = new BitmapImage(); ms.Seek(0, SeekOrigin.Begin); bitmap.BeginInit(); bitmap.CacheOption = BitmapCacheOption.OnLoad; bitmap.StreamSource = ms; bitmap.EndInit(); return(bitmap); } }
/// <summary> /// Update the comment frame /// </summary> private void UpdatePictureFrames(TagListViewItem item) { //BKP use IPicture ? if (this.pictures_dirty) { TagLib.IPicture[] pics = new TagLib.IPicture[pictureList.Items.Count]; int len = pictureList.Items.Count; for (int i = 0; i < len; ++i) { TagLib.IPicture p = pictureList.Items[i].Tag as TagLib.IPicture; pics[i] = p; } item.MetaTag.Pictures = pics; } }
private void PlaylistAdd_Click(object sender, RoutedEventArgs e) { Microsoft.Win32.OpenFileDialog openDialog = new Microsoft.Win32.OpenFileDialog(); openDialog.Filter = "MP3 files (*.mp3)|*.mp3|All files (*.*)|(*.*)"; openDialog.Multiselect = true; Nullable <bool> result = openDialog.ShowDialog(); if (result == true) { var file = openDialog.FileName; mediaElement.Source = new Uri(file); TagLib.File tagFile = TagLib.File.Create(file); Musics = new List <MusicClass> { new MusicClass { Title = tagFile.Tag.Title, Artist = tagFile.Tag.FirstAlbumArtist, MusicURI = file } }; playlist.Items.Add(Musics); playlist.SelectedIndex += 1; mediaElement.Play(); Play.Content = FindResource("PauseButton"); Play.IsEnabled = true; Stop.IsEnabled = true; MusicName.Content = tagFile.Tag.Title; ArtistName.Content = tagFile.Tag.FirstAlbumArtist; if (tagFile.Tag.Pictures != null && tagFile.Tag.Pictures.Length > 0) { TagLib.IPicture picture = tagFile.Tag.Pictures[0]; var sys = new System.IO.MemoryStream(picture.Data.Data); sys.Seek(0, System.IO.SeekOrigin.Begin); BitmapImage albumArt = new BitmapImage(); albumArt.BeginInit(); albumArt.StreamSource = sys; albumArt.EndInit(); Cover.Source = albumArt; } } }
public LocalMedia(String path, TagLib.File file) : base(path) { this.Author = file.Tag.Performers.FirstOrDefault(); this.Title = String.IsNullOrWhiteSpace(file.Tag.Title) ? Path.GetFileNameWithoutExtension(file.Name) : file.Tag.Title; this.Duration = file.Properties.Duration; this.Description = file.Tag.Comment; this.Album = file.Tag.Album; TagLib.IPicture cover = file.Tag.Pictures.FirstOrDefault(p => p.Type == TagLib.PictureType.FrontCover) ?? file.Tag.Pictures.FirstOrDefault(); if (cover?.Data?.Data != null) { using (MemoryStream ms = new MemoryStream(cover.Data.Data)) this.SetBitmapImage(stream: ms); } }
private void AddItem(object i) { if (i is CUEToolsSourceFile) { CUEToolsSourceFile sf = i as CUEToolsSourceFile; ListViewItem item = new ListViewItem(sf.path, 0); item.Tag = sf; listChoices.Items.Add(item); } else if (i is TagLib.IPicture) { TagLib.IPicture pic = i as TagLib.IPicture; ListViewItem item = new ListViewItem(pic.Description, -1); item.Tag = pic; listChoices.Items.Add(item); } else if (i is CUEMetadataEntry) { CUEMetadataEntry entry = i as CUEMetadataEntry; ListViewItem item = new ListViewItem(entry.ToString(), entry.ImageKey); item.Tag = entry; listChoices.Items.Add(item); if (entry.ImageKey == "freedb") { // check if the entry contains non-iso characters, // and add a second one if it does CUEMetadata copy = new CUEMetadata(entry.metadata); if (copy.FreedbToEncoding()) { entry = new CUEMetadataEntry(copy, entry.TOC, entry.ImageKey); item = new ListViewItem(entry.ToString(), entry.ImageKey); item.Tag = entry; listChoices.Items.Add(item); } } } else { ListViewItem item = new ListViewItem(i.ToString(), -1); item.Tag = i; listChoices.Items.Add(item); } }
/// <summary> /// get the first front cover or the first picture /// </summary> /// <param name="tag"></param> /// <returns></returns> public TagLib.IPicture FindDefaultPicture(TagLib.Tag tag) { if (tag.Pictures.Length < 1) { return(null); } TagLib.IPicture pic = tag.Pictures[0]; // find the first front cover image, if not use first image foreach (TagLib.IPicture p in tag.Pictures) { if (p.Type == TagLib.PictureType.FrontCover && p.MimeType != "-->") { pic = p; break; } } return(pic); }
private bool addcoverart(string audiopath,string picturepath) { try { TagLib.File TagLibFile = TagLib.File.Create(audiopath); TagLib.Picture picture = new TagLib.Picture(picturepath); TagLib.Id3v2.AttachedPictureFrame albumCoverPictFrame = new TagLib.Id3v2.AttachedPictureFrame(picture); albumCoverPictFrame.MimeType = System.Net.Mime.MediaTypeNames.Image.Jpeg; albumCoverPictFrame.Type = TagLib.PictureType.FrontCover; TagLib.IPicture[] pictFrames = new TagLib.IPicture[1]; pictFrames[0] = (TagLib.IPicture)albumCoverPictFrame; TagLibFile.Tag.Pictures = pictFrames; TagLibFile.Save(); } catch { return false; } return true; }