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 .
5 Comments
I like to help.
?
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
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
the article is very gud but i am not able to provide isolated storage path as uri to media player launcher can you help regarding this problem