Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Good morning everyone,

I recently started playing around with Metro Apps. I came up with a tiny music player. Unfortunately there is one problem.

I've the following code:

C#
private static readonly object Locker = new object();
private static volatile BitmapImage _defaultCover;
 
private BitmapImage _cover;
public BitmapImage CoverArt 
{
  get { return _cover ?? _defaultCover; }
  set { SetProperty( ref _cover, value ); }
}

private async Task LoadThumbnailAsync( StorageFile file )
{
  if ( file == null )
  {
    return;
  }
 
  var thumb = await file.GetThumbnailAsync( ThumbnailMode.MusicView, 192, ThumbnailOptions.UseCurrentScale );
  if ( thumb.Type == ThumbnailType.Image )
  {
    var cover = new BitmapImage();
    cover.SetSource( thumb );
    CoverArt = cover;
    return;
  }
 
  if ( CoverArt == null )
  {
    lock ( Locker )
    {
      if ( CoverArt == null )
      {
        // some Bitmap manipulation here...
        InMemoryRandomAccessStream memStream = ...
        ...
        
        var cover = new BitmapImage();
        cover.SetSource( memStream );
         _defaultCover = cover;
        OnPropertyChanged( "CoverArt" );
      }
    }
  }
}


So, just in short. I'm loading the built-in cover art of some mp3s. If there's no picture I want to display a custom bitmap, that's the singleton. However, all image controls which are displaying the singleton are flickering while the audio collection is still loading (the other thumbnails are generated).

I tried already skipping the InMemoryRandomAccessStream part and just load a default png from the project folder - the result is the same. To be honest I don't have clue what's causing this behavior. Maybe someone can help me?

Thanks in advance.
Posted

1 solution

I also have this problem. In my case I am receiving data from a WiFi webcam.
I have managed to improve it quite a bit by replacing a blocking network call for the async version, but the image still flickers like crazy.
My networking call and bitmap generation only take around 5 milliseconds total, and the Webcam is only putting out 30 fps 640x480 MJPEG at up to 7 Mbits/sec, so I can't see any problem there.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900