Play message

A

asharda

Hi,

I have a small site which gets the file name from the database and
then maps it to a directory on the server and then plays it when the
button is clicked. The file plays as long as I run the application
from my m/c but if I try to run it from the internal network
everythign works except that the file doesn't play the message. I am
not sure what is wrong. I checked the path and that looks ok and it
doesn't throw any exceptions either.

Here is the code:

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Runtime.InteropServices; // for PInvoke


public partial class _Default : System.Web.UI.Page
{
DataSet dsData;

[System.Runtime.InteropServices.DllImport("winmm.DLL", EntryPoint
= "PlaySound", SetLastError = true)]
private static extern bool PlaySound(string szSound, System.IntPtr
hMod, PlaySoundFlags flags);

[System.Flags]
public enum PlaySoundFlags : int
{
SND_SYNC = 0x0000,
SND_ASYNC = 0x0001,
SND_NODEFAULT = 0x0002,
SND_LOOP = 0x0008,
SND_NOSTOP = 0x0010,
SND_NOWAIT = 0x00002000,
SND_FILENAME = 0x00020000,
SND_RESOURCE = 0x00040004
}

protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{

loadData();
//dsData.Tables[0].DefaultView.RowFilter = "DateRecorded
IS NOT NULL";
GridView1.DataSource = dsData.Tables[0]; //.DefaultView;
GridView1.DataBind();
}

}


protected void GridView1_RowCommand(object sender,
GridViewCommandEventArgs e)
{
int index = int.Parse(e.CommandArgument.ToString());
GridView grid = (GridView)e.CommandSource;
GridViewRow row = grid.Rows[index];

if (e.CommandName == "PlayMessage")
{
//lblRecordCount.Text = Server.MapPath("~/AudioFiles/" +
row.Cells[2].Text);
lblRecordCount.Text = Server.MapPath("~/AudioFiles/" +
row.Cells[2].Text);
try
{
PlaySound(Server.MapPath("~/AudioFiles/" +
row.Cells[2].Text), new System.IntPtr(), PlaySoundFlags.SND_SYNC);
}
catch (Exception ex)
{
lblRecordCount.Text = "Exception : " + ex.ToString();
}
}

else if (e.CommandName == "GetTagList")
{
Response.Write( "<script>window.open('EditTagList.aspx?
id=" + grid.DataKeys[index].Value + "&Name=" + row.Cells[2].Text +
"','myWindow','height=400px,width=450px,top=200,left=200')</script>");
}
}
}

Thanks,
 
K

Kevin Spencer

Your code to play the sound is server-side code. Therefore, it will play
sound on the web server machine while processing the page. You can hear it
on your machine because when you are running the application on your
machine, your machine is the server.

--
HTH,

Kevin Spencer
Chicken Salad Surgeon
Microsoft MVP

Hi,

I have a small site which gets the file name from the database and
then maps it to a directory on the server and then plays it when the
button is clicked. The file plays as long as I run the application
from my m/c but if I try to run it from the internal network
everythign works except that the file doesn't play the message. I am
not sure what is wrong. I checked the path and that looks ok and it
doesn't throw any exceptions either.

Here is the code:

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Runtime.InteropServices; // for PInvoke


public partial class _Default : System.Web.UI.Page
{
DataSet dsData;

[System.Runtime.InteropServices.DllImport("winmm.DLL", EntryPoint
= "PlaySound", SetLastError = true)]
private static extern bool PlaySound(string szSound, System.IntPtr
hMod, PlaySoundFlags flags);

[System.Flags]
public enum PlaySoundFlags : int
{
SND_SYNC = 0x0000,
SND_ASYNC = 0x0001,
SND_NODEFAULT = 0x0002,
SND_LOOP = 0x0008,
SND_NOSTOP = 0x0010,
SND_NOWAIT = 0x00002000,
SND_FILENAME = 0x00020000,
SND_RESOURCE = 0x00040004
}

protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{

loadData();
//dsData.Tables[0].DefaultView.RowFilter = "DateRecorded
IS NOT NULL";
GridView1.DataSource = dsData.Tables[0]; //.DefaultView;
GridView1.DataBind();
}

}


protected void GridView1_RowCommand(object sender,
GridViewCommandEventArgs e)
{
int index = int.Parse(e.CommandArgument.ToString());
GridView grid = (GridView)e.CommandSource;
GridViewRow row = grid.Rows[index];

if (e.CommandName == "PlayMessage")
{
//lblRecordCount.Text = Server.MapPath("~/AudioFiles/" +
row.Cells[2].Text);
lblRecordCount.Text = Server.MapPath("~/AudioFiles/" +
row.Cells[2].Text);
try
{
PlaySound(Server.MapPath("~/AudioFiles/" +
row.Cells[2].Text), new System.IntPtr(), PlaySoundFlags.SND_SYNC);
}
catch (Exception ex)
{
lblRecordCount.Text = "Exception : " + ex.ToString();
}
}

else if (e.CommandName == "GetTagList")
{
Response.Write( "<script>window.open('EditTagList.aspx?
id=" + grid.DataKeys[index].Value + "&Name=" + row.Cells[2].Text +
"','myWindow','height=400px,width=450px,top=200,left=200')</script>");
}
}
}

Thanks,
 
A

asharda

Your code to play the sound is server-side code. Therefore, it will play
sound on the web server machine while processing the page. You can hear it
on your machine because when you are running the application on your
machine, your machine is the server.

--
HTH,

Kevin Spencer
Chicken Salad Surgeon
Microsoft MVP




I have a small site which gets the file name from the database and
then maps it to a directory on the server and then plays it when the
button is clicked. The file plays as long as I run the application
from my m/c but if I try to run it from the internal network
everythign works except that the file doesn't play the message. I am
not sure what is wrong. I checked the path and that looks ok and it
doesn't throw any exceptions either.
Here is the code:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Runtime.InteropServices;    // for PInvoke
public partial class _Default : System.Web.UI.Page
{
   DataSet dsData;
   [System.Runtime.InteropServices.DllImport("winmm.DLL", EntryPoint
= "PlaySound", SetLastError = true)]
   private static extern bool PlaySound(string szSound, System.IntPtr
hMod, PlaySoundFlags flags);
   [System.Flags]
   public enum PlaySoundFlags : int
   {
       SND_SYNC = 0x0000,
       SND_ASYNC = 0x0001,
       SND_NODEFAULT = 0x0002,
       SND_LOOP = 0x0008,
       SND_NOSTOP = 0x0010,
       SND_NOWAIT = 0x00002000,
       SND_FILENAME = 0x00020000,
       SND_RESOURCE = 0x00040004
   }
   protected void Page_Load(object sender, EventArgs e)
   {
       if (IsPostBack)
       {
           loadData();
           //dsData.Tables[0].DefaultView.RowFilter = "DateRecorded
IS NOT NULL";
           GridView1.DataSource = dsData.Tables[0]; //.DefaultView;
           GridView1.DataBind();
       }
   protected void GridView1_RowCommand(object sender,
GridViewCommandEventArgs e)
   {
       int index = int.Parse(e.CommandArgument.ToString());
       GridView grid = (GridView)e.CommandSource;
       GridViewRow row = grid.Rows[index];
       if (e.CommandName == "PlayMessage")
       {
           //lblRecordCount.Text = Server.MapPath("~/AudioFiles/" +
row.Cells[2].Text);
           lblRecordCount.Text = Server.MapPath("~/AudioFiles/" +
row.Cells[2].Text);
           try
           {
               PlaySound(Server.MapPath("~/AudioFiles/" +
row.Cells[2].Text), new System.IntPtr(), PlaySoundFlags.SND_SYNC);
           }
           catch (Exception ex)
           {
               lblRecordCount.Text = "Exception : " + ex.ToString();
           }
       }
       else if (e.CommandName == "GetTagList")
       {
           Response.Write( "<script>window.open('EditTagList..aspx?
id=" + grid.DataKeys[index].Value + "&Name=" + row.Cells[2].Text +
"','myWindow','height=400px,width=450px,top=200,left=200')</script>");
       }
   }
}
Thanks,- Hide quoted text -

- Show quoted text -

How can I make it to play on the client machine and not on the server?

Thanks,
 

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,769
Messages
2,569,582
Members
45,059
Latest member
cryptoseoagencies

Latest Threads

Top