Dotneteers.net
All for .net, .net for all!

Extending the Music + Video Hub on Windows Phone 7

VBandi's blog

Syndication

Subscribe

Generic Content

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”:

image

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);
            stream.Seek(0, SeekOrigin.Begin);

            //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;
            stream.Seek(0, SeekOrigin.Begin);

            //add to the history
            MediaHistory.Instance.WriteRecentPlay(mediaHistoryItem);

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:

image

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:

image

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.


Posted Aug 24 2010, 04:00 PM by vbandi
Filed under:

Comments

Sneak peek at 3rd party music and video hub extension in Windows Phone 7 wrote Sneak peek at 3rd party music and video hub extension in Windows Phone 7
on Tue, Aug 24 2010 23:08

Pingback from  Sneak peek at  3rd party music and video hub extension in Windows Phone 7

Desenvolvedores: sim! É possível estender o hub Music + Video | Windows Phone Blog Brasil wrote Desenvolvedores: sim! É possível estender o hub Music + Video | Windows Phone Blog Brasil
on Wed, Aug 25 2010 2:05

Pingback from  Desenvolvedores: sim! É possível estender o hub Music + Video | Windows Phone Blog Brasil

TrackBack wrote Twitter Trackbacks
on Thu, Aug 26 2010 6:35
Alberto Silva wrote Windows Phone 7–Experiência para programadores, XXXV
on Sun, Aug 29 2010 21:17

Depois de uns dias fora com a família, o volume de links para artigos relacionados com o desenvolvimento

LIFE IN MOTION wrote Eigene WP7-Apps in den Musik & Video-Hub integrieren
on Wed, Sep 1 2010 15:49

Wer bereits an Apps für WP7 arbeitet, die irgend etwas mit Musik, Podcasts, Videos o.ä. zu tun haben

WP7 – Music and Video hub Integration (Zune) « wp.lyalin.com – WP7 Application Center wrote WP7 – Music and Video hub Integration (Zune) « wp.lyalin.com – WP7 Application Center
on Wed, Oct 6 2010 22:43

Pingback from  WP7 – Music and Video hub Integration (Zune) « wp.lyalin.com – WP7 Application Center

Oleksandr Krakovetskiy blog wrote Дайджест технических материалов #5 (Windows Phone 7)
on Wed, Oct 27 2010 13:24

Tools, Books, Guides Windows Phone 7 Developer Tools RTM (online installer) , ISO UI Design and Interaction

Laurent Duveau wrote re: Extending the Music + Video Hub on Windows Phone 7
on Wed, Dec 1 2010 4:39

Thanks, that helps!!!

????????? beta??? » Windows Phone 7 ???????????????????????? wrote ????????? beta??? » Windows Phone 7 ????????????????????????
on Tue, Jun 21 2011 18:35

Pingback from  ????????? beta??? » Windows Phone 7 ????????????????????????

Para desenvolvedores: Sim! ?? poss??vel estender o Music + Video Hub – Windows Phone Brasil wrote Para desenvolvedores: Sim! ?? poss??vel estender o Music + Video Hub – Windows Phone Brasil
on Sun, Feb 5 2012 21:34

Pingback from  Para desenvolvedores: Sim! ?? poss??vel estender o Music + Video Hub  –  Windows Phone Brasil

Extend dotnet | Alldigiphoto wrote Extend dotnet | Alldigiphoto
on Sat, Apr 28 2012 7:46

Pingback from  Extend dotnet | Alldigiphoto

Windows Phone 7 ???????????? | DanceCoder wrote Windows Phone 7 ???????????? | DanceCoder
on Fri, May 18 2012 5:16

Pingback from  Windows Phone 7 ???????????? | DanceCoder

rimonabantexcellence site title wrote rimonabantexcellence site title
on Wed, Jul 17 2013 6:15

Pingback from  rimonabantexcellence site title