For nCount = optPlaybackRate.LBound To optPlaybackRate.UBound
If optPlaybackRate(nCount).Value = True Then
Select Case nCount
Case 0
If m_objMediaPosition <>NULL Then _
m_objMediaPosition.Rate = 0.5
Case 1
If m_objMediaPosition <>NULL Then _
m_objMediaPosition.Rate = 1
Case 2
If m_objMediaPosition <> NULL Then _
m_objMediaPosition.Rate = 2
End Select
Exit For
End If
Next
m_dblRunLength = Round(m_objMediaPosition.Duration, 2)
txtDuration.Text = CStr(m_dblRunLength)
' 設置當前位置為起始位置;
m_dblStartPosition = 0
' 顯示用戶選擇的多媒體流的播放速率;
m_dblRate = m_objMediaPosition.Rate
txtRate.Text = CStr(m_dblRate)
'設置按鈕的默認狀態(tài);
tbControlBar.Buttons("play").Enabled = True
tbControlBar.Buttons("stop").Enabled = False
tbControlBar.Buttons("pause").Enabled = False
Call tbControlBar_ButtonClick(tbControlBar.Buttons(1))
ErrLine:
Err.Clear
Resume Next
Exit Sub
End Sub
************************************************************************
用戶點擊播放速率單選按鈕時的響應處理函數(shù);
************************************************************************
Private Sub optPlaybackRate_Click(Index As Integer)
On Local Error GoTo ErrLine
Select Case Index
Case 0
If m_objMediaPosition<> NULL Then _
txtRate.Text = 0.5
Case 1
If m_objMediaPosition<> NULL Then _
txtRate.Text = 1
Case 2
If m_objMediaPosition<> NULL Then _
txtRate.Text = 2
End Select
'重新設置媒體回放的播放速率;
If m_objMediaPosition Then
Select Case Index
Case 0
If m_objMediaPosition <>NULL Then _
m_objMediaPosition.Rate = 0.5
Case 1
If m_objMediaPosition <> NULL Then _
m_objMediaPosition.Rate = 1
Case 2
If m_objMediaPosition <> NULL Then _
m_objMediaPosition.Rate = 2
End Select
End If
Exit Sub
ErrLine:
Err.Clear
Exit Sub
End Sub
**************************************************************************
音頻平衡滑動條改變時的響應處理函數(shù);
**************************************************************************
Private Sub slBalance_Change()
On Local Error GoTo ErrLine
'用戶使用滑動條來設置語音平衡的值;
If m_objFilgraphManager <> NULL Then _
m_objBasicAudio.Balance = slBalance.Value
Exit Sub
ErrLine:
Err.Clear
Exit Sub
End Sub
***********************************************************************
設置音量大小的滑動條改變時的響應處理函數(shù)
***********************************************************************
Private Sub slVolume_Change()
On Local Error GoTo ErrLine
'用戶使用滑動條來設置語音的大小;
If m_objFilgraphManager <>NULL Then _
m_objBasicAudio.Volume = slVolume.Value
Exit Sub
ErrLine:
Err.Clear
Exit Sub
End Sub
***************************************************************************
界面上關于多媒體流的"播放"、"暫停"、"停止"等按鈕的點擊響應函數(shù);
***************************************************************************
Private Sub tbControlBar_ButtonClick(ByVal Button As Button)
On Local Error GoTo ErrLine
If ObjPtr(m_objMediaControl) > 0 Then
If Button.Key = "play" Then '如果用戶點擊了"播放"按鈕;
'如果多媒體的當前位置不處在文件尾部,則對多媒體流的位置重新置位;
If CLng(m_objMediaPosition.CurrentPosition) < CLng(m_dblStartPosition) Then
m_objMediaPosition.CurrentPosition = m_dblStartPosition
ElseIf CLng(m_objMediaPosition.CurrentPosition) = CLng(m_dblRunLength) Then
m_objMediaPosition.CurrentPosition = m_dblStartPosition
End If
Call m_objFilgraphManager.Run
m_boolVideoRunning = True
tbControlBar.Buttons("play").Enabled = False
tbControlBar.Buttons("stop").Enabled = True
tbControlBar.Buttons("pause").Enabled = True
picVideoWindow.Refresh
ElseIf Button.Key = "pause" Then '用戶點擊了"暫停"按鈕;
Call m_objFilgraphManager.Pause
m_boolVideoRunning = False
tbControlBar.Buttons("play").Enabled = True
tbControlBar.Buttons("stop").Enabled = True
tbControlBar.Buttons("pause").Enabled = False
ElseIf Button.Key = "stop" Then '用戶點擊了"停止"按鈕;
Call m_objFilgraphManager.Stop
m_boolVideoRunning = False
' 重新設置視頻流的當前播放位置為起始位置;
m_objMediaPosition.CurrentPosition = 0
txtElapsed.Text = "0.0"
tbControlBar.Buttons("play").Enabled = True
tbControlBar.Buttons("stop").Enabled = False
tbControlBar.Buttons("pause").Enabled = False
End If
End If
Exit Sub
ErrLine:
Err.Clear
Exit Sub
End Sub
以上內(nèi)容希望對在多媒體領域有興趣的讀者朋友有所幫助,起到拋磚引玉的作用,將上面的代碼稍加修改后添加到自己正在開發(fā)的應用程序中,實現(xiàn)流媒體的播放,達到豐富軟件的功能的目的。