cabgef
cabgef

Reputation: 1398

Windows Forms dotnet .wav playback - need to preload multiple wav files to memory for fast playback

I need to play back 30 second audio clips, 1 per second, in winforms dotnet. I am currently loading/playing the wav files from the filesystem, which works fine on a notebook, but is causing problems on a netbook. Can I pre-load all sound files into memory, if so how?

Upvotes: 0

Views: 1498

Answers (3)

Here's a recent example that creates a .wav file (a sine) in memory entirely from scratch and plays it. What you're trying to do should be much simpler, and you should be able to derive it from the sample posted.

Real low level sound generation in C#?

Upvotes: 0

Albin Sunnanbo
Albin Sunnanbo

Reputation: 47038

If you use the SoundPlayer to play your files you can preload the file with SoundPlayer.Load.

SoundPlayer sp = new SoundPlayer("filename");
sp.Load(); // preload
sp.Play();

Edit:
As noted by the documentation you may also use SoundPlayer.LoadAsync to load the sound in the background.

Upvotes: 1

MedicineMan
MedicineMan

Reputation: 15314

I'm inclined to say that you would load the file into a system.io.memorystream of some sort. Hopefully the libraries that play your file, will take a memorystream or memorystream can be converted into the data structure that this library takes.

Upvotes: 0

Related Questions