IWMPNetwork::d ownloadProgress 屬性

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

downloadProgress屬性會取得已完成下載的百分比。

Syntax

public System.Int32 downloadProgress {get; set;}

Public ReadOnly Property downloadProgress As System.Int32

屬性值

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

備註

當Windows 媒體播放機控制項連接到可同時播放和下載的數位媒體檔案時,downloadProgress屬性會取得已下載之檔案總數的百分比。 此功能目前僅支援從網頁伺服器下載的數位媒體檔案。 您可以同時下載並播放下列任何格式的檔案:

  • 進階系統格式 (ASF)
  • Windows Media 音訊 (WMA)
  • Windows Media 視訊 (WMV)
  • MP3
  • MPEG
  • WAV

此外,某些 AVI 檔案可以同時下載和播放。

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

範例

下列程式碼範例會使用 downloadProgress 來顯示已完成下載的百分比。 此資訊會顯示在標籤中,以回應 緩衝 事件。 此範例會使用 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 download progress in a timer event handler.
private void UpdateDownloadProgress(object sender, EventArgs e)
{
    downloadProgressLabel.Text = ("Download progress: " + player.network.downloadProgress + " 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 download progress in a timer event handler.
Public Sub UpdateDownloadProgress(ByVal sender As Object, ByVal e As System.EventArgs) Handles timer.Tick

    downloadProgressLabel.Text = ("Download progress: " + player.network.downloadProgress + " percent complete")

End Sub

規格需求

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

另請參閱

AxWindowsMediaPlayer.Buffering 事件 (VB 和 C#)

IWMPNetwork 介面 (VB 和 C#)