IWMPMedia::d urationString 属性

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

durationString 属性获取一个字符串,指示 HH:MM:SS 格式的当前媒体项的持续时间。

此属性为只读。

语法

public System.String durationString {get;}

Public ReadOnly Property durationString As System.String

属性值

作为持续时间的 System.String

备注

如果此属性与 AxWindowsMediaPlayer.currentMedia 中指定的媒体项一起使用,则它可能不包含有效值。 如果媒体项的长度小于一小时,则省略返回值的小时部分。

在使用此属性之前,必须具有对库的读取访问权限。 有关详细信息,请参阅 库访问

示例

以下示例使用 durationString 将当前媒体项的持续时间显示为标签中的格式化文本。 AxWMPLib.AxWindowsMediaPlayer 对象由名为 player 的变量表示。

// Create an event handler for the OpenStateChange event.
private void player_OpenStateChange(object sender, AxWMPLib._WMPOCXEvents_OpenStateChangeEvent e)
{
    // Test whether the current media item is open.
    if (e.newState == (int)WMPLib.WMPOpenState.wmposMediaOpen)
    {
         // Display the formatted duration string in the label.
         mediaDuration.Text = player.currentMedia.durationString;
    }
}

' Create an event handler for the OpenStateChange event.
Public Sub player_OpenStateChange(ByVal sender As Object, ByVal e As AxWMPLib._WMPOCXEvents_OpenStateChangeEvent) Handles player.OpenStateChange

    ' Test whether the current media item is open.
    If (e.newState = 13) Then

        ' Display the formatted duration string in the label.
        mediaDuration.Text = player.currentMedia.durationString

    End If

End Sub

要求

要求
版本
Windows 媒体播放器 9 系列或更高版本
命名空间
WMPLib
程序集
Interop.WMPLib.dll (Interop.WMPLib.dll.dll)

另请参阅

AxWindowsMediaPlayer.currentMedia (VB 和 C#)

IWMPMedia 接口 (VB 和 C#)

IWMPMedia.duration (VB 和 C#)