Play Media files with the MediaPlayerLauncher in Windows Phone 7

The Windows Phone SDK provides the MediaPlayerLauncher which allows the developers to play video or music in the WP7 App .

The MediaPlayerLauncher defined in the namespace “Microsoft.Phone.Tasks” will launch the Media Player and plays the Media file specified .

The Media files are stored to the Isolated Storage when saved to the disk or stored to the APplication installation directory if bundled with the xap file .

Using the MediaPlayerLauncher is simple .

Just create an instance of the MediaPlayerLauncher and set the properties like Media , Location and Controls and Call the Show Method of the MediaPlayerLauncher .

 

MediaPlayerLauncher objMediaPlayerLauncher = new MediaPlayerLauncher();
objMediaPlayerLauncher.Media = new Uri("test.mp3", UriKind.Relative);
objMediaPlayerLauncher.Location = MediaLocationType.Install;
objMediaPlayerLauncher.Controls = MediaPlaybackControls.Pause | MediaPlaybackControls.Stop | MediaPlaybackControls.All;
objMediaPlayerLauncher.Orientation = MediaPlayerOrientation.Landscape;
objMediaPlayerLauncher.Show();

It is also necessary to specify the Location which is a MediaLocationType Enumeration  .

The MediaLocationType enumeration lists the data stores in which the media file will be stored .

  • MediaLocationType.None indicates that the media item is in neither data store and when a Show Method is called with this Option , you might get the FileNotFoundException .
  • MediaLocationType.Install indicates that the Media file is in the Application’s installation directory . In the above example , the test.mp3 is packages with the xap file , so this option is needed .
  • MediaLocationType.Data indicates that the Media file is in the isolated storage

It is also possible to indicate the different controls that should be displayed by the Media Player Application which is defined via the Enum MediaPlaybackControls which includes All , FastForward , Pause , None , Rewind , Skip , Stop .

Also note the difference when you include “objMediaPlayerLauncher.Orientation” in WP7 App ,

you should get the error

“Error 1 ‘Microsoft.Phone.Tasks.MediaPlayerLauncher’ does not contain a definition for ‘Orientation’ and no extension method ‘Orientation’ accepting a first argument of type ‘Microsoft.Phone.Tasks.MediaPlayerLauncher’ could be found (are you missing a using directive or an assembly reference?”

 

But when you include the same in WP7.1 Beta SDK , it should work .

Also as per the MSDN , the application can start the media player and the user can play music, but video is not rendered .

If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.

6 Comments

  1. Bent Elo Christiansen June 24, 2011 Reply
  2. Play Media files with the MediaPlayerLauncher in Windows Phone 7 | ProgramInDotnet August 1, 2011 Reply
  3. Timo September 9, 2011 Reply
  4. bdg December 21, 2011 Reply
  5. tanya gupta January 5, 2012 Reply
  6. gurjeet singh February 25, 2014 Reply

Leave a Reply


x

Interesting BlogPosts to read

How to get an Enumerator from range of elements from ArrayList in C# ?
The code snippet shown in this blog post demonstrates how you can get the enumeraor from a range of ...
How to check for the column name in an SqlDataReader Object in C# ?
When working in ADO.NET for data access , there are times when you want to check to see if a column ...
Download - Pokemon Go for for Windows 10 (Third Party app)
Pokemon Go is one of the popular AR games for android and iOS devices and now , the game is made ava...