admin管理员组文章数量:1425820
I'm using the YouTube iFrame API to embed YouTube videos on my site. The videos are pulled from Reddit data obtained via their API, so the content dynamically changes. Some of these videos load as "Video Unavailable".
My goal is to detect when this happens, and remove the unavailable video. However, I haven't found a way to detect this state.
What I've tried so far:
- Look in the iframe contents for items with a class of ytp-error. This does not work because all modern browsers prevent javascript from looking inside iframe contents.
- Adding an onError event listener to the player. This does not work because a video being unavailable apparently does not constitute an error in eyes of the player.
I assume there is some call that I can use to detect this in the player, but I have not found such as call. How can this be detected?
I'm using the YouTube iFrame API to embed YouTube videos on my site. The videos are pulled from Reddit data obtained via their API, so the content dynamically changes. Some of these videos load as "Video Unavailable".
My goal is to detect when this happens, and remove the unavailable video. However, I haven't found a way to detect this state.
What I've tried so far:
- Look in the iframe contents for items with a class of ytp-error. This does not work because all modern browsers prevent javascript from looking inside iframe contents.
- Adding an onError event listener to the player. This does not work because a video being unavailable apparently does not constitute an error in eyes of the player.
I assume there is some call that I can use to detect this in the player, but I have not found such as call. How can this be detected?
Share Improve this question edited Oct 27, 2021 at 18:48 Haydentech asked Oct 19, 2021 at 14:32 HaydentechHaydentech 1,2343 gold badges12 silver badges30 bronze badges 1- Check the answers in this question. – Marco Aurelio Fernandez Reyes Commented Oct 26, 2021 at 17:40
1 Answer
Reset to default 7Thankfully, it doesn't require another call to the YT API. In the YouTube iFrame's onReady handler, getPlayerState() will return -1 (unstarted) for "unavailable" videos, while all other videos return a status of 5 (video cued). I can now simply remove all videos from the DOM which have this -1 status.
本文标签: Detect via javascript if video is unavailable when using YouTube iframe playerStack Overflow
版权声明:本文标题:Detect via javascript if video is unavailable when using YouTube iframe player - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745416303a2657699.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论