C Board  

Go Back   C Board > General Programming Boards > C# Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 05-27-2002, 05:13 PM   #1
Registered User
 
Join Date: Jan 2002
Posts: 18
Playing Music in C#

is there a way to play music in a C# app? ive been searching forums and code sites for a while and haven't been able to find something on it.
thanks
Smoose777 is offline   Reply With Quote
Old 05-28-2002, 10:53 PM   #2
Something Clever
 
ginoitalo's Avatar
 
Join Date: Dec 2001
Posts: 187
Try -

Code:
[DllImport("winmm.dll")] 
      public static extern long PlaySound(String lpszname, long hModule, long dwFlags);

Now, do the CBoard a favour,
Post some code when it works

ginoitalo is offline   Reply With Quote
Old 05-29-2002, 07:07 PM   #3
Unregistered
Guest
 
Posts: n/a
Yeah I heard that they forgot to add sound to Vs.net, but than you can allways export Win32 functionality in your managed C# project. I think that you need to add the dll to the assembly or something like that from the command line though, but I could be wrong. The linker is called al.exe, so type al on the command prompt to see all the options.
  Reply With Quote
Old 06-05-2002, 01:48 PM   #4
Super Moderator
 
Join Date: Sep 2001
Posts: 4,746
Are you talking about your basic 84 note PC-Speaker music, or are you talking full blown, Stereo, CD, WIN32 sound?
sean is offline   Reply With Quote
Old 06-05-2002, 02:43 PM   #5
Something Clever
 
ginoitalo's Avatar
 
Join Date: Dec 2001
Posts: 187
I think he means Rich Windows audio stuff like .wav, .mp3

If you know know to play either could
you post an example ?
ginoitalo is offline   Reply With Quote
Old 06-05-2002, 04:14 PM   #6
Registered User
 
Esss's Avatar
 
Join Date: Aug 2001
Posts: 133
Quite the easiest method is to use the ActiveMovie (quartz.dll) COM library.
Add a reference to the ActiveMovie COM library with Add Reference. This will generate an RCW (runtime callable wrapper) around the library, and will put it in the QuartzTypeLib namespace. Then:
PHP Code:
QuartzTypeLib.FilgraphManagerClass fm = new QuartzTypeLib.FilgraphManagerClass();

fm.RenderFile("D:\\\\My Music\\\\Whitesnake - Is This Love.mp3");
fm.Run(); 
The current position is available from the CurrentPosition property, and you can check to see if it's finished by comparing this with the StopPosition property.
PHP Code:
do
{
    
System.Console.Write(String.Format("\r{0}", (int)fm.CurrentPosition));
}
while (
fm.CurrentPosition fm.StopTime);
fm.Stop(); 
__________________
Ess
Like a rat in a maze who says,
"Watch me choose my own direction"
Are you under the illusion
The path is winding your way?
- Rush
Esss is offline   Reply With Quote
Old 06-05-2002, 06:16 PM   #7
Banned
 
Troll_King's Avatar
 
Join Date: Oct 2001
Posts: 1,784
Still this isn't .net. It's running unmanaged code within a managed assembly. Is there any music playing functionality in the .net BCL?
Troll_King is offline   Reply With Quote
Old 06-06-2002, 04:40 AM   #8
Registered User
 
Esss's Avatar
 
Join Date: Aug 2001
Posts: 133
> Still this isn't .net. It's running unmanaged code within a managed assembly.

Of course it is. So is anything you do that interacts with the user. Ultimately it always comes down to unmanaged code. Display a window, and some unmanaged code (rather a lot of it, actually) is used to show that window. Or did you have some other means in mind to address the soundcard?

There are no classes within the .NET Framework for sound of any kind.
__________________
Ess
Like a rat in a maze who says,
"Watch me choose my own direction"
Are you under the illusion
The path is winding your way?
- Rush
Esss is offline   Reply With Quote
Old 06-06-2002, 06:42 AM   #9
Banned
 
Troll_King's Avatar
 
Join Date: Oct 2001
Posts: 1,784
Yes, I can tell that the framework makes calls to Win32 when I use the cordbg command line debugger utility. Before optimizing the JIT's it calls Win32 about 3700 times for a hello world program. After optimization it ends up at around 355 or approximately 10 percent.

The idea I'm wondering about however is the frameworks capability to allow the programmer to deploy much easier. Simply cut and paste the assembly, however does having too many unmanaged modules screw that up? Also with the assembly apparently you have dll versioning, but does unmanaged modules interfere with that too? Why doesn't the Framework Class Library have a namespace which deals with music files?
Troll_King is offline   Reply With Quote
Old 06-06-2002, 04:11 PM   #10
Registered User
 
Esss's Avatar
 
Join Date: Aug 2001
Posts: 133
> The idea I'm wondering about however is the frameworks capability to allow the programmer to deploy much easier. Simply cut and paste the assembly, however does having too many unmanaged modules screw that up?

Not if you can rely on the unmanaged modules being there, which is of course possible with the ActiveMovie library.

> Also with the assembly apparently you have dll versioning, but does unmanaged modules interfere with that too?

Obviously, using COM components implies you wind up using the COM versioning model. Which is not terribly robust. However, it doesn't have any effect on the versioning of your own assemblies.

> Why doesn't the Framework Class Library have a namespace which deals with music files?

Probably because the rest of the .NET Framework took up all the available time. There are rumours of 'managed DirectX', but when it's this easy (and reliable), why bother waiting?
__________________
Ess
Like a rat in a maze who says,
"Watch me choose my own direction"
Are you under the illusion
The path is winding your way?
- Rush
Esss is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Is AOL music crazy? joeprogrammer General Discussions 9 03-24-2006 07:24 PM
Playing music adr Windows Programming 13 12-31-2005 03:23 PM
playing music in C++ dutch's finest C++ Programming 3 02-21-2005 05:57 PM
Playing music PJYelton Windows Programming 5 06-25-2003 09:09 AM
Playing Music Quantrizi A Brief History of Cprogramming.com 11 05-11-2002 07:47 PM


All times are GMT -6. The time now is 01:19 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22