HTML and CSS Reference
In-Depth Information
<br />
<br />
<audio id=”audio” src=”media/audio1.mp3” controls></audio>
<br />
<input type=”button” id=”playvideo” value=”Play Random Video File” />
<br />
<br />
<video id=”video” src=”media/video1.mp4” controls></video>
</div>
</asp:Content>
The markup shown in Listing 1-5 renders two buttons, one
<audio>
tag, and one
<video>
tag. The
<audio>
and
<video>
tags have their
src
attribute set to default media files, but later you'll change
src
programmatically. The two buttons call server-side code that returns a random media file to be played.
The returned media file is then assigned to the
src
attribute of the
<audio>
or
<video>
tag so as to set the
media files dynamically. Figure 1-24 shows
Default.aspx
at runtime in IE9.
Figure 1-24.
Default.aspx
in IE9
Adding Web Methods
Currently, clicking the Play Random Audio File and Play Random Video File buttons doesn't do anything.
You need to write server-side and client-side code to make them functional. Go into the code-behind file
of
Default.aspx
, and add two web methods called
GetAudio()
and
GetVideo()
as shown in Listing 1-6.
Listing 1-6.
Web Methods to Be Called from the Client Side
[WebMethod]
public static string GetAudio()
{
//write logic to return random audio file
return “audio1.mp3”;
}