Dmitry Lyalin's Applications for Windows Phone 7

Archive for October, 2010

MediaHistory, WriteableBitmap and the {"partial read?"} Exception in WP7

If your application is integrating with the Media and Video hub in Windows Phone 7 then you should be aware of the “partial read” exception, let me explain:

Problem – “Partial read” exception

Media and Video hub integration allows you to write Recent, New and playing items from your media application directly into the hub, the way you do this is through the MediaHistory class. One of its properties is an image from a Stream called “ImageStream” that you can create an image (using WriteablBitmap) or load an image from some data source.

This passed image displays in the Media and Video hub to identify the content you passed in and does work. But here is the trick if you pass the stream in incorrectly you’ll get the Partial Read exception.


I am not sure of all the things that can cause the same exception but in my case the “stream” I was passing was not at Position 0 (or a valid position on where your Image is in the stream). By default things like WriteableBitmap place the position to end-of-file so that’s where I got killed :(.

So lessons learned, if you attempt to write to the Now Playing, Recently Played or Acquired items list make sure your image’s stream is at a valid position, don’t assume it will reset the position for you or you’ll see this exception.


WP7 – Music and Video hub Integration (Zune)

One of the very neat features in Windows Phone 7 is the ability to integrate with the Music and Video hub (basically the Zune experience on the phone).

As a developer you can write code to add items to the “now playing” or “history” lists. Also as a nice bonus once your application will be listed in the Marquee section!

MSDN already has one good article describing how to accomplish this:

How to: Integrate with the Music and Videos Hub for Windows Phone

Unfortunately it seems one missing piece of documentation (as of today 10/6/2010 at least) is how to get the right values inside of your application when the Music Hub re-launches it for a particular “now playing” or “history” item click. Update: The documentation has been updated to reflect how to get the values passed in!


This question was answered in our Windows Phone 7 forum, see here. This forum post describes the following steps needed to re-capture this info:

  • Your application will have a certain “Page” that will be the first page Navigated to when the app starts. In my app its MainPage.xaml
  • In that page add an override of the OnNavigatedTo method
  • In the OnNavigatedTo method read the QueryString to get the same key/value pair which I passed in originally as the PlayerContext.

That’s should be it, you are all set.

Bonus Tip: Just don’t forget to update your WMAppManifest.xaml to include HubType=”1” or this integration code wont be able to execute and you’ll get some unfriendly exceptions.

Related Links:

  • Check out András Velvárt’s (Microsoft MVP) article on this same topic.

Sliders and Progress bars in WP7

Two key controls in Windows Phone 7 are Sliders and Progress bars. Unfortunately both controls that ship with Windows Phone 7 developer tools RTM (for now) are not perfect and can lead to performance problems (as with ProgressBar control) or incorrect visualization of thumbnail (as with the case for Slider control).

Luckily there are solutions, two great blog posts with samples are available from Microsoft employees that provide the fix until the official templates are improved, here they are:

I use both in my WP7 TWiT app and owe these guys a lot of thanks, their work and postings solve real problems for me id have to deal with otherwise.