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 .



7 comments
Play Media files with the MediaPlayerLauncher in Windows Phone 7
[...] Read original post by Senthil Kumar at Ginktage [...]
Jun 24, 2011
Bent Elo Christiansen
I like to help.
Jun 24, 2011
Senthil Kumar
?
Jun 24, 2011
Play Media files with the MediaPlayerLauncher in Windows Phone 7 | ProgramInDotnet
[...] via Play Media files with the MediaPlayerLauncher in Windows Phone 7. [...]
Aug 1, 2011
Timo
Thanks for this article. It helps immediately.
Sep 9, 2011
bdg
Hi,
I am a newbee in WP7 and was trying to play songs in WP7 emulator.
I want to retrieve the filename from a Song instance (obtained from SongCollection database) and then create an AudioTrack instance with the URI and pass it to the background audioplayback agent. However I dont see a way to retrieve the filename from Song instance.
Can you please help me out? Thanks in advance
Dec 21, 2011
tanya gupta
the video is playing repeatedly but i dnt want this to happen, the video should play once and then stop, how to achieve this?? help
Jan 5, 2012