473,698 Members | 2,571 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

play a piece of music

I want to play a piece of music in .NET application
How to do that ?
Thanks a lot !
Nov 16 '05 #1
3 9762
> "Hai Ly Hoang" schrieb im Newsbeitrag
I want to play a piece of music in .NET application
How to do that ?


Have a look at this free library:
http://www.mentalis.org/soft/class.qpx?id=1

Usage is easy:

using Org.Mentalis.Mu ltimedia;
SoundFile sf = new SoundFile("path ToSoundFile");
sf.Play();
Cheers

Arne Janning
Nov 16 '05 #2
"Hai Ly Hoang" <No*****@Mail.c om> ha scritto nel messaggio
news:Of******** ******@TK2MSFTN GP10.phx.gbl...
I want to play a piece of music in .NET application
How to do that ?


You can try with the managed DirectX or with the OpenAL porting Tao.OpenAL
too.

Here is a piece of code I use for playing mp3 files with DirectSound. Hope
it can be useful.
Just look at the methods Music_Load(stri ng filename) and Music_Play().

using System;
using System.Windows. Forms;

using Microsoft.Direc tX;

using Microsoft.Direc tX.AudioVideoPl ayback;

[...]

private Audio ourAudio = null;

{...]

private int Music_Load(stri ng filename)

{

try

{

ourAudio = new Audio(filename) ;

ourAudio.Ending += new System.EventHan dler(this.Music _ClipEnded); //CALLED
AT THE END

}

catch

{

MessageBox.Show ("Error", "Invalid/corrupted file?.", MessageBoxButto ns.OK,
MessageBoxIcon. Information);

return -1;

}

return 0;

}

private int Music_Play()

{

try

{

ourAudio.Play() ;

return 0;

}

catch

{

MessageBox.Show ("Error", "Music_Play () failed.", MessageBoxButto ns.OK,
MessageBoxIcon. Information);

return -1;

}

}

private void Music_ClipEnded (object sender, System.EventArg s e)

{

if (ourAudio != null)

{

ourAudio.Stop() ;

ourAudio.Play() ; //LOOP PLAY

}

}


Nov 16 '05 #3
I've created a very basic program in C#
but for some reason it doesn't run but runs the debugger instead:
As described in the SDK documentation your program is supposed to work
exactly as mine but yours works and mine doesn't.
Here is the code.
private Device dsDevice = null;
SecondaryBuffer buffer;
BufferDescripti on info;
public Form1()
{

dsDevice = new Device();
dsDevice.SetCoo perativeLevel(t his,Cooperative Level.Priority) ;
info=new BufferDescripti on();
info.ControlFre quency=true;
Info.ControlPan =true;
info.ControlVol ume=true;
buffer=new SecondaryBuffer ("Chord.wav",in fo,dsDevice);

buffer.Play(0,B ufferPlayFlags. Default);

Can anyone tell me what's the problem?
THanks a lot!
Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1319
by: Jenny | last post by:
This is an old post. How to make it work? ------------------ Hi If anyone out there could figure out why the following script dosen't work, and maybe help me fixing the problem, I would be very gratefull. //Html document starts:
2
2656
by: Con | last post by:
Hi, I'm getting the following error message in the JavaScript console: Error: mus has no properties Source File: file:///G:/temp/cafedub.htm Line: 35 Now, I would like to script to work in both IE 6 and Netscape 7. The goals of the script are as follows: o when a music image is clicked, please the associated music without
1
4297
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 me that playback using Output's play() method should already be asynchronous and controllable. I...
2
1681
by: Hai Ly Hoang | last post by:
In my application, i want to play a piece of music (wav or mp3). How to do it ?
20
3247
by: Stephen Kellett | last post by:
Hi Folks, How can I play midi and/or audio files using JavaScript? I'm hoping there are some calls/APIs I can use that I am unaware of. My JavaScript book from O'Reilly seems rather lacking in this area. I'm looking for something like: playMidiNote(pitch, duration); playSoundFile(soundFileURL);
10
2074
by: exodus | last post by:
As a fun little task to gain more knowledge of python, i decided to try to mimick the ipod UI with it. here's what i've got so far #!/usr/bin/env python # -*- coding: utf-8 -*- # generated by wxGlade 0.5 on Sat Oct 27 15:46:36 2007 import wx, os, pygame pygame.init() class MyFrame2(wx.MDIChildFrame):
10
7059
by: andrew.smith.cpp | last post by:
Hello :-) how can i play a ".wav" file in C++.means with the help of the C++ code i just want to play a "a.wav" file more then 10 times. i just want to play background music. Can i do it in C++ ? if yes then how ? Thanks
17
12868
by: Muddasir | last post by:
Hi everyone. How can I play music in background while user can browse through my website. Uptill now I have created a music player which plays audio tracks but as soon as users jumps to another page the music stops. How can I achieve this. any ideas !!!!! Regards Muddasir Hussain
5
6071
by: Kapil Choubisa | last post by:
Hi! Everybody I am creating an application for playing music files in Browser. I successfully palyed the .Wav file. but I am unable to play other formats of music files. Is there any tool or way for this. or How can I add plugins to my web application for asking user to install for playing Plz help me
0
9170
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8902
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
8873
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5862
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4372
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4623
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3052
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2339
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.