Current location - Music Encyclopedia - NetEase Cloud Music - Doubt of making music player with vb6.0
Doubt of making music player with vb6.0
Add an MMC control!

Music player

Music player

Media player control (MCI) can play audio and video, that is, music and DVD.

Create a new folder under the root directory of D: disk and rename it music. Copy three music files into it, one Wav file is renamed as 1, the other Mp3 file is renamed as 2, and then copy the thr video file in lesson 10. This is an Avi file.

Start VB, modify the form properties, add labels, and change the title to "My Player".

MCI control should be added to the toolbox by right-clicking the toolbox, selecting Components, finding Microsoft Multimeia Control6.0 in the dialog box, and then clicking OK to add the multimedia control MMControl to the toolbox.

Find the MMControl control (the last one) in the toolbox, select it and draw one on the form. You can find that there are playing, stopping, pausing, fast forwarding, playing a CD and so on, just like our common device symbols. Save the file to your own folder and name it "Music Player".

Since the player is virtual, you need to set the display properties. Right-click the multimedia control in the form, select Properties from the pop-up menu, select the Control tab at the top of the pop-up dialog box, check the valid options next to each button symbol, and then click OK to return to the form. In this case, you can use the control.

Click the start button to run, and the player in the window is still empty, because there are no files to play.

Close the program and return to the form window, add a frame Fram 1, add three radio button options to it, set Caption to Wav, Mp3 and Avi respectively, and then modify the background color.

Let's add code to open the player, play the specified file, double-click the form, and add code to initialize the player in the process of Form_Load ():

MMcontrol 1。 Notify=False' does not return playback information.

MMcontrol 1。 Wait=True' Others wait while playing.

Select Option 1 from the list on the left at the top of the code window, and then click Auto on the right. Add the code to play Wav in the pop-up Option_Click ():

Mmcontrol1.command = "close"' Close the player first.

MMControl 1。 Device type = "wave audio"' wav audio format.

The one. wav file in the mmcontrol1.filename = "d: \ music \ one.wav"' folder.

MMControl 1。 Command = "open "'open the device.

MMControl 1。 Command = "play "'plays the file.

The function of each line of code is mentioned in the green comments. The last sentence is used to play automatically, which is equivalent to clicking the "play" button of the player. When playing, there must be a file name and a play command.

Also find the Click () procedure of Option2 and add the code to play MP3:

Mmcontrol1.command = "close"' Close the player first.

MMControl 1。 DeviceType = ""Other types.

Files in the mmcontrol1.filename = "d: \ music \ two.mp3"' folder.

MMControl 1。 Command = "open "'open the device.

MMControl 1。 Command = "play "'You can also click the play button.

The Mp3 format here is a compressed format and belongs to other types. The others, like Wav files, are all sound files, with no images, only music.

Note that option 3 is slightly different. It is an Avi video format, that is, it has both sound and images. Its Click () code is:

Mmcontrol1.command = "close"' Close the player first.

Mm control1.devicetype = "avi video"' avi video format.

Use the background form as the screen.

The thr. avi file in the mmcontrol1.filename = "d: \ music \ thr.avi"' folder.

MMControl 1。 Command = "open "'open the device.

MMControl 1。 Command = "play "'You can also click the play button.

The third line of code here is to display the video image in the background. You can also add a picture frame and change the format of 1 to PIcture 1. Note that the ratio of images is generally 4:3 or 16:9.

Check the code and pay attention to the correctness of punctuation and capitalization in Chinese and English. Save the file.

Click the "Start" button to run the program, click files in different formats to play music, and see the powerful functions of our multimedia player. Pay attention to rewind the tape when playing it repeatedly, and click "rewind" to play it again. Be sure to turn off the device before quitting, that is, the "close" command.

The whole code is:

Private Sub command 1_Click ()' exits the program.

Mm control1.command = "close"' Turn off the player device.

MMControl 1。 Shareable = true' Allow others to use the player.

end

End joint

Double-click Private Sub Form_DblClick ()' to exit.

Mmcontrol1.command = "close"' Close the player.

MMControl 1。 Shareable = True

end

End joint

Private Sub-Form _Load ()

MMControl 1。 Notify = False' does not return playback information.

MMControl 1。 Wait = True' Wait while others are playing.

End joint

Private subform _ unload (cancel as integer)' Close the window.

Mmcontrol1.command = "close"' Close the player.

MMControl 1。 Shareable = True

End joint

Private suboption 1_Click ()

Mmcontrol1.command = "close"' Close the player first.

MMControl 1。 Device type = "wave audio"' wav audio format.

Files in the mmcontrol1.filename = "d: \ music \ one.wav"' folder.

MMControl 1。 Command = "open "'open the device.

MMControl 1。 Command = "play "'plays the file.

End joint

Private suboption 2_Click ()

Mmcontrol1.command = "close"' Close the player first.

MMControl 1。 DeviceType = ""Other types.

Mmcontrol1.filename = "d: \ music \ two.mp3"' files in the current folder.

MMControl 1。 Command = "open "'open the device.

MMControl 1。 Command = "play "'You can also click the play button.

End joint

Private suboption 3_Click ()

Mmcontrol1.command = "close"' Close the player first.

Mm control1.devicetype = "avi video"' avi video format.

Use the background form as the screen.

Files in the mmcontrol1.filename = "d: \ music \ thr.avi"' folder.

MMControl 1。 Command = "open "'open the device.

MMControl 1。 Command = "play "'You can also click the play button.

End joint