【发布时间】:2022-11-05 19:29:14
【问题描述】:
问题可以在这里看到:https://www.wgbh.org/news/local-news/2022/06/07/housing-is-in-short-supply-heres-why-that-matters
当点击海报图片播放按钮时,海报图片消失,视频应该开始播放(由 API 中的<player>.playVideo() 触发)。
但是,在 Chrome(和 Brave)中,用户还必须单击 YT 原生播放按钮。 playVideo() 方法没有显示错误。
用户点击触发了这段代码 sn-p 中的play() 函数(不直播),我每半秒调用一次 playVideo() 。初始视频状态是“视频提示”,但之后,状态永远不会从“未启动”改变,视频永远不会播放。
play () {
console.log('Received play signal from poster')
let playerState = this.player.getPlayerState().toString()
const thePlayer = this.player
console.log('Pre-play-signal state: ', PLAYER_STATES[playerState])
let waitForPlay = setInterval(function () {
thePlayer.playVideo()
playerState = thePlayer.getPlayerState().toString()
console.log('Interval play state: ', PLAYER_STATES[playerState])
if (playerState === '1') {
clearInterval(waitForPlay)
console.log('Final play state: ', PLAYER_STATES[playerState])
}
}, 500)
}
playVideo() 请求的响应标头:
accept-ranges: bytes
access-control-allow-credentials: true
access-control-allow-origin: https://www.youtube.com
access-control-expose-headers: Client-Protocol, Content-Length, Content-Type, X-Bandwidth-Est, X-Bandwidth-Est2, X-Bandwidth-Est3, X-Bandwidth-App-Limited, X-Bandwidth-Est-App-Limited, X-Bandwidth-Est-Comp, X-Bandwidth-Avg, X-Head-Time-Millis, X-Head-Time-Sec, X-Head-Seqnum, X-Response-Itag, X-Restrict-Formats-Hint, X-Sequence-Num, X-Segment-Lmt, X-Walltime-Ms
alt-svc: h3=":443"; ma=2592000,h3-29=":443"; ma=2592000,h3-Q050=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43"
cache-control: private, max-age=21248
client-protocol: quic
content-length: 2097152
content-type: video/webm
cross-origin-resource-policy: cross-origin
date: Wed, 08 Jun 2022 20:19:21 GMT
expires: Wed, 08 Jun 2022 20:19:21 GMT
last-modified: Tue, 07 Jun 2022 13:41:59 GMT
server: gvs 1.0
timing-allow-origin: https://www.youtube.com
vary: Origin
x-content-type-options: nosniff
x-restrict-formats-hint: None
我已经尝试过使用--disable-web-security 标志打开的浏览器,但没有区别。
任何帮助,将不胜感激。谢谢。
【问题讨论】:
-
我有同样的问题,只是 Chrome 和 Edge,而不是 Firefox
标签: javascript youtube-iframe-api