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
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
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
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.
Are you talking about your basic 84 note PC-Speaker music, or are you talking full blown, Stereo, CD, WIN32 sound?
I think he means Rich Windows audio stuff like .wav, .mp3
If you know know to play either could
you post an example ?
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: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:
QuartzTypeLib.FilgraphManagerClass fm = new QuartzTypeLib.FilgraphManagerClass();
fm.RenderFile("D:\\\\My Music\\\\Whitesnake - Is This Love.mp3");
fm.Run();
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
Still this isn't .net. It's running unmanaged code within a managed assembly. Is there any music playing functionality in the .net BCL?
> 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
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?
> 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