Joined: 17 Jun 2009
|Posted: Sat Mar 12, 2011 5:35 pm Post subject: Playing/Embedding XM and MOD files in Visual Basic 6
|Alright, this is done with BASS 2.4
Below, I have posted a link for project download.
This brief tutorial will teach you how to embed XM files into your Visual Basic 6 application and play them in the background. The modules and functions used in this project are NOT made by me. I simply reshaped the existing project found on the website to fit the need of playing files from resource.
You need to copy the Bass.dll file to your System 32 folder and register it.
This project is actually quite simple.
Enabling VB6 Resource Editor:
First of all, you need to add resources to your VB6 project.
Go to Add-Ins>Add-In Manager> Scroll down and click on VB 6 Resource Editor> Check Loaded/Unloaded> OK
A window should pop up. Also, a new green button that looks like a registry cube with a hand over it should pop up in the toolbar.
Adding Resources to your Project:
In the VB Resource Editor window, click on the Add Custom Resource button. (To the right of the image button)
Now add your resource XM files one by one.
Adding the appropriate Modules:
Below, in this post, I have a link that has the modules needed to play XM files. (You can also download the project containing the modules from the original BASS website.)
Add these modules to the project:
Setting up the form:
Double-Click on the form, Scroll down to the very bottom, and paste this code:
The first sub is the "main function" that plays the file.
The second one checks if the correct BASS dll was loaded, and starts digital output.
The third one will check if you're running in IDE or EXE modes.
And the last one will make sure it's unloaded properly.
Also, add this API at the top of the project:
It's used for detecting if the project is running in IDE or EXE mode/container.
Go back to your form, create a button, paste this code inside the button:
This will play resource index 101 of the "CUSTOM" branch of resources.
Stopping the music:
If you want to stop the music, simply call these functions:
How Play_File Sub works:
Three variables are used here: chan, DataLength, and DataStore
DataLength is the size of the music file. It is needed to properly allocate the size of the array of bytes.
DataStore is an array of bytes that holds the music file. It retrieves the resource as an array of bytes which will be used in playing the file.
chan is a stream or music handle that holds the music stream. It is then used in the function BASS_ChannelPlay to finally output the music.
Download Project (Contains Source Files + Modules + XM Music + Bass.dll + EXE)