How to play Video or Music in Windows phone app using Mediaplayer Launcher

In this article we will learn about the Media Player Launcher that helps to launch the Windows Phone Media Player from our app. It can be used to play the Video or music with uniform Media Player interface.

 

1. First create a new project having the name Mediaplayer.

 


 

2. Before going further add the following Namespace required for the above tasks in the MainPage.xaml.cs.


 

MediaPlayerLauncher

MediaPlayerLauncher launches the Media Player application and plays the specified media file.
Media files can be stored in isolated storage, the application’s installation directory or any other location not belonging to the phone.

 

Let us take an example of Video which we need to play on our phone. The code required for this task is given below.

 


 

There are different properties in this task that needs to be explained

 

MediaPlaybackControls

You can optionally specify that one or more controls should be shown by the Media Player using bitwise OR combinations of the MediaPlaybackControls values:

  • MediaPlaybackControls.All
  • MediaPlaybackControls.None
  • MediaPlaybackControls.Pause
  • MediaPlaybackControls.Stop
  • MediaPlaybackControls.Skip
  • MediaPlaybackControls.FastForward
  • MediaPlaybackControls.Rewind

 

MediaLocationType

You can also specify one of these locations using the MediaLocationType enumeration.

  • 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 or is not present on the phone.

 

You can also play an audio file in a similar way .Just set the media path to the location of audio file that is either present in your application or is present online.

 

This might be useful when you want to play an online song on your phone.

Example suppose I want to play an online song the code required for this task is given below.


The code is similar to the video one the only change is in the media path.

 


 

Note:

1. On the Emulator the application can start the Media Player and play music, but video is not rendered! If possible test on a real device.
2. All audio file formats are not supported on Windows phone. You can check the list of audio formats supported by Windows phone from the link given below.

http://msdn.microsoft.com/en-in/library/windows/apps/hh986969.aspx

I hope this post will be helpful to you. You can download the full project source file from the link given below.

Download full source project file Mediaplayer.zip

Chetan Gulati

Currently am doing B TECH in IT from Delhi Technological University. App development is my passion. Believe in quality rather than quantity.

  • Umair

    how to add an image uri to media player launcher of an audio file

Read more:
How to create your first Windows Phone app
How to change the App name and Tile name of your Windows phone app
Data binding in Windows Phone app – One way binding
Close