使用循环播放 MP3 文件

Play MP3 files using loops

我正在编写一个代码,该代码可以根据 A 列中这些 mp3 文件的文件名列表从特定目录播放 MP3 文件。该代码适用于大约五六个文件,然后 excel 挂起一段时间然后从另一个意外点恢复。我怎样才能修改代码使其播放A列中的所有mp3文件?

Public wmp As Object

Sub Test()
    Dim r As Long
    Set wmp = CreateObject("new:6BF52A52-394A-11D3-B153-00C04F79FAA6")
    For r = 1 To Cells(Rows.Count, 1).End(xlUp).Row
        With wmp
            .URL = ThisWorkbook.Path & "\Media\" & Cells(r, 1).Value & ".mp3"
            .Controls.Play
        End With
        DoEvents
        Application.Wait Now + TimeValue("00:00:02")
    Next r
End Sub

您可以使用循环构建播放列表,然后播放

Public wmp As Object

Sub Test()
    Dim r As Long
    Dim itm
    Set wmp = CreateObject("new:6BF52A52-394A-11D3-B153-00C04F79FAA6")
    For r = 1 To Cells(Rows.Count, 1).End(xlUp).Row
        With wmp
            Set itm = .newMedia(ThisWorkbook.Path & "\Media\" & Cells(r, 1).Value & ".mp3")
            .currentPlaylist.appendItem itm
        End With
    Next r
    wmp.Controls.Play
End Sub