private void 进度条_ValueChanged(object sender, RoutedPropertyChangedEventArgs <double> e) { if (button == 1) { 播放时间.Content = Function_list.sec_to_hms(进度条.Value).Substring(3, 5) + "-" + Song_time; } }
/// <summary> /// 读取专辑图片 /// 有些图片格式不支持会导致NET框架内部出错,会自动将图片转换为.png格式的图片文件 /// </summary> /// <param name="path">歌曲路径</param> /// <returns></returns> public static BitmapImage GetCover(string path) { BitmapImage bmp = new BitmapImage(); TagLib.File f = TagLib.File.Create(path); try { if (f.Tag.Pictures != null && f.Tag.Pictures.Length != 0) { //字节流转BitmapImage对象 bmp.BeginInit(); bmp.StreamSource = new MemoryStream(f.Tag.Pictures[0].Data.Data); bmp.EndInit(); return(bmp);//返回图片对象 } } catch //(Exception ex)如果图片格式不支持 { FileStream fs = null; try {//将图片写入到新的路径 fs = new FileStream(System.IO.Path.GetTempPath() + "临时文件.png", FileMode.Create, FileAccess.Write); fs.Write(f.Tag.Pictures[0].Data.Data, 0, f.Tag.Pictures[0].Data.Data.Length); } catch { } finally { fs.Close();//释放文件句柄 fs.Dispose(); }//图片格式转换 System.Drawing.Image Dummy = System.Drawing.Image.FromFile(System.IO.Path.GetTempPath() + "临时文件.png"); Dummy.Save(System.IO.Path.GetDirectoryName(path) + @"\" + System.IO.Path.GetFileNameWithoutExtension(path) + ".png", System.Drawing.Imaging.ImageFormat.Bmp); bmp = Function_list.Album_pictures(System.IO.Path.GetDirectoryName(path) + @"\" + System.IO.Path.GetFileNameWithoutExtension(path) + ".png"); Dummy.Dispose(); System.IO.File.Delete(System.IO.Path.GetDirectoryName(path) + @"\" + System.IO.Path.GetFileNameWithoutExtension(path) + ".png"); System.IO.File.Delete(System.IO.Path.GetTempPath() + "临时文件.png"); return(bmp);//返回图片对象 } return(null); }