Library code snippets
Add Quick MP3 Audio Functionality to your Programs
If you haven't heard of MP3, I would be surprised. It is now the format of choice for music and sounds, as it has relitively good quality, and small size. This tutorial will show you how to add a small MP3 player directly into your form, for background music or sound effects. The 'source' that is posted here is NOT what is described in this tutorial. It is an ActiveX control, that was made the same way. It includes a VB5/6 project and example program.
This tutorial will be using the Microsoft Multimedia Control (NOT Windows Media Player), and programmers who have used MCI before should recognize the process.
Side-Note: MP3 is the acronym for MPEG Layer 3, as it is closely related to MPEG 1/2 video.
Setting up the Form
- Add a new form to your project, or select the one that you would like to add the audio to.
- Right click on the toolbox, and click 'Components...'
- Add 'Microsoft Multimedia Control' (v6.0 in VB6) to the toolbox
- Put a new Multimedia control on the form
- Rename the control from 'MMControl1' to 'mmcMP3'
- Right click on the control on your form. In the properties view, disable and set visible to false for all buttons except for 'Play' and 'Pause'.
(NOTE: You can leave 'Stop' enabled, but it doesn't rewind, it just pauses)
It is time for some code!! Go to the add this code to your form. You can substitute the Form_Load event for any you deem suitable to start the audio.
Private Sub Form_Load
mmcMP3.DeviceType = "MPEGVideo" '\\Change MCI device type to MPEG
mmcMP3.Filename = "C:\Myaudio.Mp3" '\\designate file to be played
mmcMP3.Command = "Open" '\\Open file for playing
mmcMP3.Command = "Play" '\\Play file
End Sub
Private Sub Form_Unload
mmcMP3.Command = "Stop" '\\Stop playing the file
mmcMP3.Command = "Close" '\\Close the file
End Sub
Related articles
Related discussion
-
Build an MP3 Player
by Jameson (0 replies)
-
Run-time error '91'
by converter2009 (1 replies)
-
VB6 Runtime error 381 subsript out of range Error
by Uncle (2 replies)
-
passing and reading parameters from using Shell
by jigartoliya (0 replies)
-
Convert C++ code to VB6
by mawcot (4 replies)
Related podcasts
-
Christian Beauclair
14 mai 2008 (�mission #0074) ::.Christian Beauclair: Stratégies de migration VB6 vers .NET Nous discutons avec Christian Beauclair des stratégies de migration VB6 vers .NET. Entre autres, nous discutons comment utiliser le "VB 6 Code Advisor" et le "Interop Forms Toolkit" pour ajouter la puiss...
thank you, i have been looking everywhere for this, and it works!!!![Smiley Face [:)]](/emoticons/emotion-1a.gif)
![Big Smile [:D]](/emoticons/emotion-2a.gif)
do you also know how to have multiple music files, and the program runs throught them all one at a time, if you do i would be very gratefull
thanks for all your help
Well, this would be very helpful if it still applied to visual studio.net, unfortunately it doesn't. Any word on where I can find an updated version of this article that works for visual studio.net?
Learning
Professional
Enterprise.
Is there a standard version before the Pro one?
Anyway nice and simple.
This thread is for discussions of Add Quick MP3 Audio Functionality to your Programs.