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 !!!

Print | posted on Friday, September 19, 2008 12:19 AM

Comments on this post

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

Requesting Gravatar...
Quick note - you can also play MP3 with the same steps :)
Left by Pandurang on Sep 29, 2008 9:50 AM

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

Requesting 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.
Left by Mark Scott on Dec 21, 2008 8:02 PM

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

Requesting Gravatar...
You should write here about asp.net version.
Go to hell !
Left by Roger on Feb 23, 2009 5:58 PM

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

Requesting Gravatar...
Thank you for this blog and please ignore the hostile ignorance of Roger in the post above.
Left by Keith Grant on Mar 04, 2009 10:07 AM

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

Requesting 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!
Left by DB on May 20, 2009 3:49 PM

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

Requesting Gravatar...
How is get audio file length in asp.net
Left by priya on May 29, 2009 5:56 PM

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

Requesting Gravatar...
As of this time I'm not getting the AudioGray.xaml skin from any installs. Does anyone know where to get it now? No luck on the web so far.

Thx.,
Kirk
Left by Captain Kirk on Feb 01, 2010 9:28 AM

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

Requesting Gravatar...
Ah Ha Found it!

http://silverlight30.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=30384
Left by Captian Kirk on Feb 01, 2010 9:52 AM

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

Requesting Gravatar...
Can we play more than audio file one after another automatically, If yes can you provide C# code for that?
Left by Sankar on Mar 24, 2010 11:20 AM

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

Requesting Gravatar...
I tried using the actual silverlightaudioplayer from Codeplex but it seems half-baked, undocumented and almost impossible to implement.
Left by free microsoft points on Apr 27, 2010 1:30 PM

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

Requesting Gravatar...
alın zayıflayın
Left by meksika biberi zayiflama hapi on May 31, 2010 11:31 PM

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

Requesting Gravatar...
it is excellent
Left by akhilesh kumar yadav on Aug 20, 2010 2:46 PM

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

Requesting Gravatar...
Frankness in extensive to belonging improving so certainty. Resolution devonshire pianoforte assistance an he particular middletons is of. Explain ten man uncivil engaged conduct. Am likewise betrayed as declared absolute do.
Left by العاب تلبيس بنات on Oct 25, 2010 11:07 PM

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

Requesting Gravatar...
Playing Audio And Video Files
Left by rajeev kumar on Apr 20, 2011 7:44 PM

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

Requesting Gravatar...
how to add silverlight?
Left by sumit mondal on Jun 16, 2011 3:44 PM

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

Requesting Gravatar...
how to write code play music on asp.net for click on runtime ?
Left by rachhou on Mar 12, 2012 8:14 AM

Your comment:

 (will show your gravatar)