2017-09-19 31 views
2

在调用.play()之前设置.currentTimeHTMLMediaElement内的canplay事件pause事件被调度。如何在canplay事件中设置HTMLMediaElement的.currentTime,调用play并避免调度暂停事件?

当试图设置.currentTime和错误之后canplay事件中调用.play()抛出

DOMException: The play() request was interrupted by a call to pause().

如何设置内部canplay.currentTimeHTMLMediaElementcanplaythrough事件,而不调度pause事件,或如何从pause事件处理程序中调用.play()以启动medi一组播放.currentTime

<!DOCTYPE html> 
 
<html> 
 

 
<head> 
 
</head> 
 

 
<body> 
 
    <video preload="auto" controls></video> 
 
    <span></span> 
 
    <script> 
 
    const url = "https://mirrors.creativecommons.org/movingimages/webm/ScienceCommonsJesseDylan_240p.webm#t=10,15"; 
 

 
    const video = document.querySelector("video"); 
 

 
    let cursor = 10.5; 
 

 
    video.oncanplay = e => { 
 
     video.oncanplay = null; 
 
     video.currentTime = cursor; 
 
     console.log(e, video.currentTime, video.buffered.end(0)); 
 
     video.play().catch(err => document.querySelector("span").textContent = err.message); 
 
    } 
 

 
    video.onpause = e => { 
 
     console.log(e, video.currentTime); 
 
    } 
 

 
    video.src = url; 
 
    </script> 
 
</body> 
 

 
</html>

回答

2

那你有没有一个非常奇怪的错误,我不知道它从何而来,也没有什么是你落在它的可能性。

如果我没有弄错,那么当您设置currentTime属性时,Chrome将不再遵守src的时间范围#t=start,end参数。

所以他们会忘记它,并行动,如果你经历了end阈值,从而暂停视频。

但是,当它试图写一个测试用例时,我发现这只发生在canplay事件中,只有在这个视频中,并且只有时间范围设置为10,15

将其设置为#t=10.0,15,它的工作原理
将其设置为#t=10,15.0,它的工作原理是
将其设置为任何其他值,似乎工作(不,我没有测试所有可能值)
将它设置为#t=10,15的其他视频,它的工作原理
将其设置为#t=10,15在同一个视频,但是从其他的服务器提供服务,工作...

// changed the #t parameter 
 
    const url = "https://mirrors.creativecommons.org/movingimages/webm/ScienceCommonsJesseDylan_240p.webm#t=10.0,15"; 
 

 
    const video = document.querySelector("video"); 
 

 
    let cursor = 10.5; 
 

 
    video.oncanplay = e => { 
 
     video.oncanplay = null; 
 
     video.currentTime = cursor; 
 
     console.log(e, video.currentTime, video.buffered.end(0)); 
 
     video.play().catch(err => document.querySelector("span").textContent = err.message); 
 
    } 
 

 
    video.onpause = e => { 
 
     console.log(e, video.currentTime); 
 
    } 
 

 
    video.src = url;
<video preload="auto" controls></video> 
 
    <span></span>

所以对于一个真正的解决,我认为https://bugs.chromium.org/p/chromium/issues/仍然是最好的方式,但我不确定他们会告诉你什么,因为这似乎与视频文件本身高度相关。

+0

这是值得的,我有* FFmpegVideoDecoder:avcodec_decode_video2():处理输入时发现无效数据,时间戳:10009000持续时间:41000大小:502 side_data_size:0 is_key_frame:0加密:0 discard_padding(ms): (0,0)*在chrome:// media-internals中。 – Kaiido

+0

铬问题https://bugs.chromium.org/p/chromium/issues/detail?id=767163 – guest271314