Making the MCI command to make a player, simple and practical, is very suitable for a feature or background music for its own software, is based on this requirement, I am ready to write:
1. Simple use of the MCI directive; 2, the progress control and volume adjustment of the media playback; 3, the reading of music information, including MP3 (ID3V1 & ID3V2) and ASF (WMA & WMV), etc .; 4, the establishment of music list Save (M3U format)
It was mainly to write music, and the example of playing video, there is nothing else, but I feel that playing music is simple, there is nothing to write, but also to illustrate, MCI is also possible.
Private Const WS_CHILD = & H40000000Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Long, ByVal hwndCallback As Long) As LongPrivate Declare Function GetShortPathName Lib "kernel32" Alias " GetShortPathNameA "(ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Long) As LongPrivate Declare Function SetWindowPos Lib" user32 "(ByVal hWnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, Byval Cy As Long, Byval Wflags As Long AS Longprivate Function ShortName (Lname AS String) AS String 'Number of short file name DIM S AS STRING, I as long i = 512 s = space $ (i) getshortpathname lname, S, I ShortName = Left $ (S, INSTR (1, S, VBnullchar) - 1) end function
Private Function Playmci (CMD As String, Optional Returnstr As String) As long 'play MCI Dim s AS String S = Space $ (256) Playmci = McIndString (CMD, S, 256, 0) Returnstr = Left $ (S, Instr 1, S, VBNULLCHAR) - 1) End function
Private Function ShowVideo (Strfilename As String, HWD As Long, X As Long, Y As Long, W AS Long, H AS Long) AS String If Dir (StringName, Vbhidden or VBreadOrthly or vbsystem) = vbnullstring or strfilename = vbnullstring the exit function i = playmci ("Open" "& ShortName (StrfileName) &" Alias Song Parent "& HWD &" STYLE "& WS_CHILD &" Wait ") IF i <> 0 THEN EXIT Function I = Playmci ("Status Song Window Handle Wait", S) IF i <> 0 Then Goto Fail i = Val (s) if i = 0 Then Goto Fail SetWindowPos I, 0, X, Y, W, H, 0 Playmci "Play Song" showvideo = I 'If successfully returns the handle of the video window EXIT FUNCTIONFAIL: Playmci "Close Song" end functionprivate subdplay_click () i = showvideo ("h: h: h: h: h: h: h :wmv", me.hwnd, 0, 0 , 100, 100) 'Returned, very useful, can be used for mobile window location, or subclass it, plus pop-up menu, respond to I <> 0 Then cmdplay.enabled = false cmdstop.Enabled = true cmdplay.enable, etc. Endness subprivate sub cmdstop_click () Playmci "close song" cmdplay.enabled = true cmdsto p.enabled = false
Private Sub Form_Load () Me.ScaleMode = 3 cmdPlay.Enabled = True cmdStop.Enabled = False cmdPlay.Caption = "Play" cmdStop.Caption = "stop" End SubPrivate Sub Form_Unload (Cancel As Integer) PlayMCI "close Song" End Sub