MediaSession.setPositionState() - Web APIs 编辑

The MediaSession method setPositionState() is used to update the current document's media playback position and speed for presentation by user's device in any kind of interface that provides details about ongoing media. This can be particularly useful if your code implements a player for type of media not directly supported by the browser.

Call this method on the navigator object's mediaSession object.

Syntax

navigator.mediaSession.setPositionState(stateDict);

Parameters

stateDict Optional
An object conforming to the MediaPositionState dictionary, providing updated information about the playback position and speed of the document's ongoing media. If the object is empty, the existing playback state information is cleared.

Return value

undefined.

Exceptions

TypeError

This error can occur in an array of circumstances:

Example

Below is a function which updates the position state of the current MediaSession track.

function updatePositionState() {
  navigator.mediaSession.setPositionState({
    duration: audioEl.duration,
    playbackRate: audioEl.playbackRate,
    position: audioEl.currentTime
  });
}

We can use this function when updating media session metadata and within callbacks for actions, such as below.

navigator.mediaSession.setActionHandler('seekbackward', details => {

  // our time to skip
  const skipTime = details.seekOffset || 10;

  // set our position
  audioEl.currentTime = Math.max(audioEl.currentTime - skipTime, 0);
  updatePositionState();

});

Specifications

SpecificationStatusComment
Media Session Standard
The definition of 'MediaSession.setPositionState()' in that specification.
DraftInitial definition.

Browser compatibility

BCD tables only load in the browser

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:86 次

字数:4334

最后编辑:8年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文