Microsoft has been saying that the Music and Video Hub will be extendable on Windows Phone 7. But so far, it has been fairly unknown what this extension means and how one would go around to implement it.
I was lead to the right path by reading the new Windows Phone Marketplace policies document. It has an entire section dedicated to policies regarding a Music + Video Hub application, and states, that “An Application that calls the Microsoft.Devices.MediaHistory or Microsoft.Devices.MediaHistoryItem” classes is considered a Music + Video hub application”. So, let’s see what these classes do!
Note: to access the Music + Video hub on the emulator, you will have to use the “Unlocked emulator” floating around. See my Windows Phone 7 emulator tips and tricks article on the subject.
As the name suggests, the MediaHistory class is essentially the history of media items played on the phone. The MediaHistoryItem class holds the items that the MediaHistory cares about.
To see these classes in action, we have to create a custom media player application. Our at least something that pretends it is a media player. Let’s start by creating a new Windows Phone List Application project, called “MusicVideoHub”:
I assume you are familiar with this project template – it essentially contains of a list of items, and a detail page which is shown when one of the items is tapped on. In this exploratory app, we are going to pretend that the details pages are actually media pages that play back the selected item.
To do so, add the following to the OnNavigatedTo event handler of the DetailsPage.xaml.cs file:
//create a snapshot of the page title
WriteableBitmap wb = new WriteableBitmap(ListTitle, null);
MemoryStream stream = new MemoryStream();
wb.SaveJpeg(stream, 173, 173, 0, 90);
//create the media history item
var mediaHistoryItem = new MediaHistoryItem
Title = ListTitle.Text,
Source = "Test Source",
ImageStream = stream
//Set the now playing to the item
MediaHistory.Instance.NowPlaying = mediaHistoryItem;
//add to the history
You can see that the code is very straightforward. The only thing worth noting is that it creates a (distorted) snapshot of the Title textblock (contains text like “runtime five, etc”, and posts that as the album art.
Now if you run the app, and select “runtime six” and then “runtime five”, this is what you will see on the Music + Video hub:
Which shows the currently playing track (set by the NowPlaying property). Note, that the Title is written over the album art, and so is the text “paused”. The album art is also made a little bit darker, so that the white text is readable upon it. Scrolling a little bit to the right, you can see this:
This is the history, showing “runtime five” as the last and “runtime six” as the previous history entry.
You can also use your application to purchase new music or video content from your own store. If you do that, the newly purchased content can also be added to the Music + Video hub by using the MediaHistory.Instance.WriteAcquiredItem method.
If you tap on any of these history tiles, you will be taken back to your application, which created the tile. However, there is some missing functionality (or functionality that I was unable to find – let me know if you know the solution):
- If your application is activated from the Music + Video hub instead of the Start page or the application list, the user expects to see a page related to the history or newly purchased item he / she tapped on. However, I didn’t find a way to detect this – the LaunchingEventArgs class is empty, and the NowPlaying property is not set either.
- the Now Playing always shows up as paused – I would like to be able to notify the OS of its state, and learn how I can actually play back media here.
I assume that these problems will be solved in a few weeks, when the final WP7 SDK arrives. After all, there must be a reason why I had to unlock the emulator to see the Music + Video hub – probably these features were not ready when the Beta SDK was released. I am curious to see what the real extent of Music + Video integration turns out to be.
Aug 24 2010, 04:00 PM