private Encoding DetectEncodingFromFile()
        {
            using (FileStream DetectStream = TextFile.GetFileStreamFromFile(AccessMode.Read))
                using (StreamReader Reader = new StreamReader(DetectStream, Encoding.Default, true))
                {
                    Reader.Read();

                    return(Reader.CurrentEncoding);
                }
        }
示例#2
0
        /// <summary>
        /// 异步获取音乐封面
        /// </summary>
        /// <returns>艺术家名称</returns>
        private async Task <BitmapImage> GetMusicCoverAsync()
        {
            try
            {
                using (FileStream FileStream = MediaFile.GetFileStreamFromFile(AccessMode.Read))
                    using (var TagFile = TagLib.File.Create(new StreamFileAbstraction(MediaFile.Name, FileStream, FileStream)))
                    {
                        if (TagFile.Tag.Pictures != null && TagFile.Tag.Pictures.Length != 0)
                        {
                            var ImageData = TagFile.Tag.Pictures[0].Data.Data;

                            if (ImageData != null && ImageData.Length != 0)
                            {
                                using (MemoryStream ImageStream = new MemoryStream(ImageData))
                                {
                                    BitmapImage bitmap = new BitmapImage
                                    {
                                        DecodePixelHeight = 250,
                                        DecodePixelWidth  = 250
                                    };
                                    await bitmap.SetSourceAsync(ImageStream.AsRandomAccessStream());

                                    return(bitmap);
                                }
                            }
                            else
                            {
                                return(null);
                            }
                        }
                        else
                        {
                            return(null);
                        }
                    }
            }
            catch
            {
                return(null);
            }
        }