473,544 Members | 1,738 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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("WinM M.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.Enc oding.ASCII.Get Bytes(wfname);

PlaySound(bname ,SoundFlags);

}

public void StopPlay()

{

PlaySound(null, SND_PURGE);

}

_______________ _______________ _______________ _______________ _______________ _
____--
Nov 19 '05 #1
1 7984
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.wa v">

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**********@h otmail.com> wrote in message
news:eD******** ******@TK2MSFTN GP14.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("WinM M.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.Enc oding.ASCII.Get Bytes(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
4035
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": window.onload = function() { var audObj = document.createElement("object"); audObj.setAttribute("id", "objmedia");...
1
4287
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. I'm using python 2.4 with pymedia on XP. I started out with the example in the tutorials section of the pymedia website. The pymedia docs imply to...
2
4581
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 Windows API to play it. But that doesn't look very clean. I guess there must be a way to directly play that sound without first extracting it.
5
7173
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 the standard MessageBox icons into this dialog? Thanks, Dennis
1
3251
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 it possible to play a sound file in .aspx page. If it is through webservice, that is also good. C# code please. Also, please let me know waht is...
9
5593
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 server, WMP 10.0 . If I type the full path in an IE address field it plays the file in WMP When I test my Web page ( running the debugger in VS.)...
5
2139
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 play the sound. It works perfectly well in Windows XP, but when I move my application to a Vista machine, the sound does not play... I used a debug...
26
3860
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 almost no posts from the last 3 years: ...
8
14926
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 cut and paste code that MSDN recommends for playing a simple wav file from inside an embedded file, like presumeably the 'resources' file .resx is. ...
0
7598
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7757
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7360
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7699
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5288
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4905
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3400
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3398
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
982
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.