Previewing Audio Files
By Todd Thomas <tt@be.com>

Here's a quick little sample code ditty about bending a BFilePanel to suit your (hopefully not evil) needs. We've covered this subject in past articles, but we've never before combined it with (drum roll, please) The Game Kit!

Get the thrilling sample code for this article at <ftp://ftp.be.com/pub/samples/game_kit/SndFilePanel.zip>. I've tried to comment the source extensively, but feel free to mail me if you have any questions.

Submitted for your approval is the SndFilePanel class, which not only lets you peruse your file system for sound files, but lets you preview them as well, using the super easy BFileGameSound class. BFileGameSound is the ticket if you need to play a sound file quickly and painlessly. I've also provided a simple BApplication-based test harness to let you try out SndFilePanel.

Class SndFilePanel is a mostly standard derivation of BFilePanel, except I've mixed in BHandler via multiple inheritance so I can implement MessageReceived(). In MessageReceived, I handle events generated by the BButton added to the file panel to allow playing and stopping the BFileGameSound. For more info on fiddling with BFilePanel derivatives, consult <http://www-classic.be.com/aboutbe/benewsletter/volume_III/Issue38.html>.

Using BFileGameSound is easy, as I hope you can see from the source. A BFileGameSound instance is created in SndFilePanel::SelectionChanged(), upon finding a suitable file to preview. Playing and stopping the sound is handled in response to the appropriate message in SndFilePanel::MessageReceived(). For more info on using BFileGameSound, consult <http://www-classic.be.com/aboutbe/benewsletter/volume_III/Issue29.html>.

I said it was quick, right?
