Topic: VBOgg
Play OGG files from Visual Basic
Version 1.03 Note: This version fixes a bug where attempting to play an invalid Ogg file would cause the dll to crash hard (and take the VB IDE with it). Additionally, PlayOggFile() now returns true if it successfully loaded and started a valid Ogg file, and false otherwise. See the included readme for previous version info.
Ogg Vorbis is a good alternative to MP3 for sound effects and music, offering compression and quality that is just as good, but without the royalty costs. The DLLs are not bad to work with, but really leave VB developers out in the cold. It's not a simple task to pass a FILE object from VB to C++, for example.
The VBOgg.dll addresses this. We came across a small C++ clas that encapsulates much of the tedium of playing an Ogg file. We also have no idea who wrote the oggplayer class on which this dll is based, so if you know, please inform us so we can assign appropriate credit. With a little cleanup, the oggplayer class did a good job of loading and playing streaming Ogg data (IE: the entire file is not loaded all at once, but rather bits at a time).
VBOgg adds one more layer of encapsulation to provide a clean interface to Visual Basic. Here are the supported function declarations:
Private Declare Function InitOgg Lib "vbogg.dll" _
(ByVal HWND As Long, ByVal IsGlobal As Long) As Long
Private Declare Function PlayOggFile Lib "vbogg.dll" _
(ByVal FileName As String) As Long
Private Declare Function OggIsPlaying Lib "vbogg.dll" _
() As Long
Private Declare Function StopOgg Lib "vbogg.dll" _
() As Long
Private Declare Function UpdateOgg Lib "vbogg.dll" _
() As Long
Private Declare Function CloseOgg Lib "vbogg.dll" _
() As Long
Private Declare Function SetOggVolume Lib "vbogg.dll" _
(ByVal Volume As Long) As Long
Private Declare Function SetOggPan Lib "vbogg.dll" _
(ByVal Position As Long) As LongThey're pretty straightforward, except possibly for UpdateOgg. You see, since this is streaming the file, every now and then it needs to check to see if it's time to load the next chunk into one of its buffers. (It actually has two buffers, and alternates between them.) So, you need to make this call occasionally from VB to make the streaming work. The example code does that from a Timer interval of 1000, which seems to work well enough.
The C++ source code is included, but you'll need the Vorbis SDK to compile it. vorbisfile_static.lib, vorbis_static.lib, ogg_static, and dsound.lib will have to be linked to your project to successfully compile. (It uses DirectSound for access to the sound card.)
VBOgg will load and play a single Ogg file. There are no multiple channels, and the sound doesn't any other "tricks." The included VB project does pretty much everything the DLL supports. In other words, if you want it to do more, you'll have to do the code yourself (and let us have a copy to play with, of course).
Download
VBOgg is available here. The download includes the source code, so have a crack at it. And, it's utterly FREE.
Support
You can ask a question in the Freebies section of our Forums. Requests for enhancements go there also, as well as general help on using it in your VB program.
Alternatively, you can support US. We aren't charging anyone for VBOgg, but it does take time to answer questions and add features...and money to provide the hosting. If you are grateful for VBOgg, please feel free to donate to its continued use and development.