Play message

Play message

am 21.01.2008 23:07:16 von 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( "");
}
}
}

Thanks,

Re: Play message

am 22.01.2008 13:04:39 von 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

wrote in message
news:f6e8a563-bda1-4d7f-8bf8-3737764a6de0@i29g2000prf.google groups.com...
> 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( "");
> }
> }
> }
>
> Thanks,

Re: Play message

am 22.01.2008 15:23:11 von asharda

On Jan 22, 7:04=A0am, "Kevin Spencer" wrote:
> 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
>
> wrote in message
>
> news:f6e8a563-bda1-4d7f-8bf8-3737764a6de0@i29g2000prf.google groups.com...
>
>
>
> > 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; =A0 =A0// for PInvoke
>
> > public partial class _Default : System.Web.UI.Page
> > {
> > =A0 =A0DataSet dsData;
>
> > =A0 =A0[System.Runtime.InteropServices.DllImport("winmm.DLL", EntryPoint=

> > =3D "PlaySound", SetLastError =3D true)]
> > =A0 =A0private static extern bool PlaySound(string szSound, System.IntPt=
r
> > hMod, PlaySoundFlags flags);
>
> > =A0 =A0[System.Flags]
> > =A0 =A0public enum PlaySoundFlags : int
> > =A0 =A0{
> > =A0 =A0 =A0 =A0SND_SYNC =3D 0x0000,
> > =A0 =A0 =A0 =A0SND_ASYNC =3D 0x0001,
> > =A0 =A0 =A0 =A0SND_NODEFAULT =3D 0x0002,
> > =A0 =A0 =A0 =A0SND_LOOP =3D 0x0008,
> > =A0 =A0 =A0 =A0SND_NOSTOP =3D 0x0010,
> > =A0 =A0 =A0 =A0SND_NOWAIT =3D 0x00002000,
> > =A0 =A0 =A0 =A0SND_FILENAME =3D 0x00020000,
> > =A0 =A0 =A0 =A0SND_RESOURCE =3D 0x00040004
> > =A0 =A0}
>
> > =A0 =A0protected void Page_Load(object sender, EventArgs e)
> > =A0 =A0{
> > =A0 =A0 =A0 =A0if (IsPostBack)
> > =A0 =A0 =A0 =A0{
>
> > =A0 =A0 =A0 =A0 =A0 =A0loadData();
> > =A0 =A0 =A0 =A0 =A0 =A0//dsData.Tables[0].DefaultView.RowFilter =3D "Dat=
eRecorded
> > IS NOT NULL";
> > =A0 =A0 =A0 =A0 =A0 =A0GridView1.DataSource =3D dsData.Tables[0]; //.Def=
aultView;
> > =A0 =A0 =A0 =A0 =A0 =A0GridView1.DataBind();
> > =A0 =A0 =A0 =A0}
>
> > =A0 =A0}
>
> > =A0 =A0protected void GridView1_RowCommand(object sender,
> > GridViewCommandEventArgs e)
> > =A0 =A0{
> > =A0 =A0 =A0 =A0int index =3D int.Parse(e.CommandArgument.ToString());
> > =A0 =A0 =A0 =A0GridView grid =3D (GridView)e.CommandSource;
> > =A0 =A0 =A0 =A0GridViewRow row =3D grid.Rows[index];
>
> > =A0 =A0 =A0 =A0if (e.CommandName == "PlayMessage")
> > =A0 =A0 =A0 =A0{
> > =A0 =A0 =A0 =A0 =A0 =A0//lblRecordCount.Text =3D Server.MapPath("~/Audio=
Files/" +
> > row.Cells[2].Text);
> > =A0 =A0 =A0 =A0 =A0 =A0lblRecordCount.Text =3D Server.MapPath("~/AudioFi=
les/" +
> > row.Cells[2].Text);
> > =A0 =A0 =A0 =A0 =A0 =A0try
> > =A0 =A0 =A0 =A0 =A0 =A0{
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0PlaySound(Server.MapPath("~/AudioFiles/" =
+
> > row.Cells[2].Text), new System.IntPtr(), PlaySoundFlags.SND_SYNC);
> > =A0 =A0 =A0 =A0 =A0 =A0}
> > =A0 =A0 =A0 =A0 =A0 =A0catch (Exception ex)
> > =A0 =A0 =A0 =A0 =A0 =A0{
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0lblRecordCount.Text =3D "Exception : " + =
ex.ToString();
> > =A0 =A0 =A0 =A0 =A0 =A0}
> > =A0 =A0 =A0 =A0}
>
> > =A0 =A0 =A0 =A0else if (e.CommandName == "GetTagList")
> > =A0 =A0 =A0 =A0{
> > =A0 =A0 =A0 =A0 =A0 =A0Response.Write( "