»áÔ±£º ÃÜÂ룺 ¡¡Ãâ·Ñ×¢²á | Íü¼ÇÃÜÂë | »áÔ±µÇ¼ ÍøÒ³¹¦ÄÜ£º ¼ÓÈëÊÕ²Ø ÉèΪÊ×Ò³ ÍøÕ¾ËÑË÷  
 °²È«¼¼Êõ¼¼ÊõÎĵµ
  ¡¤ °²È«ÅäÖÆ
  ¡¤ ¹¤¾ß½éÉÜ
  ¡¤ ºÚ¿Í½Ìѧ
  ¡¤ ·À»ðǽ
  ¡¤ Â©¶´·ÖÎö
  ¡¤ ÆƽâרÌâ
  ¡¤ ºÚ¿Í±à³Ì
  ¡¤ ÈëÇÖ¼ì²â
 °²È«¼¼ÊõÂÛ̳
  ¡¤ °²È«ÅäÖÆ
  ¡¤ ¹¤¾ß½éÉÜ
  ¡¤ ·À»ðǽ
  ¡¤ ºÚ¿ÍÈëÇÖ
  ¡¤ Â©¶´¼ì²â
  ¡¤ Æƽⷽ·¨
  ¡¤ É±¶¾×¨Çø
 °²È«¼¼Êõ¹¤¾ßÏÂÔØ
  ¡¤ É¨Ã蹤¾ß
  ¡¤ ¹¥»÷³ÌÐò
  ¡¤ ºóÃÅľÂí
  ¡¤ ¾Ü¾ø·þÎñ
  ¡¤ ¿ÚÁîÆƽâ
  ¡¤ ´úÀí³ÌÐò
  ¡¤ ·À»ðǽ
  ¡¤ ¼ÓÃܽâÃÜ
  ¡¤ ÈëÇÖ¼ì²â
  ¡¤ ¹¥·ÀÑÝʾ
¼¼ÊõÎĵµ > VBÎĵµ > ¶àýÌå
MCIÃüÁîÏê½â
·¢±íÈÕÆÚ£º2002-09-13 00:00:00×÷ÕߣºÀ ³ö´¦£º  

MCIÃüÁîÏê½â

'ÓÃMCIÃüÁîÀ´ÊµÏÖ¶àýÌåµÄ²¥·Å¹¦ÄÜ

'ÏÂÃæµÄÄÚÈݼ¸ºõÓв¥·ÅÆ÷Èí¼þµÄ¸÷ÖÖ¹¦ÄÜ£¬ÄãÖ»ÊÇÒýÓÃÕâЩº¯Êý¾ÍÄÜ×ö³öÒ»¸ö²¥·ÅÆ÷À´

'

Public 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 Long

Public Declare Function mciGetDeviceID Lib "winmm.dll" Alias "mciGetDeviceIDA" (ByVal lpstrName As String) As Long

Public Declare Function waveOutGetVolume Lib "winmm.dll" (ByVal uDeviceID As Long, lpdwVolume As Long) As Long

Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long

Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long

Public Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long

Enum PlayTypeName

  File = 1

  CDAudio = 2

  VCD = 3

  RealPlay = 4

End Enum

Dim PlayType As PlayTypeName

Enum AudioSource

  AudioStereo = 0 ' "stereo"

  AudioLeft = 1 '"left"

  AudioRight = 2 '"right"

End Enum

Dim hWndMusic As Long

Dim prevWndproc As Long

'=======================================================

'´ò¿ªMCIÉ豸£¬urlStrΪÍøÖ·,´«Öµ´ú±í³É¹¦Óë·ñ

'=======================================================

Public Function OpenURL(urlStr As String, Optional hwnd As Long) As Boolean

  OpenMusic = False

  Dim MciCommand As String

  Dim DriverID As String

  

  CloseMusic

   'MCIÃüÁî

  DriverID = GetDriverID(urlStr)

  If DriverID = "RealPlayer" Then

    PlayType = RealPlay

    Exit Function

  End If

  MciCommand = "open " & urlStr & " type " & DriverID & " alias NOWMUSIC"

  

  If DriverID = "AVIVideo" Or DriverID = "MPEGVideo" Or DriverID = "MPEGVideo2" Then

    If hwnd <> 0 Then

      MciCommand = MciCommand + " parent " & hwnd & " 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

'=======================================================

'´ò¿ªMCIÉ豸£¬FILENAMEΪÎļþÃû,´«Öµ´ú±í³É¹¦Óë·ñ

'=======================================================

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

  '»ñÈ¡¶ÌÎļþÃû

  GetShortPathName FileName, ShortPathName, 255

  RefShortName = Left(ShortPathName, InStr(1, ShortPathName, Chr(0)) - 1)

  'MCIÃüÁî

  DriverID = GetDriverID(RefShortName)

  If DriverID = "RealPlayer" Then

    PlayType = RealPlay

    Exit Function

  End If

  MciCommand = "open " & RefShortName & " type " & DriverID & " alias NOWMUSIC"

  

  If DriverID = "AVIVideo" Or DriverID = "MPEGVideo" Or DriverID = "MPEGVideo2" Then

    If hwnd <> 0 Then

      MciCommand = MciCommand + " parent " & hwnd & " 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 = &H202 Then

  MsgBox "OK"

  End If

  WndProc = CallWindowProc(prevWndproc, hwnd, Msg, wParam, lParam)

End Function

'=======================================================

'¸ù¾ÝÎļþÃû£¬È·¶¨É豸

'=======================================================

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

'======================================================

'²¥·ÅÎļþ

'======================================================

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

'======================================================

'»ñȡýÌåµÄ³¤¶È

'======================================================

Public Function GetMusicLength() As Long

  Dim RefStr As String * 80

  mciSendString "status NOWMUSIC length", RefStr, 80, 0

  GetMusicLength = Val(RefStr)

End Function

'======================================================

'»ñÈ¡µ±Ç°²¥·Å½ø¶È

'======================================================

Public Function GetMusicPos() As Long

  Dim RefStr As String * 80

  mciSendString "status NOWMUSIC position", RefStr, 80, 0

  GetMusicPos = Val(RefStr)

End Function

'======================================================

'»ñȡýÌåµÄµ±Ç°½ø¶È

'======================================================

Public Function SetMusicPos(Position As Long) As Boolean

  Dim RefInt As Long

  SetMusicPos = False

  RefInt = mciSendString("seek NOWMUSIC to " & Position, vbNull, 0, 0)

  If RefInt = 0 Then SetMusicPos = True

End Function

'======================================================

'ÔÝÍ£²¥·Å

'======================================================

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

'======================================================

'¹Ø±ÕýÌå

'======================================================

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

'======================================================

'ÉèÖÃÉùµÀ

'======================================================

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 " & strSource, vbNull, 0, 0)

  If RefInt = 0 Then SetAudioSource = True

End Function

'======================================================

'È«ÆÁ²¥·Å

'======================================================

Public Function PlayFullScreen() As Boolean

  Dim RefInt As Long

  PlayFullScreen = False

  RefInt = mciSendString("play NOWMUSIC fullscreen", vbNull, 0, 0)

  If RefInt = 0 Then PlayFullScreen = True

End Function

'=====================================================

'ÉèÖÃÉùÒô´óС

'=====================================================

Public Function SetVolume(Volume As Long) As Boolean

  Dim RefInt As Long

  SetVolume = False

  RefInt = mciSendString("setaudio NOWMUSIC volume to " & Volume, vbNull, 0, 0)

  If RefInt = 0 Then SetVolume = True

End Function

'=====================================================

'ÉèÖò¥·ÅËÙ¶È

'=====================================================

Public Function SetSpeed(Speed As Long) As Boolean

  Dim RefInt As Long

  SetSpeed = False

  RefInt = mciSendString("set NOWMUSIC speed " & Speed, vbNull, 0, 0)

  If RefInt = 0 Then SetSpeed = True

End Function

'====================================================

'¾²ÒôTrueΪ¾²Òô£¬FALSEΪȡÏû¾²Òô

'====================================================

Public Function SetAudioOnOff(AudioOff As Boolean) As Boolean

  Dim RefInt As Long

  Dim OnOff As String

  SetAudioOff = False

  If AudioOff Then OnOff = "off" Else OnOff = "on"

  RefInt = mciSendString("setaudio NOWMUSIC " & OnOff, vbNull, 0, 0)

  If RefInt = 0 Then SetAudioOff = True

End Function

'====================================================

'ÊÇ·ñÓл­ÃæTrueΪÓУ¬FALSEΪȡÏû

'====================================================

Public Function SetWindowShow(WindowOff As Boolean) As Boolean

  Dim RefInt As Long

  Dim OnOff As String

  SetWindowShow = False

  If WindowOff Then OnOff = "show" Else OnOff = "hide"

  RefInt = mciSendString("window NOWMUSIC state " & OnOff, vbNull, 0, 0)

  If RefInt = 0 Then SetWindowShow = True

End Function

'====================================================

'»ñµÃµ±Ç°Ã½ÌåµÄ״̬ÊDz»ÊÇÔÚ²¥·Å

'====================================================

Public Function IsPlaying() As Boolean

  Dim sl As String * 255

  mciSendString "status NOWMUSIC mode", sl, Len(sl), 0

  If Left(sl, 7) = "playing" Or Left(sl, 2) = "²¥·Å" Then

    IsPlaying = True

  Else

    IsPlaying = False

  End If

End Function

'====================================================

'»ñµÃ²¥·Å´°¿ÚµÄhandle

'====================================================

Public Function GetWindowHandle() As Long

  Dim RefStr As String * 160

  mciSendString "status NOWMUSIC window handle", RefStr, 80, 0

  GetWindowHandle = Val(RefStr)

End Function

'====================================================

'»ñÈ¡DeviceID

'====================================================

Public Function GetDeviceID() As Long

  GetDeviceID = mciGetDeviceID("NOWMUSIC")

End Function

 

¡¾·µ»Ø¶¥²¿¡¿ ¡¾´òÓ¡±¾Ò³¡¿ ¡¾¹Ø±Õ´°¿Ú¡¿

¹ØÓÚÎÒÃÇ / ¸øÎÒÁôÑÔ / °æȨ¾Ù±¨ / Òâ¼û½¨Òé / ÍøÕ¾±à³ÌQQȺ   
Copyright ©2003- 2024 Lihuasoft.net webmaster(at)lihuasoft.net ¼ÓÔØʱ¼ä 0.00166