IWMPNetwork::bufferingProgress 属性

[与此页面关联的功能(Windows 媒体播放器 SDK)是旧版功能。 它已被 MediaPlayer 取代。 MediaPlayer 已针对Windows 10和Windows 11进行了优化。 Microsoft 强烈建议新代码尽可能使用 MediaPlayer 而不是 Windows 媒体播放器 SDK。 如果可能,Microsoft 建议重写使用旧 API 的现有代码以使用新 API。]

bufferingProgress 属性获取缓冲已完成的百分比。

语法

public System.Int32 bufferingProgress {get; set;}

Public ReadOnly Property bufferingProgress As System.Int32

属性值

一个 System.Int32 ,表示以百分比表示的缓冲进度。

备注

每次停止并重启播放时,此属性将重置为零。 如果播放暂停,则不会重置。

缓冲仅适用于流式处理内容。 只有在使用 AxWindowsMediaPlayer.URL 属性设置播放 URL 时,此属性才会获得有效信息。

使用 AxWindowsMediaPlayer._WMPOCXEvents_BufferingEvent 确定缓冲何时开始或停止。

示例

以下示例使用 bufferingProgress 显示标签中完成的缓冲百分比,以响应 Buffering 事件。 该示例使用间隔为 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#)