怎样用mediaplayer控件播放指定文件夹内的mp3文件,播放顺序为随机,播放的时间长度要能够事先指定.

解决方案 »

  1.   


    Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal _
    lpstrCommand As String, ByVal lpstrRetumString As String, ByVal _
    uReturnLength As Long, ByVal hwndCallback As Long) As LongCall mciSendString("play F:\MP3\aa.MP3" & " from " & 0, 0&, 0, 0)路径自己该
      

  2.   

    Dim repeat As Boolean
    Private Sub Form_Load()
    Timer1.Interval = 100
    Dim FileNames As String
    FileNames = Dir("c:\123\", vbNormal)  '显示文件和文件夹
    Do While FileNames <> ""
    If LCase(Right(Trim(FileNames), 3)) = "mp3" Then
    List1.AddItem FileNames
    End If
    FileNames = Dir '再次调用dir函数,此时可以不带参数
    Loop
    i = sj()
    MsgBox i
    WindowsMediaPlayer1.settings.autoStart = True
    WindowsMediaPlayer1.Controls.stop
    WindowsMediaPlayer1.URL = "c:\123\" & List1.List(i)
    WindowsMediaPlayer1.Controls.play
    repeat = False
    Label1.Caption = WindowsMediaPlayer1.Controls.currentPosition
    End SubPrivate Sub Timer1_Timer()
    Label1.Caption = WindowsMediaPlayer1.Controls.currentPosition
    If repeat = True Then
    i = sj()WindowsMediaPlayer1.Controls.stop
    WindowsMediaPlayer1.URL = "c:\123\" & List1.List(i)
    WindowsMediaPlayer1.Controls.play
    repeat = False
    End If
    End SubPrivate Sub WindowsMediaPlayer1_PlayStateChange(ByVal NewState As Long)
    If NewState = 8 Then
    repeat = True
    End If
    End Sub
    Private Function sj() As Integer
    Randomize
    sj = Int(((List1.ListCount - 1) * Rnd))End Function