The playback of the MP3 music file can be easily implemented using the API function [McISendstring]. Below this program implements most of the normal operations of MP3 playback, modify it, make a 100KB size MP3 player is easy
Start the VB program, place 6 command buttons on the form, three tags, one public dialog, a progress bar, a status bar, and a timer, the window is arranged, please refer to the drawings
Button "Open MP3 file" is used to open the dialog box to select the MP3 file, the other 5 buttons are Play, Pause, PAUSE, Stopplay, Back (backward), prew (forward jump ). Label1 is used to represent the current time of the song; the Label2 is placed on the left side of the time: 00:00 "; Lable3 is placed on the right side of the time, used to represent the total song.
Below you can write code. First mciSendString Lib "winmm.dll" Alias "mciSendStringA" in the "general declaration" declare function section of the form Private Declare Function (Byval lpstrCommand As String, ByVal lpstrRetumString As String, ByVal uReturnLength As long, ByVal hwndCallback as long) As longDim mfn As string
The following is the code for each object: Private Sub Form_load () mfn = "" play.Enabled = Falsepause.Enabled = FalseStopplay.Enabled = Falseback.Enabled = Falseprew.Enabled = FalseTimer1.Enabled = FalseTimer1.Interval = 500End Sub
Private Sub open_Click () On Error Goto errWith CommonDialog1.CancelError = True.Filter = "music files | * .mp3;.. * Wav; * mid" .Flags = cdlOFNNoChangeDir And cdlOFNPathMustExist.Action = 1stopplay_Click 'stop button while the device is initialized MFN = .filename 'This program is named in the file must not be space form1.caption = .fileNamePlay.enabled = truend withplay_clickexit suberr: End Sub
Private sub plan_click () on error resume nextdim t as longt = mcIndstring ("Open" MFN, 0 &, 0, 0) 'Open's space must not be lost DIM RET AS STRING * 128T = MCISENDSTRING ("status" mfn "Length", RET, 128, 0) 'Show the total length of the song RET = Left (RET, 8) IF RET <> "" "" "" "" "", "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" " ) End ifPlay.enabled = falsePause.enabled = trueback.enabled = trueprew.enabled = truet = mcIndstring ("Status" MFN "MODE", RET, 128, 0) 'Get the current state of the device, is Play or pause, RET = Left (RET, 8) statusbar1.panels (1) .text = RET 'In the status bar display play status T = McISendString ("Play" MFN "Form" Str (Progressbar1.Value) 0 &, 0, 0) 'Start playing Timer1.enabled = truend subsprivate sub pause_click () T% = mcIndstring ("Pause" MFN, 0 &, 0, 0)' issues a paused command play.enable = truepause.enabled = FalseStopplay.enabled = trueback.enabled = falseprew.enabled = falsend sub
Private sub stopplay_click () T% = mcIndstring ("STOP" MFN, 0 &, 0, 0) T% = mcIndstring ("Close" MFN, 0 &, 0, 0) 'Stop play play.enabled = truepause.enabled = FalseStopPlay.enabled = falseback.enabled = falseprew.enabled = false
Private sub back_click () T% = mcisndstring ("Play" MFN "from" Str (ProgressBar1.Value- (ProgressBar1.max / 10)), 0 &, 0, 0) 'backwards in a small segment and then playing END Sub
Private sub prew_click () T% = mcisndstring ("Play" MFN "from" stri (ProgressBar1.Value ), 0 &, 0, 0) 'Go forward a small segment Play End Sub
Private sub timer1_timer () DIM T As Longdim Ret As String * 128t = McIndstring ("status" mfn "position", ret, 0, 0) 'Get the current play location RET = Left (RET, 8) Progressbar1.Value = Val (RET) Label1.caption = getTime (Val (RET)) 'Show song Current Time if ProgressBar1.Value = ProgressBar1.max TenStopplay_Clickend Ift = McISendString ("Status" MFN "MODE", RET, 128, 0) RET = Left (RET, 8) statusbar1.panels (1) .text = Retend Subprivate Sub Form_Unload (Cacel AS Integer) T% = McIndstring ("STOP" MFN, 0 &, 0, 0) T% = McISendString ("Close" MFN, 0 &, 0, 0) End Sub
The function of this function is the function of this function to convert the time indicated by long integer to electronic clock "**: **" DIM min, second = position / 1000min = min / 60sec = Min-int (min) min = int (min) sec = 60 * sec / 100sec = int (sec *00) gettime = str (min) ": STR (sec) End function
The five control buttons in the figure, actually set the font to "WebDings", allowing their CAPTION attributes to "4" ";" "<" "7" "8" can