MediaSession.setPositionState()并寻求不工作
MediaSession.setPositionState()未显示音频时间, 也不按预期显示Seekbar。
const audio= document.querySelector('audio');
function updatePositionState() {
if ('setPositionState' in navigator.mediaSession) {
navigator.mediaSession.setPositionState({
duration: audio.duration,
playbackRate: audio.playbackRate,
position: audio.currentTime,
});
}
}
await audio.play();
updatePositionState();
navigator.mediaSession.setActionHandler('seekto', (details) => {
updatePositionState();
});
MediaSession.setPositionState() not showing the audio time,
also seekbar not showing as expected.
const audio= document.querySelector('audio');
function updatePositionState() {
if ('setPositionState' in navigator.mediaSession) {
navigator.mediaSession.setPositionState({
duration: audio.duration,
playbackRate: audio.playbackRate,
position: audio.currentTime,
});
}
}
await audio.play();
updatePositionState();
navigator.mediaSession.setActionHandler('seekto', (details) => {
updatePositionState();
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这对我有用:
This is what worked for me:
参见 https:> https:/ https://noah-github.com/noah-jaffe/mjaffe/mmixcloud_play_play_play_playerer/blob /main/musicplayer.html 对于此精确函数的用例,所有音频媒体控件均已在
set> setup_media_session_action_action_handlers()
函数中实现。在使用Android Chrome查看HTML页面上的Android设备上的动作中,如下

See https://github.com/Noah-Jaffe/Mixcloud_player/blob/main/MUSICPLAYER.html for a use case of this exact function, all of the audio media controls are implemented inside the
setup_media_session_action_handlers()
function.in action on android device viewing html page with Android Chrome it looks like the following

我遇到了同样的事情。
然后,我正在进行一些清理,并决定目前不需要以下内容:
一旦我对此进行了评论,现在在我的移动设备上可以看到Seek Bar。在桌面上仍然看不到。我怀疑MediaSession API的工作方式可能是您向前和向后的按钮跳过,那么Seekto将被禁用。
现在,Seekto bar是可见的,可以触发,但这是不正确的。当轨道启动时,已经走了四分之一。
我似乎找不到在菜谱上在菜谱中设置曲目的运行时的方法。
我在某个地方读到,甚至不可能在溪流上有搜索栏。
I encountered the same thing.
Then I was doing some cleaning up and decided that the below was not required for now:
Once I had commented this out, the seek bar was now visible on my Mobile Device. On the desktop it was still not visible. I suspect that maybe the way the MediaSession API works is if you have the skip forward and backward buttons, then the seekTo is disabled.
Now, the seekTo bar is visible and can be triggered but it is incorrect. When a track starts, it's already a quarter of the way through.
I can't seem to find a way to set the runtime of the track in the MedaSession API on a stream.
I had read somewhere that it was not possible to even have a seek bar on a stream. ????♀️