- ©«¤l
- 2035
- ¥DÃD
- 24
- ºëµØ
- 0
- ¿n¤À
- 2031
- ÂI¦W
- 0
- §@·~¨t²Î
- Win7
- ³nÅ骩¥»
- Office2010
- ¾\ŪÅv
- 100
- ©Ê§O
- ¨k
- µù¥U®É¶¡
- 2012-3-22
- ³Ì«áµn¿ý
- 2024-2-1
|
¦^´_ 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- Option Explicit
- Private Const SND_APPLICATION = &H80 ' look for application specific association
- Private Const SND_ALIAS = &H10000 ' name is a WIN.INI [sounds] entry
- Private Const SND_ALIAS_ID = &H110000 ' name is a WIN.INI [sounds] entry identifier
- Private Const SND_ASYNC = &H1 ' play asynchronously
- Private Const SND_FILENAME = &H20000 ' name is a file name
- Private Const SND_LOOP = &H8 ' loop the sound until next sndPlaySound
- Private Const SND_MEMORY = &H4 ' lpszSoundName points to a memory file
- Private Const SND_NODEFAULT = &H2 ' silence not default, if sound not found
- Private Const SND_NOSTOP = &H10 ' don't stop any currently playing sound
- Private Const SND_NOWAIT = &H2000 ' don't wait if the driver is busy
- Private Const SND_PURGE = &H40 ' purge non-static events for task
- Private Const SND_RESOURCE = &H40004 ' name is a resource name or atom
- Private Const SND_SYNC = &H0 ' play synchronously (default)
- #If VBA7 Then
- Private Declare PtrSafe Function PlaySoundA Lib "winmm.dll" (ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long
- ' ¥H¤W«Y .Wav Àɤ§°Ñ¼Æ«Å§i¡F ¤U¦C¤T¦æ¬° .MP3 Àɮ׫ŧi¤§¤Þ¥Î¥\¯à¨ç¦¡¤ÎÅܼƫŧi¡C
- 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
- Private Declare PtrSafe Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long
- #Else
- Private Declare Function PlaySoundA Lib "winmm.dll" (ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long
- ' ¥H¤W«Y .Wav Àɤ§°Ñ¼Æ«Å§i¡F ¤U¦C¤T¦æ¬° .MP3 Àɮ׫ŧi¤§¤Þ¥Î¥\¯à¨ç¦¡¤ÎÅܼƫŧi¡C
- 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
- Private Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long
- #End If
- Dim Mp3File, LastMp3File As String, lst() As String, idx As Long
- Sub Ex()
- Dim cnt As Long
-
- idx = 0
- addList (ThisWorkbook.Path & "\" & "±`¥Î¼s¼½" & "\" & "°ê»y_¦U¦ì®È«È±z¦n.wav")
- addList (ThisWorkbook.Path & "\" & "±`¥Î¼s¼½" & "\" & "°ê»y_6ÂI.wav")
- addList (ThisWorkbook.Path & "\" & "±`¥Î¼s¼½" & "\" & "°ê»y_¤À50.wav")
- addList (ThisWorkbook.Path & "\" & "±`¥Î¼s¼½" & "\" & "°ê»y_¤À.wav")
- addList (ThisWorkbook.Path & "\" & "±`¥Î¼s¼½" & "\" & "°ê»y_¶}©¹.wav")
- addList (ThisWorkbook.Path & "\" & "±`¥Î¼s¼½" & "\" & "°ê»y_¥x¥_ªº.wav")
- addList (ThisWorkbook.Path & "\" & "±`¥Î¼s¼½" & "\" & "°ê»y_¨®¦¸5.wav")
- addList (ThisWorkbook.Path & "\" & "±`¥Î¼s¼½" & "\" & "°ê»y_¨®¦¸0.wav")
- addList (ThisWorkbook.Path & "\" & "±`¥Î¼s¼½" & "\" & "°ê»y_¨®¦¸0.wav")
- addList (ThisWorkbook.Path & "\" & "±`¥Î¼s¼½" & "\" & "°ê»y_¦¸.wav")
- addList (ThisWorkbook.Path & "\" & "±`¥Î¼s¼½" & "\" & "°ê»y_°ªÅK.wav")
- addList (ThisWorkbook.Path & "\" & "±`¥Î¼s¼½" & "\" & "°ê»y_¥_¤W.wav")
- addList (ThisWorkbook.Path & "\" & "±`¥Î¼s¼½" & "\" & "°ê»y_ªº¦C¨®§Y±N¶i¯¸½Ð«e©¹.wav")
- addList (ThisWorkbook.Path & "\" & "±`¥Î¼s¼½" & "\" & "°ê»y_²Ä¤G¤ë¥x.wav")
- addList (ThisWorkbook.Path & "\" & "±`¥Î¼s¼½" & "\" & "°ê»y_·f¼¨Ã¯d·N¤ë¥x¶¡»ØÁÂÁÂ.wav")
-
- For cnt = 1 To UBound(lst)
- If UCase(Right(lst(cnt), 4)) = ".WAV" Then
- PlaySound (lst(cnt))
- ElseIf UCase(Right(lst(cnt), 4)) = ".MP3" Then
- MMStop (LastMp3File)
- LastMp3File = lst(cnt)
- MMPlay (lst(cnt))
- End If
- Next cnt
-
- rmvList
- End Sub
- Public Function addList(ByVal fn As String)
- Dim num As Long
-
- If idx = 0 Then num = 1 Else num = UBound(lst) + 1
- ReDim Preserve lst(num)
- lst(num) = fn
- idx = idx + 1
- End Function
- Public Function rmvList()
- If idx = 0 Then Exit Function
- ReDim Preserve lst(0) ' lst : String(0 to 0)
- idx = 0 ' UBound(lst) = 0 : Long
- End Function
- ' Purpose : Plays an audio file
- ' Inputs : sFilePath The location of the wav file
- ' lFlags Can be one or many of the constants given above
- ' Outputs : The text found on the web site
- ' Author : Andrew Baker
- ' Date : 21/10/2000 12:37
- ' Notes : Code adapted from code found on www.allapi.net (excellent site!)
- ' Revisions :
- Function PlaySound(sFilePath As String, Optional lFlags As Long = SND_FILENAME Or SND_ASYNC) As Long
- PlaySound = PlaySoundA(sFilePath, 0&, lFlags)
- End Function
- Function ConvShortFilename(ByVal strLongPath$) As String
- Dim strShortPath$
- If InStr(1, strLongPath, " ") Then
- strShortPath = String(LenB(strLongPath), Chr(0))
- GetShortPathName strLongPath, strShortPath, Len(strShortPath)
- ConvShortFilename = Left(strShortPath, InStr(1, strShortPath, Chr(0)) - 1)
- Else
- ConvShortFilename = strLongPath
- End If
- End Function
- Private Sub MMPlay(ByRef FileName As String)
- FileName = ConvShortFilename(FileName)
- mciSendString "close " & FileName, vbNullString, 0, 0
- mciSendString "open " & FileName, vbNullString, 0, 0
- mciSendString "play " & FileName, vbNullString, 0, 0
- End Sub
- Private Sub MMStop(ByRef FileName As String)
- FileName = ConvShortFilename(FileName)
- mciSendString "stop " & FileName, vbNullString, 0, 0
- mciSendString "close " & FileName, vbNullString, 0, 0
- End Sub
½Æ»s¥N½X |
-
1
µû¤À¤H¼Æ
-
|