问题
I use the following code in my web page to successfully autoplay and loop one video. Now, I'd like to add another video, essentially looping two videos. So, after one video is finished playing, the second video will start to play, and then the first video, and so on, and so froth. How should the code be modified to do that?
<iframe width="560" height="315" src=
"https://www.youtube.com/embed/51xS4yXbryc?
rel=0&version=3&playlist=51xS4yXbryc&loop=1
&autoplay=1" frameborder="0" allowfullscreen=""></iframe>
That is a one-line code. I break it into four lines so it's easier to read.
回答1:
For add more than one video in your iframe, you can use the following code:
https://www.youtube.com/embed/<VIDEO_ID_1>?rel=0&version=3&playlist=<VIDEO_ID_2>,<VIDEO_ID_3>,<VIDEO_ID_N>&loop=1&autoplay=1
Where:
VIDEO_ID_1
: is the firstvideoId
to reproduce.VIDEO_ID_2
,VIDEO_ID_3
,VIDEO_ID_N
and so on will be thevideoId
s you want include.
In this way, you can include a max of 196 or 200 videos in the same iframe1 that will autoplay and loop once the final videoId
is reached.
This is a small sample with 4 videos on it.
This is another sample with 93 videos on it.
If you check this playlist, you'll see that it has more than 1000 videos on it - (1653 videos to be exact), but, the iframe resets the threshold to 196 or 200 videos approximately.
1 I discover this threshold when I tried to answer this question in Stack Overflow and you can check it by yourself if you enter to the Youtube website - this playlist and check that it will show only the first 200 videos on it.
This might be a threshold set (and undocumented) by YouTube.
回答2:
A similar question was asked before about iframe and looping. I found this from another question on stackoverflow, a youtube link has a special ? parameter: autoplay. For example in this link
src="https://www.youtube.com/embed/M7lc1UVf-VE ?&autoplay=1& loop=1&rel=0&showinfo=0&color=white&iv_load_policy=3&playlist=M7lc1UVf-VE"
Try adding ?&autoplay=1& considering that worked for someone else.
I found it from here
Update
If you wanna play multiple videos you can do it simply and embed a playlist. You can find how to do so in this article at the Embed a playlist section. Hope this helps.
来源:https://stackoverflow.com/questions/55263250/how-to-loop-two-videos-using-youtube-iframe-code