Media.durationString

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

durationString屬性會擷取String值,指出 HH:MM:SS 格式目前媒體專案的持續時間。

Syntax

播放機currentMediadurationString

可能的值

此屬性是唯讀 的 String

備註

如果這個屬性與 Player中指定的媒體專案一起使用,則為 。currentMedia,它可能不會包含有效的值。 如果媒體專案少於一小時,則會省略傳回值的 HH: 部分。

若要擷取這個屬性的值,需要程式庫的讀取權限。 如需詳細資訊,請參閱 程式庫存取

範例

下列 JScript 範例使用 MediadurationString ,將目前媒體專案的持續時間顯示為格式化文字。 名為 MediaInfo 的 HTML DIV 元素會顯示持續時間資訊。 Player物件是以識別碼 = 「Player」 建立的。

<!-- Create an event handler to update the display when
 the current media item changes. -->
<SCRIPT LANGUAGE = "JScript"  FOR = Player  EVENT = OpenStateChange(NewState)>

// Test whether the new media item is open.
if (NewState == 13){

   // Write the formatted duration string to the DIV region.
   MediaInfo.innerHTML = "Duration: " + Player.currentMedia.durationString;
}
</SCRIPT>

規格需求

需求
版本
Windows 媒體播放機 7.0 版或更新版本。
DLL
Wmp.dll

另請參閱

Media 物件

Media.duration

Player.currentMedia

Settings.mediaAccessRights

Settings.requestMediaAccessRights