Example #1
0
        void FillMetadataBagStub(FileInformation fileInfo, ConcurrentBag <MediaMetadata> bag)
        {
            // Prep metadata and cover.
            IRandomAccessStreamWithContentType stream = null;

            try
            {
                IMediaInfo info;
                // Workaround for mojibake in id3v2 tags: use system code page.
                if (string.Compare(fileInfo.FileType, ".mp3", true) == 0)
                {
                    var        fInfo = MusicPropertiesMediaInfo.Create(fileInfo.MusicProperties);
                    IMediaInfo extraInfo;
                    using (stream = fileInfo.OpenReadAsync().AsTask().Result)
                    {
                        var result =
                            NativeMethods.GetMediaInfoFromStream(stream, out extraInfo);
                    }
                    fInfo.TrackNumber   = extraInfo.TrackNumber;
                    fInfo.TotalTracks   = extraInfo.TotalTracks;
                    fInfo.DiscNumber    = extraInfo.DiscNumber;
                    fInfo.TotalDiscs    = extraInfo.TotalDiscs;
                    fInfo.Date          = extraInfo.Date;
                    fInfo.Genre         = extraInfo.Genre;
                    fInfo.AllProperties = extraInfo.AllProperties;
                    info = fInfo;
                }
                else
                {
                    using (stream = fileInfo.OpenReadAsync().AsTask().Result)
                    {
                        var result =
                            NativeMethods.GetMediaInfoFromStream(stream, out info);
                    }
                }
                // Ignore all entities with empty title field.
                if (string.IsNullOrEmpty(info?.Title))
                {
                    return;
                }
                bag.Add(new MediaMetadata(info, fileInfo.Path, fileInfo.BasicProperties.DateModified));
            }
            catch (Exception ex)
            {
                // TODO: Handle exceptions
                Debug.WriteLine(ex);
            }
        }
 private async void SetSourceAsync(BitmapImage bi, FileInformation fi)
 {
     try
     {
         using (var stream = await fi.OpenReadAsync())
         {
             await bi.SetSourceAsync(stream);
         }
     }
     catch
     {
         // ignore failure
     }
 }