No external controls make multimedia player (i)

Source: Internet
Author: User
Tags exit goto
Controls | media
Using the MCI directive to make the player, simple and practical, well suited to be a side function or background music for your own software, it is based on this need that I am prepared to write in a few parts:

1, the MCI instruction simple use;
2, the media playback Progress control and volume adjustment;
3, the reading of music information, including MP3 (ID3v1 & ID3v2) and ASF (WMA & WMV) and so on;
4, the establishment and preservation of music list (m3u format)

Originally want to write play music, give a video example, no other meaning, just feel playing music is simple, there is nothing to write, but also in order to show that MCI video is also possible.

Private Const ws_child = &h40000000
Private Declare Function mcisendstring Lib "Winmm.dll" Alias "Mcisendstringa" (ByVal Lpstrcommand as String, ByVal Lpstrre Turnstring as String, ByVal ureturnlength as Long, ByVal Hwndcallback as long) as long
Private Declare Function getshortpathname Lib "kernel32" Alias "Getshortpathnamea" (ByVal Lpszlongpath as String, ByVal LP Szshortpath as String, ByVal Cchbuffer as Long
Private Declare Function setwindowpos Lib "user32" (ByVal hWnd as Long, ByVal hwndinsertafter as Long, ByVal X as Long, by Val y as Long, ByVal CX as Long, ByVal Cy as Long, ByVal wflags as long) as long
Private Function shortname (LName As String) as String
' Get 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 = mciSendString (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 long
Dim I as Long, s as String
If Dir (strFileName, Vbhidden or vbreadonly or vbsystem) = vbNullString or strFileName = vbNullString Then 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 returned to the handle of the video window
Exit Function
Fail
PLAYMCI "Close Song"
End Function

Private Sub Cmdplay_click ()
I=showvideo ("h:\1.wmv", Me.hwnd, 0, 0, 100, 100)
' Return this handle, very useful, can be used to move the window position, or subclass it, plus pop-up menu, response mouse action, etc.
If I <> 0 Then
cmdplay.enabled = False
cmdstop.enabled = True
End If
End Sub
Private Sub Cmdstop_click ()
PLAYMCI "Close Song"
cmdplay.enabled = True
cmdstop.enabled = False
End Sub

Private Sub Form_Load ()
Me.scalemode = 3
cmdplay.enabled = True
cmdstop.enabled = False
Cmdplay.caption = "Play"
Cmdstop.caption = "Stop"
End Sub
Private Sub form_unload (Cancel as Integer)
PLAYMCI "Close Song"
End Sub




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.