none
vb2008 讀取wav mp3 檔案 有時候可以有時候讀到上一次的時間 RRS feed

  • 問題

  • 我想說在我有一個button 開啟檔案的時候就顯示時間,請問一定要播放才可以顯示全部時間嗎?還是說開啟就可以了,


            If OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
                Try

                    TextBox1.Text = OpenFileDialog1.FileName '將檔案名稱顯示於視窗標題欄
                    Label1.Text = CStr(CheckMusicLength(TextBox1.Text))
                Catch ex As Exception
                    MsgBox(ex.Message)
                End Try
            End If

     Public Function CheckMusicLength(ByVal FileName As String) As Double
            Dim playingalltime As Double
            Dim tempall As Integer
            Dim mp As String
            mciSendStringA("open " & ShortPathName(FileName) & " alias music", "", 0, 0)
            mp = Space(256)
            mciSendStringA("status music length", mp, Len(mp), 0)
            playingalltime = Val(mp)
            tempall = Val(mp) / 1000
            CheckMusicLength = tempall

            StopMidi()
        End Function

     Public Function StopMidi() As Boolean                       '停止音樂
            StopMidi = mciSendStringA("stop music", "", 0, 0) = 0
            mciSendStringA("close music", "", 0, 0)
        End Function

    2009年8月2日 下午 02:47

解答

所有回覆