I am building an application that play multiple wave files continuously.

I learned that .NET 2.0 framework provide us with PlayLooping() from System.Media namespace.

However this method does not allow me to play multiple file.

Anybody know any solution or links that might help me


Re: Visual C# General Need help playing wave file.

Dominator Legend


If u mean runing more than one file at the same time, u may need DirectX,

The multifile is made by u, i.e. when playere finish playing u give the next file and so on, u will need to know when the file finish in order to load the next one, DirectX may help u in this

you may try DirectX, it will allow u to control the media, i think DirectSound will not be neccessary u may use DirectAudioVideoPlayer.

Good luck

Re: Visual C# General Need help playing wave file.


Thanks for the suggestion.

I tried using it and it works.

I still have a question though. How are we able to detect when a file finish playing.

I am playing the sound file with SecondaryBuffer.

Re: Visual C# General Need help playing wave file.

Dominator Legend


I try to find a way to get the duration of loaded file using DirectSound, SecondaryBuffer i found that you can get the current position and set the current position but i didn't found a way to get the file duration, unlike Directtovideo it can tell you the file duration,

If you trying to build an audio player without making advanced actions like effects, you can use DirectAudioVideo, I code one here is the link, ProjName=Direct%20Library&ProjLang=CSharp

I'm sorry to tell you that i don't know how to get the duration using the direct sound,

good luck mate.

Please if any one knows how to get the file duration using DirectSound Please Help, i think we can got that from file info. but DirectSound provide such properties. any ideas


Re: Visual C# General Need help playing wave file.


Hi, Dominator Legend

You can get the buffer size this way. Suppose your SecondaryBuffer object is called sb; then the buffer size would be


And also, the sample rate, bits per sameple, and number of channels are stored in the corresponding variables,. You can easily calculate the duration like this:

int bytes_per_sample = sb.Format.BitsPerSample / 8;

int duration_in_sec = sb.Caps.BufferBytes / sb.Format.SamplesPerSecond / bytes_per_sample / sb.Format.Channels;

duration_in_sec is the duration in seconds.

Hope this be helpful~