This requires one more thing. The YouTube video URL needs parameters to tell it to accept commands. In my application, which is Drupal 9, I use a hook to modify the URL of all YouTube video URLs.
Example URL: https://www.youtube.com/embed/f5piHKZPoP4?rel=0&autoplay=0&enablejsapi=1
Specifically, the "enablejsapi" parameter is what enables this. I will also share a php file with the Drupal hook I used for this.
To learn more about the optional parameters you can pass, look at this documentation: https://developers.google.com/youtube/player_parameters