ASP.NET MediaPlayer Control - Playing Audio Files

Earlier I had blogged about playing video files in ASP.NET using MediaPlayer Control which was then part of the .NET 3.5 Extensions Beta. The update is that now it is no longer ASP.NET 3.5 Extensions Beta.  You just have to install the .NET 3.5 SP1 to get this feature/control.

Today I was exploring on how I can play audio files (plain audio in wma format without any video).  Sounds simple right? Use the same MediaPlayer and point it to the wma file.

But it was a little more than what I thought of.  When you point the Media Player control to any resource and dont pick up a PlayerSkin, by default it thinks it is a video and puts up a Windows Media Player kind of an interface.  When you play a video, it makes sense to have this since you also have the display screen and worth taking the screen space.  However, when you play audio, all you require is a controller which takes up minimum space.

To do that, you simply have to pick up a PlayerSkin.  The default player skin that ships with the SP1 is AudioGray.xaml.  This provides a an audio control template that helps in playing/controling audio in the background.

The steps are

1. Create a "File - New - Website - ASP.NET Website"

2. Add a Webform to your solution.  You can chose "Webform" or an "AJAX Webform" .  If you chose a "Webform" you would require to add the ScriptManager Tag to your webform from the "Ajax Extensions" in ToolBox.

3. Expand the Toolbox, from Silverlight Controls, drag and drop a MediaPlayer control to your webform.

4. Click on the smart tag to get MediaPlayer Tasks Window

5. Click on the "Import Skin" link below the "PlayerSkin" Textbox

6. You get a list of available MediaPlayer Skins

7. Pick the "AudioGray.xaml" file which gives the skin for Audio control

8. Specify the "MediaSource" with your audio file

9. You can set it to "Mute" or "Auto Play" using the checkboxes according to your preference.

You are all set to play your audio file on your website.  Similarly for video files you could chose the built-in skins and customize according to your requirements and use them.

Playing audio/video on a webpage has never been easy.

Cheers !!!

posted @ Friday, September 19, 2008 12:19 AM

Print

Comments on this entry:

# re: ASP.NET MediaPlayer Control - Playing Audio Files

Left by Pandurang at 9/29/2008 9:50 AM
Gravatar
Quick note - you can also play MP3 with the same steps :)

# re: ASP.NET MediaPlayer Control - Playing Audio Files

Left by Mark Scott at 12/21/2008 8:02 PM
Gravatar
3. Expand the Toolbox, from Silverlight Controls, drag and drop a MediaPlayer control to your webform.

Where are these Silverlight Controls? My toolbar, but default, in VS2008 do not have any Silverlight controls.

# re: ASP.NET MediaPlayer Control - Playing Audio Files

Left by Roger at 2/23/2009 5:58 PM
Gravatar
You should write here about asp.net version.
Go to hell !

# re: ASP.NET MediaPlayer Control - Playing Audio Files

Left by Keith Grant at 3/4/2009 10:07 AM
Gravatar
Thank you for this blog and please ignore the hostile ignorance of Roger in the post above.

# re: ASP.NET MediaPlayer Control - Playing Audio Files

Left by DB at 5/20/2009 3:49 PM
Gravatar
I can safely say I have no idea what Roger is speaking about! :D

Thanks loads for this blog. I had integrated the Silverlight Media Player in my ASP.net app successfully but, when used purely for playing audio files, the default skin is hideous.

I tried using the actual silverlightaudioplayer from Codeplex but it seems half-baked, undocumented and almost impossible to implement.

This solution (ie changing the skin file) took me about 30 seconds to implement and has made my app look a whole lot better. Great work!

# re: ASP.NET MediaPlayer Control - Playing Audio Files

Left by priya at 5/29/2009 5:56 PM
Gravatar
How is get audio file length in asp.net

Your comment:



 (will not be displayed)


 
 
 
 
 

Live Comment Preview:

 
«November»
SunMonTueWedThuFriSat
25262728293031
1234567
891011121314
15161718192021
22232425262728
293012345