ªð¦^¦Cªí ¤W¤@¥DÃD µo©«

[µo°Ý] WindowsMediaPlayer¼½©ñ­µÀÉ°ÝÃD

¦^´_ 1# lshsien
¥¿¦p Joforn ¤j¤j©Ò´£¥Üªº¡A¥H¤Uªº
¥N½X¤£»Ý­n MediaPlayer ªº¤ä´©±±¥ó¡C
¦pªG§A¸û²ßºD¨Ï¥Î MediaPlayer ±±¥ó
¨º»ò§A«K¥i¥H¤£¥Î©¹¤U¾\Äý¤F¡C
  1. Option Explicit

  2. Private Const SND_APPLICATION = &H80         '  look for application specific association
  3. Private Const SND_ALIAS = &H10000            '  name is a WIN.INI [sounds] entry
  4. Private Const SND_ALIAS_ID = &H110000        '  name is a WIN.INI [sounds] entry identifier
  5. Private Const SND_ASYNC = &H1                '  play asynchronously
  6. Private Const SND_FILENAME = &H20000         '  name is a file name
  7. Private Const SND_LOOP = &H8                 '  loop the sound until next sndPlaySound
  8. Private Const SND_MEMORY = &H4               '  lpszSoundName points to a memory file
  9. Private Const SND_NODEFAULT = &H2            '  silence not default, if sound not found
  10. Private Const SND_NOSTOP = &H10              '  don't stop any currently playing sound
  11. Private Const SND_NOWAIT = &H2000            '  don't wait if the driver is busy
  12. Private Const SND_PURGE = &H40               '  purge non-static events for task
  13. Private Const SND_RESOURCE = &H40004         '  name is a resource name or atom
  14. Private Const SND_SYNC = &H0                 '  play synchronously (default)

  15. #If VBA7 Then
  16.     Private Declare PtrSafe Function PlaySoundA Lib "winmm.dll" (ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long
  17.     '  ¥H¤W«Y .Wav Àɤ§°Ñ¼Æ«Å§i¡F ¤U¦C¤T¦æ¬° .MP3 Àɮ׫ŧi¤§¤Þ¥Î¥\¯à¨ç¦¡¤ÎÅܼƫŧi¡C
  18.     Private Declare PtrSafe 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
  19.     Private Declare PtrSafe Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long
  20. #Else
  21.     Private Declare Function PlaySoundA Lib "winmm.dll" (ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long
  22.     '  ¥H¤W«Y .Wav Àɤ§°Ñ¼Æ«Å§i¡F ¤U¦C¤T¦æ¬° .MP3 Àɮ׫ŧi¤§¤Þ¥Î¥\¯à¨ç¦¡¤ÎÅܼƫŧi¡C
  23.     Private 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
  24.     Private Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long
  25. #End If

  26. Dim Mp3File, LastMp3File As String, lst() As String, idx As Long

  27. Sub Ex()
  28.     Dim cnt As Long
  29.    
  30.     idx = 0
  31.     addList (ThisWorkbook.Path & "\" & "±`¥Î¼s¼½" & "\" & "°ê»y_¦U¦ì®È«È±z¦n.wav")
  32.     addList (ThisWorkbook.Path & "\" & "±`¥Î¼s¼½" & "\" & "°ê»y_6ÂI.wav")
  33.     addList (ThisWorkbook.Path & "\" & "±`¥Î¼s¼½" & "\" & "°ê»y_¤À50.wav")
  34.     addList (ThisWorkbook.Path & "\" & "±`¥Î¼s¼½" & "\" & "°ê»y_¤À.wav")
  35.     addList (ThisWorkbook.Path & "\" & "±`¥Î¼s¼½" & "\" & "°ê»y_¶}©¹.wav")
  36.     addList (ThisWorkbook.Path & "\" & "±`¥Î¼s¼½" & "\" & "°ê»y_¥x¥_ªº.wav")
  37.     addList (ThisWorkbook.Path & "\" & "±`¥Î¼s¼½" & "\" & "°ê»y_¨®¦¸5.wav")
  38.     addList (ThisWorkbook.Path & "\" & "±`¥Î¼s¼½" & "\" & "°ê»y_¨®¦¸0.wav")
  39.     addList (ThisWorkbook.Path & "\" & "±`¥Î¼s¼½" & "\" & "°ê»y_¨®¦¸0.wav")
  40.     addList (ThisWorkbook.Path & "\" & "±`¥Î¼s¼½" & "\" & "°ê»y_¦¸.wav")
  41.     addList (ThisWorkbook.Path & "\" & "±`¥Î¼s¼½" & "\" & "°ê»y_°ªÅK.wav")
  42.     addList (ThisWorkbook.Path & "\" & "±`¥Î¼s¼½" & "\" & "°ê»y_¥_¤W.wav")
  43.     addList (ThisWorkbook.Path & "\" & "±`¥Î¼s¼½" & "\" & "°ê»y_ªº¦C¨®§Y±N¶i¯¸½Ð«e©¹.wav")
  44.     addList (ThisWorkbook.Path & "\" & "±`¥Î¼s¼½" & "\" & "°ê»y_²Ä¤G¤ë¥x.wav")
  45.     addList (ThisWorkbook.Path & "\" & "±`¥Î¼s¼½" & "\" & "°ê»y_·f­¼¨Ã¯d·N¤ë¥x¶¡»ØÁÂÁÂ.wav")
  46.         
  47.     For cnt = 1 To UBound(lst)
  48.         If UCase(Right(lst(cnt), 4)) = ".WAV" Then
  49.             PlaySound (lst(cnt))
  50.         ElseIf UCase(Right(lst(cnt), 4)) = ".MP3" Then
  51.             MMStop (LastMp3File)
  52.             LastMp3File = lst(cnt)
  53.             MMPlay (lst(cnt))
  54.         End If
  55.     Next cnt
  56.         
  57.     rmvList
  58. End Sub

  59. Public Function addList(ByVal fn As String)
  60.     Dim num As Long
  61.    
  62.     If idx = 0 Then num = 1 Else num = UBound(lst) + 1
  63.     ReDim Preserve lst(num)
  64.     lst(num) = fn
  65.     idx = idx + 1
  66. End Function

  67. Public Function rmvList()
  68.     If idx = 0 Then Exit Function
  69.     ReDim Preserve lst(0)   '  lst :  String(0 to 0)
  70.     idx = 0                 '  UBound(lst) = 0 : Long
  71. End Function

  72. ' Purpose     :  Plays an audio file
  73. ' Inputs      :  sFilePath           The location of the wav file
  74. '                lFlags              Can be one or many of the constants given above
  75. ' Outputs     :  The text found on the web site
  76. ' Author      :  Andrew Baker
  77. ' Date        :  21/10/2000 12:37
  78. ' Notes       :  Code adapted from code found on www.allapi.net (excellent site!)
  79. ' Revisions   :

  80. Function PlaySound(sFilePath As String, Optional lFlags As Long = SND_FILENAME Or SND_ASYNC) As Long
  81.     PlaySound = PlaySoundA(sFilePath, 0&, lFlags)
  82. End Function

  83. Function ConvShortFilename(ByVal strLongPath$) As String
  84.     Dim strShortPath$
  85.     If InStr(1, strLongPath, " ") Then
  86.         strShortPath = String(LenB(strLongPath), Chr(0))
  87.         GetShortPathName strLongPath, strShortPath, Len(strShortPath)
  88.         ConvShortFilename = Left(strShortPath, InStr(1, strShortPath, Chr(0)) - 1)
  89.     Else
  90.         ConvShortFilename = strLongPath
  91.     End If
  92. End Function

  93. Private Sub MMPlay(ByRef FileName As String)
  94.     FileName = ConvShortFilename(FileName)
  95.     mciSendString "close " & FileName, vbNullString, 0, 0
  96.     mciSendString "open " & FileName, vbNullString, 0, 0
  97.     mciSendString "play " & FileName, vbNullString, 0, 0
  98. End Sub

  99. Private Sub MMStop(ByRef FileName As String)
  100.     FileName = ConvShortFilename(FileName)
  101.     mciSendString "stop " & FileName, vbNullString, 0, 0
  102.     mciSendString "close " & FileName, vbNullString, 0, 0
  103. End Sub
½Æ»s¥N½X
1

µû¤À¤H¼Æ

TOP

¦^´_ 6# lshsien
ÁöµM§A°¾¦n¨Ï¥Î Windows Media Player¡A
¦ý§Ú¨Ï¥Î Joforn ¤j¤j´£¨Ñªºµ{¦¡½X´ú¸Õ
¤TºØ«¬ºAªº´CÅéÀÉ (*.mp3;*.wav;*.mp4)
¥¦¦b°õ¦æ¼·©ñ¹Lµ{«D±`í©w¡ADoEvents ªº
®É¬q®³®º±o«ê·í¡A¤×¨ä¬O mp4 ¼v¤ù¼·©ñ
µøµ¡¤]«Ü¬yºZ¡AÆZ­È±o§A±Ä¥Î¡C¨ä¹ê
Windows Media Player¤¸¥ó¥ç¨Ï¥Î¦P¼Ë¤§
Windows System µ{¦¡®w (Lib)¡C
  1. Sub Ex()
  2.     ItemAdd (ThisWorkbook.Path & "\" & "¤j´d©G¤Ñ¨Ïªiù»e.wav")
  3.     ItemAdd (ThisWorkbook.Path & "\" & "µÎ§B¯S ¤p©]¦± ¤j´£µ^ºt«µ .mp4")
  4.     ItemAdd (ThisWorkbook.Path & "\" & "Ä_æשG.mp3")
  5.     ItemAdd (ThisWorkbook.Path & "\" & "¸t½Ï§Ö¼Ö 01.mp4")
  6.     ItemAdd (ThisWorkbook.Path & "\" & "01_¤Ú«¢ G©¶¤§ºq Air On the G string.mp3")
  7.     ItemAdd (ThisWorkbook.Path & "\" & "µÎ§B¯S ¤p©]¦± ¤j´£µ^ºt«µ .mp4")
  8.     ItemAdd (ThisWorkbook.Path & "\" & "02_NOCTURNE.mp3")
  9.     ItemAdd (ThisWorkbook.Path & "\" & "03_SAULT D' AMOUR.mp3")
  10.     ItemAdd (ThisWorkbook.Path & "\" & "04_JUNE(BARCAROLLE).mp3")
  11.    
  12.     StartPlay
  13. End Sub
½Æ»s¥N½X

TOP

¦^´_ 10# Joforn
¦^´_ 9# ML089
Pause  ¥H¤Î Resume ªº³B²z¡A§Ú¼g¤F¤@
¨ç¦¡¡A¦p¤U¡G
  1. Public Sub PauseResume()
  2.     Static Msg As Boolean    '  ¥Î¥H§P©w¬O§_¬°¨C¤é²Ä¤@¦¸°õ¦æ
  3.    
  4.     If Msg = False Then
  5.         mciSendString StrPtr("pause JofornMusic"), 0&, 0, 0
  6.         Msg = True
  7.     Else
  8.         mciSendString StrPtr("resume JofornMusic"), 0&, 0, 0
  9.         Msg = False
  10.     End If
  11. End Sub
½Æ»s¥N½X
¥t¥~¡A¦A½Ð±Ð Joforn ¤j¤j¡A¦pªG·Q­n°õ¦æ *.rmvb ªº´CÅéÀÉ¡A
ÁÙ­n¥[±¾¨º¨Ç Lib¡A¤~¯à°÷°õ¦æ¡H
ÁÂÁ§A¡I

TOP

¥»©«³Ì«á¥Ñ c_c_lai ©ó 2016-1-24 20:42 ½s¿è

¦^´_ 1# lshsien
§Ú¯S¿ï¤F¤E­º­µ¼Ö (¼Ö¦±ªøµu¤£¤@¡A§tMP4ÀÉ)¡A¤ÏÂдú¸Õ
§¡¯à¥¿±`¼·©ñ¡C§A¸Õ¸Õ¬Ý§a¡I
  1. Option Explicit

  2. Dim Xwmp As IWMPMedia                       '  Playlist
  3. Dim MyPlayer As WindowsMediaPlayer
  4. Dim ListIdx As Long

  5. Public Function addList(ByVal fileName As String)
  6.     Set Xwmp = MyPlayer.newMedia(fileName)
  7.     MyPlayer.currentPlaylist.insertItem ListIdx, Xwmp
  8.     ListIdx = ListIdx + 1
  9.     DoEvents
  10.     MyPlayer.Controls.Play
  11. End Function

  12. Public Function rmvList()
  13.     DoEvents
  14.     If MyPlayer.playState = 1 Or MyPlayer.playState = 10 Then      '  "Stopped"  or  "Ready"
  15.         ListIdx = 0
  16.         MyPlayer.currentPlaylist.Clear
  17.     End If
  18. End Function

  19. Sub Ex()
  20.     Set MyPlayer = ¤u§@ªí1.WindowsMediaPlayer1
  21.     rmvList
  22.    
  23.     addList ThisWorkbook.Path & "\\" & "¤j´d©G¤Ñ¨Ïªiù»e.wav"
  24.     addList ThisWorkbook.Path & "\\" & "Ä_æשG.mp3"
  25.     addList ThisWorkbook.Path & "\\" & "µÎ§B¯S ¤p©]¦± ¤j´£µ^ºt«µ .mp4"
  26.     addList ThisWorkbook.Path & "\\" & "¸t½Ï§Ö¼Ö 01.mp4"
  27.     addList ThisWorkbook.Path & "\\" & "01_¤Ú«¢ G©¶¤§ºq Air On the G string.mp3"
  28.     addList ThisWorkbook.Path & "\\" & "ÅK¹F¥§¸¹ - My Heart Will Go On (§Ú¤ß¥Ã«í) ¤¤­^¤å¦r¹õ.mp4"
  29.     addList ThisWorkbook.Path & "\\" & "02_NOCTURNE.mp3"
  30.     addList ThisWorkbook.Path & "\\" & "03_SAULT D' AMOUR.mp3"
  31.     addList ThisWorkbook.Path & "\\" & "- Barcarolle in F sharp, Op.60.mp3"
  32. End Sub
½Æ»s¥N½X

TOP

¦^´_ 1# lshsien
°ò¥»¤W¡AWindows Media Player ¬OµLªk¼·©ñ  *.rmvb ÀÉ¡A
¦pªG§A·Q³z¹L Windows Media Player ªº¼·©ñ¾¹¨Ó¼·©ñ
*.rmvb ªº¼v¤ùÀÉ¡A¨ä¹ê°ÈÀ³¥Î½d¨Ò¦p¤U¡A´£¨Ñ¤j®a°Ñ¦Ò¡G
  1. Option Explicit

  2. Dim MyPlayer As WindowsMediaPlayer

  3. Public Function playRMVB(ByVal fileName As String)
  4.     MyPlayer.URL = fileName        '  »Ý¥H .URL ¤è¦¡«Å§i
  5.     DoEvents
  6.     MyPlayer.Controls.Play
  7. End Function

  8. Public Function InitialList()
  9.     MyPlayer.Controls.stop
  10.    
  11.     DoEvents
  12.     If MyPlayer.playState = 0 Or MyPlayer.playState = 1 Or MyPlayer.playState = 10 Then
  13.         '  0 = "Undefined"  /  1 = "Stopped"  /  10 = "Ready"
  14.         ListIdx = 0
  15.         MyPlayer.currentPlaylist.Clear
  16.     End If
  17. End Function

  18. Sub Ex()
  19.     Set MyPlayer = ¤u§@ªí1.WindowsMediaPlayer1
  20.     InitialList
  21.    
  22.     '  ******************************************************************
  23.     '  ¼·©ñ RMVB ¼v¤ùÀɻݥý¦w¸Ë Real_Alternative ªº¸ÑªR½X«á¡A Windows
  24.     '  Media Player ¤~¯à¶i¦æ¸ÑªR RMVB ¼v¤ùÀÉ¡A¶i¦Ó©l¯àª½±µ¼·©ñ¥¦¡C
  25.     '  http://www.free-codecs.com/real_alternative_download.htm
  26.     '  ¥H¤U¤T¦æ«Y .rmvb ¼v¤ù¤§¼·©ñµ{§Ç  (*** ¦ý¥u¯à©ñ¸m¦b²Ä¤@­º¼·©ñ ***)
  27.     '  1. MyPlayer.URL = ThisWorkbook.Path & "\\" & "xxxxxxxx.rmvb"
  28.     '  2. DoEvents
  29.     '  3. MyPlayer.Controls.Play
  30.     '  ******************************************************************
  31.     playRMVB ThisWorkbook.Path & "\\" & "xxxxxxxx.rmvb"
  32. End Sub
½Æ»s¥N½X

TOP

        ÀR«ä¦Û¦b : ¦Y­W¤F­W¡B­WºÉ¤Ü¨Ó¡A¨ÉºÖ¤FºÖ¡BºÖºÉ´d¨Ó¡C
ªð¦^¦Cªí ¤W¤@¥DÃD