IWMPNetwork::bufferingProgress 屬性

[與此頁面相關聯的功能Windows 媒體播放機 SDK是舊版功能。 它已被 MediaPlayer 取代MediaPlayer已針對Windows 10和Windows 11進行優化。 Microsoft 強烈建議新程式碼盡可能使用MediaPlayer,而不是Windows 媒體播放機 SDK。 Microsoft 建議盡可能重寫使用舊版 API 的現有程式碼,以使用新的 API。]

bufferingProgress屬性會取得已完成緩衝的百分比。

Syntax

public System.Int32 bufferingProgress {get; set;}

Public ReadOnly Property bufferingProgress As System.Int32

屬性值

System.Int32,這是以百分比表示的緩衝進度。

備註

每次停止並重新啟動播放時,此屬性都會重設為零。 如果暫停播放,則不會重設。

緩衝僅適用于串流內容。 只有當使用 AxWindowsMediaPlayer.URL 屬性設定播放的 URL 時,這個屬性才會取得有效的資訊。

使用 AxWindowsMediaPlayer._WMPOCXEvents_BufferingEvent 來判斷何時開始或停止緩衝處理。

範例

下列範例會使用 bufferingProgress 來顯示標籤中已完成的緩衝百分比,以回應緩衝事件。 此範例會使用 1 秒間隔的計時器來更新顯示器。 AxWMPLib.AxWindowsMediaPlayer物件是由名為 player 的變數表示。

// Add a delegate for the Buffering event.
player.Buffering += new AxWMPLib._WMPOCXEvents_BufferingEventHandler(player_Buffering);

// Create an event handler for the Buffering event.
private void player_Buffering(object sender, AxWMPLib._WMPOCXEvents_BufferingEvent e)
{
    // Determine whether buffering has started or stopped.
    if (e.start == true)
    {
        // Set the timer interval at one second (1000 miliseconds).
        timer.Interval = 1000;
        
        // Start the timer.
        timer.Start();
    }
    else
    {
        // Buffering is complete. Stop the timer.
        timer.Stop();
    }
}

// Update the buffering progress in a timer event handler.
private void UpdateBufferingProgress(object sender, EventArgs e)
{
    bufferingProgressLabel.Text = ("Buffering progress: " + player.network.bufferingProgress + " percent complete");
}

' Create an event handler for the Buffering event.
Public Sub player_Buffering(ByVal sender As Object, ByVal e As AxWMPLib._WMPOCXEvents_BufferingEvent) Handles player.Buffering

    ' Test whether packets may be arriving.
    Select Case e.newState

    ' If WMPPlayState is Stopped, Paused, ScanForward, ScanReverse, Waiting, MediaEnded
    ' or Transitioning then stop the timer. 
        Case 1
        Case 2
        Case 4
        Case 5
        Case 7
        Case 8
        Case 9
            timer.Stop()

        ' If WMPPlayState is Playing or Buffering then set the timer interval and start the timer.
        Case Else
            timer.Interval = 1000
            timer.Start()

    End Select

End Sub

' Update the buffering progress in a timer event handler.
Public Sub UpdateBufferingProgress(ByVal sender As Object, ByVal e As System.EventArgs) Handles timer.Tick

    bufferingProgressLabel.Text = ("Buffering progress: " + player.network.bufferingProgress + " percent complete")

End Sub

規格需求

需求
版本
Windows 媒體播放機 9 系列或更新版本
命名空間
WMPLib
組件
Interop.WMPLib.dll (Interop.WMPLib.dll.dll)

另請參閱

AxWindowsMediaPlayer.URL (VB 和 C#)

AxWindowsMediaPlayer.Buffering 事件 (VB 和 C#)

IWMPNetwork 介面 (VB 和 C#)