We need you!

We're working hard on the next version of Developer Fusion. Let us know what you think we should be up to!

Members

Technology Zones

Articles

Hosted By

MaximumASP

Info

Rated
Read 23,668 times

Downloads

Related Categories

Add Quick MP3 Audio Functionality to your Programs

VB6FREAK

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

  1. Add a new form to your project, or select the one that you would like to add the audio to.
  2. Right click on the toolbox, and click 'Components...'
  3. Add 'Microsoft Multimedia Control' (v6.0 in VB6) to the toolbox
  4. Put a new Multimedia control on the form
  5. Rename the control from 'MMControl1' to 'mmcMP3'
  6. 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

Was born. Now is living.

Comments

  • Re: [3123] Add Quick MP3 Audio Functionality to your Programs

    Posted by Misty on 22 Aug 2007

    thank you, i have been looking everywhere for this, and it works!!![:)][:D]


    do you also know how to have multiple music files, and the program runs throught them all one at a time, if you d...

  • Re: [3123] Add Quick MP3 Audio Functionality to your Programs

    Posted by Dr.L!qUiD on 29 Jul 2006

    does not work for me and i have vb6 pro i would really like this to? :( :(

  • Posted by happyoutkast on 10 Nov 2005

    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?

  • Posted by Smile005 on 14 Jan 2004

    I was under the impression that there were three flavours of VB (this is VB6 BTW)
    Learning
    Professional
    Enterprise.
    Is there a standard version before the Pro one?

  • Posted by James Crowley on 14 Jan 2004

    hmm... what about VB "Standard" ?