You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

关于嵌入式视频设置播放结束后自动重播的技术咨询

关于嵌入式视频设置播放结束后自动重播的技术咨询

Hey there! Let's figure out how to get your embedded YouTube video to replay automatically when it ends.

First, looking at your existing code, I notice you already added loop=1 to your iframe's URL parameters—but it might not be working because YouTube's loop parameter requires the playlist parameter to be set to the same video ID for single-video loops to work. That's a common gotcha!

Also, there's a small bug in your iframe code: you accidentally duplicated the closing part of the iframe tag at the end, which could cause rendering issues. Let's fix that up too.

Here's the adjusted code that should make your video loop properly:

if (item.getAttribute("value").includes('http')) {
    // Fixed iframe URL with playlist parameter, and removed duplicate closing code
    document.getElementById('player').innerHTML = `<iframe width="1179" height="663" src="https://www.youtube.com/embed/668nUCeBHyY?autoplay=1&cc_load_policy=1&controls=0&disablekb=1&fs=0&iv_load_policy=3&loop=1&autopause=0&playlist=668nUCeBHyY" frameborder="0" allow="accelerometer; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>`;
    console.log("I'm here in the if block");
    const video = document.getElementById('player');
}

Let me break down the key fixes:

  • Added &playlist=668nUCeBHyY to the iframe URL: This tells YouTube to treat the single video as a playlist, which makes the loop=1 parameter actually trigger a replay.
  • Removed the duplicate errerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe> part at the end of your iframe code—this was causing invalid HTML that might have broken the player.

If you ever need more control (like triggering custom actions when the video ends), you could use the YouTube IFrame API to listen for the onStateChange event, but for simple auto-replay, the parameter fix above is the easiest way to go.

Hope that gets your video looping smoothly!

备注:内容来源于stack exchange,提问作者AbderaoufLaib

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.16 07:43:15