Play Sound Clip Once

I

illmagination

Hi,

I recently received a task to have a .wav file play only once when home
page is 1st loaded and only play again when the user re-visits the page
by opening a new browser.

I am using asp.net 2.0 framework. Could someone please guide me?

Thank you.
 
K

Ken Cox [Microsoft MVP]

Hi,

I'd use a Session variable and output the client-side code programmatically.

The code below checks for the Session variable "Played". If the value is not
1, output the code to play the sound. Then set the Session variable to 1. As
long as the session is alive (that is, until the user leaves the site for 20
minutes [default] or closes the browser), the sound won't play again.

Let us know if this helps?

Ken
Microsoft MVP [ASP.NET]

<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

Protected Sub Page_Load _
(ByVal sender As Object, _
ByVal e As System.EventArgs)
If Not (Session("Played") = 1) Then
Page.ClientScript.RegisterStartupScript _
(Me.GetType, "sound", "<embed autostart='true' height='0' " & _
"loop='false' src='http://www.devx.com/assets/devx/8990.mid' " &
_
" width='0'></embed>", False)
Session("Played") = 1
End If
End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Play a sound once</title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
 
I

illmagination

Thank you but I was able to take care of it by writing to the code
behind

please see below

protected void Page_Load(object sender, EventArgs e)
{
if (Convert.ToString(Page.Session["MediaPlay"]) == "")
{
this.Page.Response.Write("<bgsound
src='/sound/Welcome.wav'>");
this.Page.Session["MediaPlay"] = "TRUE";
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top