Hey everyone! I’m working on a project where I need to make YouTube videos stop at a specific time. I already know how to make them start at a certain point using &t=45 or similar, but I can’t find anything about making them end early.
Basically I want the video to automatically stop playing at let’s say 2 minutes and 30 seconds, even if the actual video is longer. Is there a parameter I can add to the embed URL to do this?
If YouTube doesn’t have a built-in way to do this, what would be some alternative approaches? I’m building this for a website so I’m open to using JavaScript or other solutions if needed.
I’ve looked through various YouTube embedding guides but haven’t found anything useful yet. Any help would be great!
yeah, youtube doesn’t have a direct end param, but fr using js to control it is the way to go. just like that other user said, you can check the time and pause it. also, prior editing is a solid choice if it’s a fixed need.
Nope, YouTube’s embed API doesn’t have a native stop parameter like it does for start times. Hit this same problem about six months back when I was building a tutorial site. What worked for me was using the YouTube Player API with JavaScript to watch the current time and pause at your target. Just set up an interval that checks getCurrentTime() every few hundred milliseconds, then call pauseVideo() when it hits your endpoint. Pretty straightforward once you’ve got the API loaded. I’ve seen people use the onStateChange event listener too, but polling felt more solid when I tested both. Don’t forget to clear your interval when the video ends or gets paused manually - otherwise you’ll get memory leaks.