A New Internet Library: Add Your Website/Blog or Suggest A Website/Blog to our Free Web Directory http://anil.myfunda.net.

Its very simple, free and SEO Friendly.
Submit Now....

Wednesday, November 19, 2008

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



Source Click Here.

No comments:

Post a Comment

Post your comments here:

Originals Enjoy