IWMPNetwork::d ownloadProgress 属性
[与此页面关联的功能(Windows 媒体播放器 SDK)是旧版功能。 它已被 MediaPlayer 取代。 MediaPlayer 已针对Windows 10和Windows 11进行了优化。 如果可能,Microsoft 强烈建议新代码使用 MediaPlayer 而不是 Windows 媒体播放器 SDK。 如果可能,Microsoft 建议重写使用旧 API 的现有代码以使用新 API。]
downloadProgress 属性获取下载已完成的百分比。
语法
public System.Int32 downloadProgress {get; set;}
Public ReadOnly Property downloadProgress As System.Int32
属性值
一个 System.Int32,它是以百分比表示的下载进度。
备注
当Windows 媒体播放器控件连接到可以同时播放和下载的数字媒体文件时,downloadProgress 属性获取已下载的文件总数的百分比。 此功能目前仅支持从 Web 服务器下载的数字媒体文件。 可以同时下载和播放以下任何格式的文件:
- 高级流格式 (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 |
程序集 |
|
另请参阅
反馈
https://aka.ms/ContentUserFeedback。
即将发布:在整个 2024 年,我们将逐步淘汰作为内容反馈机制的“GitHub 问题”,并将其取代为新的反馈系统。 有关详细信息,请参阅:提交和查看相关反馈