By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,696 Members | 2,213 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,696 IT Pros & Developers. It's quick & easy.

play sound file

P: n/a
Lam
how can I play sound file in a .aspx page written in C#?

I try to use the code like the following. But whenI call the play function
play("sound.wav", this.SND_ASYNC)
my computer give out "be" sound instead playing the file
(same code works fine in a windows application written in c# , that mean
there is nothing wrong with my sound card.)
thanks
----------------------------------------------------------------------------
------------------
public class WAVSounds

{

[DllImport("WinMM.dll")]

public static extern bool PlaySound(byte[]wfname, int fuSound);

// flag values for SoundFlags argument on PlaySound

public int SND_SYNC = 0x0000; // play synchronously (default)

public int SND_ASYNC = 0x0001; // play asynchronously

public int SND_NODEFAULT = 0x0002; // silence (!default) if sound not found

public int SND_MEMORY = 0x0004; // pszSound points to a memory file

public int SND_LOOP = 0x0008; // loop the sound until next sndPlaySound

public int SND_NOSTOP = 0x0010; // don't stop any currently playing sound

public int SND_NOWAIT = 0x00002000; // don't wait if the driver is busy

public int SND_ALIAS = 0x00010000; // name is a registry alias

public int SND_ALIAS_ID = 0x00110000; // alias is a predefined ID

public int SND_FILENAME = 0x00020000; // name is file name

public int SND_RESOURCE = 0x00040004; // name is resource name or atom

public int SND_PURGE = 0x0040; // purge non-static events for task

public int SND_APPLICATION = 0x0080; // look for application specific
association

public WAVSounds()

{}

~WAVSounds()

{

}

public void Play(string wfname,int SoundFlags)

{

byte[] bname = new Byte[256]; //Max path length

bname = System.Text.Encoding.ASCII.GetBytes(wfname);

PlaySound(bname,SoundFlags);

}

public void StopPlay()

{

PlaySound(null,SND_PURGE);

}

__________________________________________________ __________________________
____--
Nov 19 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
It seems your code is attempting to play a sound on the server, when I think
you really want to play a sound on the client, correct?
There are a variety of ways to play a sound on the client.

For example, you can put some HTML in your page like this to play a wav, mp3
or midi file in your IE web page:
<bgsound src="mysound.wav">

And here are some more advanced techniques:
http://www.steveorr.net/Articles/StreamingMedia.aspx

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net

"Lam" <ja**********@hotmail.com> wrote in message
news:eD**************@TK2MSFTNGP14.phx.gbl...
how can I play sound file in a .aspx page written in C#?

I try to use the code like the following. But whenI call the play
function
play("sound.wav", this.SND_ASYNC)
my computer give out "be" sound instead playing the file
(same code works fine in a windows application written in c# , that mean
there is nothing wrong with my sound card.)
thanks
----------------------------------------------------------------------------
------------------
public class WAVSounds

{

[DllImport("WinMM.dll")]

public static extern bool PlaySound(byte[]wfname, int fuSound);

// flag values for SoundFlags argument on PlaySound

public int SND_SYNC = 0x0000; // play synchronously (default)

public int SND_ASYNC = 0x0001; // play asynchronously

public int SND_NODEFAULT = 0x0002; // silence (!default) if sound not
found

public int SND_MEMORY = 0x0004; // pszSound points to a memory file

public int SND_LOOP = 0x0008; // loop the sound until next sndPlaySound

public int SND_NOSTOP = 0x0010; // don't stop any currently playing sound

public int SND_NOWAIT = 0x00002000; // don't wait if the driver is busy

public int SND_ALIAS = 0x00010000; // name is a registry alias

public int SND_ALIAS_ID = 0x00110000; // alias is a predefined ID

public int SND_FILENAME = 0x00020000; // name is file name

public int SND_RESOURCE = 0x00040004; // name is resource name or atom

public int SND_PURGE = 0x0040; // purge non-static events for task

public int SND_APPLICATION = 0x0080; // look for application specific
association

public WAVSounds()

{}

~WAVSounds()

{

}

public void Play(string wfname,int SoundFlags)

{

byte[] bname = new Byte[256]; //Max path length

bname = System.Text.Encoding.ASCII.GetBytes(wfname);

PlaySound(bname,SoundFlags);

}

public void StopPlay()

{

PlaySound(null,SND_PURGE);

}

__________________________________________________ __________________________
____--

Nov 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.