【文章內(nèi)容簡介】
3 RealPlay = 4 End Enum Dim PlayType As PlayTypeName Enum AudioSource AudioStereo = 0 39。 stereo AudioLeft = 1 39。left AudioRight = 2 39。right End Enum Dim hWndMusic As Long Dim prevWndproc As Long 39。======================================================= 39。打開MCI設備,urlStr為網(wǎng)址,傳值代表成功與否 39。======================================================= Public Function OpenURL(urlStr As String, Optional hwnd As Long) As Boolean OpenMusic = False Dim MciCommand As String Dim DriverID As String CloseMusic 39。MCI命令 DriverID = GetDriverID(urlStr) If DriverID = RealPlayer Then PlayType = RealPlay Exit Function End If MciCommand = open amp。 urlStr amp。 type amp。 DriverID amp。 alias NOWMUSIC If DriverID = AVIVideo Or DriverID = MPEGVideo Or DriverID = MPEGVideo2 Then If hwnd 0 Then MciCommand = MciCommand + parent amp。 hwnd amp。 style child hWndMusic = GetWindowHandle prevWndproc = GetWindowLong(hWndMusic, 4) SetWindowLong hWndMusic, 4, AddressOf WndProc Else MciCommand = MciCommand + style overlapped End If End If RefInt = mciSendString(MciCommand, vbNull, 0, 0) mciSendString set NOWMUSIC time format milliseconds, vbNullString, 0, 0 If RefInt = 0 Then OpenMusic = True End Function 39。======================================================= 39。打開MCI設備,F(xiàn)ILENAME為文件名,傳值代表成功與否 39。======================================================= Public Function OpenMusic(FileName As String, Optional hwnd As Long) As Boolean OpenMusic = False Dim ShortPathName As String * 255 Dim RefShortName As String Dim RefInt As Long Dim MciCommand As String Dim DriverID As String CloseMusic 39。獲取短文件名 GetShortPathName FileName, ShortPathName, 255 RefShortName = Left(ShortPathName, InStr(1, ShortPathName, Chr(0)) 1) 39。MCI命令 DriverID = GetDriverID(RefShortName) If DriverID = RealPlayer Then PlayType = RealPlay Exit Function End If MciCommand = open amp。 RefShortName amp。 type amp。 DriverID amp。 alias NOWMUSIC If DriverID = AVIVideo Or DriverID = MPEGVideo Or DriverID = MPEGVideo2 Then If hwnd 0 Then MciCommand = MciCommand + parent amp。 hwnd amp。 style child hWndMusic = GetWindowHandle prevWndproc = GetWindowLong(hWndMusic, 4) SetWindowLong hWndMusic, 4, AddressOf WndProc Else MciCommand = MciCommand + style overlapped End If End If RefInt = mciSendString(MciCommand, vbNull, 0, 0) mciSendString set NOWMUSIC time format milliseconds, vbNullString, 0, 0 If RefInt = 0 Then OpenMusic = True End Function Function WndProc(ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long If Msg = amp。H202 Then MsgBox OK End If WndProc = CallWindowProc(prevWndproc, hwnd, Msg, wParam, lParam) End Function 39。======================================================= 39。根據(jù)文件名,確定設備 39。======================================================= Public Function GetDriverID(ff As String) As String Select Case UCase(Right(ff, 3)) Case MID, RMI, IDI GetDriverID = Sequencer Case WAV GetDriverID = Waveaudio Case ASF, ASX, IVF, LSF, LSX, P2V, WAX, WVX, .WM, WMA, WMX, WMP GetDriverID = MPEGVideo2 Case .RM, RAM, .RA GetDriverID = RealPlayer Case Else GetDriverID = MPEGVideo End Select End Function 39。====================================================== 39。播放文件 39。====================================================== Public Function PlayMusic() As Boolean Dim RefInt As Long PlayMusic = False RefInt = mciSendString(play NOWMUSIC, vbNull, 0, 0) If RefInt = 0 Then PlayMusic = True End Function 39。====================================================== 39。獲取媒體的長度 39。====================================================== Public Function GetMusicLength() As Long Dim RefStr As String * 80 mciSendString status NOWMUSIC length, RefStr, 80, 0 GetMusicLength = Val(RefStr) End Function 39。====================================================== 39。獲取當前播放進度 39。====================================================== Public Function GetMusicPos() As Long Dim RefStr As String * 80 mciSendString status NOWMUSIC position, RefStr, 80, 0 GetMusicPos = Val(RefStr) End Function 39。====================================================== 39。獲取媒體的當前進度 39。====================================================== Public Function SetMusicPos(Position As Long) As Boolean Dim RefInt As Long SetMusicPos = False RefInt = mciSendString(seek NOWMUSIC to amp。 Position, vbNull, 0, 0) If RefInt = 0 Then SetMusicPos = True End Function 39。====================================================== 39。暫停播放 39。====================================================== Public Function PauseMusic() As Boolean Dim RefInt As Long PauseMusic = False RefInt = mciSendString(pause NOWMUSIC, vbNull, 0, 0) If RefInt = 0 Then PauseMusic = True End Function 39。====================================================== 39。關閉媒體 39。====================================================== Public Function CloseMusic() As Boolean Dim RefInt As Long CloseMusic = False RefInt = mciSendString(close NOWMUSIC, vbNull, 0, 0) If RefInt = 0 Then CloseMusic = True End Function 39。====================================================== 39。設置聲道 39。====================================================== Public Function SetAudioSource(sAudioSource As AudioSource) As Boolean Dim RefInt As Long Dim strSource As String Select Case sAudioSource Case 1: strSource = left Case 2: strSource = right Case 0: strSource = stereo End Select SetAudioSource = False RefInt = mciSendString(setaudio NOWMUSIC source to amp。 strSource, vbNull, 0, 0) If RefInt = 0 Then SetAudioSource = True End Function 39。===========