Explain how can Silverlight use ASX files.
An ASX file is an XML file in which media files are specified in the playlist. Using ASX files in silver is pretty simple. Assign the ‘ source’ property of a MediaElement object to the ASX file name.
The following is an example of ASX file. <ASX version = "3.0">
<TITLE>MyFirst ASX Application</TITLE>
<ENTRY>
<TITLE>MyVideo</TITLE>
<AUTHOR>MyName</AUTHOR>
<COPYRIGHT>(c)2010 A company name</COPYRIGHT>
<REF HREF = "xbox.wmv" />
</ENTRY>
</ASX>
Later this .asx file need to assigned to the ‘Source’ property of MediaElement in XAML file.
<MediaElement>
.
.
Source=”myasxfile.asx”
.
</MediaElement>
Finally, add event handlers for supporting the MediaElement. The following functions are used for stopping, pausing and playing events on CurrentStateChanged event.
function media_stop(sender, args)
{
sender.findName("MediaPlayer").stop();
}
function media_pause(sender, args)
{
sender.findName("MediaPlayer").pause();
}
function media_begin(sender, args)
{
player = sender.findName("MediaPlayer");
player.play();
}
function media_state_changed(sender, args)
{
// Obtain the text block for displaying the status var mediaStateTextBlock = sender.findName("mediaStateTextBlock");
// Obtain the media state object
var media = sender.findName("MediaPlayer");
mediaStateTextBlock.Text = media.CurrentState;
}