Share via


Windows Media Player 11 SDK IWMPMedia.durationString (VB and C#) 

Windows Media Player SDK banner art

Previous Next

IWMPMedia.durationString (VB and C#)

The durationString property gets a string indicating the duration of the current media item in HH:MM:SS format.

[Visual Basic]
ReadOnly Property durationString As String

[C#]
string durationString {get;}

Property Value

A System.String that is the duration.

Remarks

If this property is used with a media item other than the one specified in AxWindowsMediaPlayer.currentMedia, it may not contain a valid value. If the media item is less than an hour long, the hours portion of the return value is omitted.

Before using this property, you must have read access to the library. For more information, see Library Access.

Example Code

The following example uses durationString to display the duration of the current media item as formatted text in a label. The AxWMPLib.AxWindowsMediaPlayer object is represented by the variable named player.

[Visual Basic]
' 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

FakePre-6030d92fb3ee4556a544d77b006a9eb4-b0253b9c4f724c388b8d1396f0a68fff

// 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;
    }
}

Requirements

Version: Windows Media Player 9 Series or later

Namespace: WMPLib

Assembly: Interop.WMPLib.dll (automatically generated by Visual Studio)

See Also

Previous Next