{//转换歌曲路径为BitmapImage专辑图片 public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (value == null) { return(null); } SongInfo sInfo = (value as SongInfoExpend).SongInfo; if (sInfo.SongType == 3) { string path = OsuLocalDataGeter.LoadOsuFileNameAs(1, sInfo.OsuPath); if (System.IO.File.Exists(path)) { return(new BitmapImage(new Uri(path, UriKind.Absolute))); } } var result = new MusicTag().GetJPGFromStream(sInfo); if (result == null) { return(new BitmapImage(new Uri("./Resource/未找到专辑图片.jpg", UriKind.Relative))); } return(result); }
public Task <byte[]> GetCurrentMusicFileJPGBufferAsync(SongInfo song, bool ShouldReset = false) { if (ShouldReset || GetCurMusicFileJPGBufferTask == null || GetCurMusicFileJPGBufferTask.Result == null) { GetCurMusicFileJPGBufferTask = Task.Run <byte[]>(() => { if (song.SongType == 3) { var osubgPath = OsuLocalDataGeter.LoadOsuFileNameAs(1, song.OsuPath); if (osubgPath == "") { return(null); } return(File.ReadAllBytes(OsuLocalDataGeter.LoadOsuFileNameAs(1, song.OsuPath))); } else { return(GetJPGBuffer(song)); } }); } return(GetCurMusicFileJPGBufferTask); }
public Task <Color> GetCurrentColorAsync(SongInfo song, bool ResetClor = false, bool ResetAll = false) { if (ResetAll || ResetClor || GetCurrentColorTask == null) { GetCurrentColorTask = Task.Run <Color>(() => { Color MajorColor; if (song.SongType == 3) { try { var src = new Bitmap(OsuLocalDataGeter.LoadOsuFileNameAs(1, song.OsuPath)); //会出现不合法地址的情况,待改。 MajorColor = GetMajorColor(src); src.Dispose(); } catch { Debug.Print("加载OSU背景图片失败"); MajorColor = Color.Black; } } else { GetCurrentMusicFileJPGBufferAsync(song, ResetAll).Wait(); if (GetCurMusicFileJPGBufferTask.Result == null) { return(Color.Black); } Bitmap sorc = GetBitmapFromBuffer( GetCurMusicFileJPGBufferTask.Result); MajorColor = GetMajorColor(sorc); sorc.Dispose(); } return(MajorColor); }); } return(GetCurrentColorTask); }