473,386 Members | 1,828 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

play sound file

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
1 7966
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Andrew Poulos | last post by:
As a follow on to the 'fun' I had with IE I'm now trying to play sounds using an Object tag (no Embed) in MZ. Sadly whenever 'playButton' gets clicked MZ says that "audObj.Play is not a function":...
1
by: Ron Provost | last post by:
Hello, I'm developing a piece of software to assist illiteraate adults to learn to read. I'm trying to figure out how, if possible, to make audio playback asynchrnous but still controllable. ...
2
by: NB | last post by:
I've done a thorough search, but could not find any posts If I store a sound file within the mdb, How do I play it (in a form event, for example) I can save it to a temp folder and call the...
5
by: Dennis C. Drumm | last post by:
I have a windows form configured as a fixed dialog I'm using as a custom MessageBox (has some additional buttons). How do I get it to play the standard windows sounds when envoked and can I insert...
1
by: Lord2702 | last post by:
I want to play a sound file, which is on my server, and approximately 5 - 7 MB it is .Wav file. or .mp3, I want to play this file so that user of my site can click on a link to play this file. Is...
9
by: Morris Neuman | last post by:
Im working with VS 2005 and trying to use a Hyperlink field in a datagrid to play a wave file that is not located in the website folders but is in a plain folder on the same machine, windows 2003...
5
by: | last post by:
Hello, I am wrtting a program that does some sound effects... the files are stored in a subfolder in the application folder... and I check the existence of the files before calling the method to...
26
by: Jake Barnes | last post by:
I did a search on the newsgroup comp.lang.javascript. I was searching for "how to play a sound with Javascript". I'm somewhat suprised that the majority of entries are from the 1990s, and there are...
8
by: raylopez99 | last post by:
I have the latest version of Visual Studio 2008 Professional, which allows you to create resource files (this is the .resx file, no?), unlike the Express version, which does not. I am trying to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.