Share via


Windows Media Player 11 SDK Media.duration 

Windows Media Player SDK banner art

Previous Next

Media.duration

The duration property retrieves the duration of the current media item in seconds.

Syntax

  
    
  

Possible Values

This property is a read-only Number (double).

Remarks

If this property is used with a media item other than the one specified in Player**.currentMedia**, it may not contain a valid value.

To retrieve the duration for files that are not in the user's library, you must wait for Windows Media Player to open the file; that is, the current OpenState must equal MediaOpen. You can verify this by handling the Player.OpenStateChange event or by periodically checking the value of Player.openState.

For playlists, the duration of each media item can be retrieved when the individual media item is opened, rather than the when the playlist is opened.

To retrieve the value of this property, read access to the library is required. For more information, see Library Access.

Example Code

The following JScript example uses Media.duration to display the time remaining in the current media item. An HTML DIV element named RemTime displays the information. An HTML timer updates the text in the DIV element every second.

The following JScript code starts the timer:

  

The following JScript code stops the timer:

  

Use the Player.PlayStateChange event with a switch statement to determine when to start and stop the timer.

The following JScript code executes each time the timer calls the update function:

  

Requirements

Version: Windows Media Player version 7.0 or later.

Library: Use wmp.dll.

See Also

Previous Next