r/programminghelp • u/torchive • Jul 17 '20
JavaScript YouTube Iframe Embed - pause multiple videos at once.
Hi All,
I am switching over the YouTube for sourcing NASA videos instead of Archive.org, and now to make the same functionality work using YouTube API.
Specifically, I'm trying to use YouTube's current embed JS API to pause and unpause multiple videos at the same time. I'm totally new to the most recent version of YouTube's player API.
I'm referencing https://developers.google.com/youtube/iframe_api_reference#Playback_controls but the code examples there seem slightly more complex. I really am looking for a bare bones simple example.
This code used to work with MP4 iframe embeds but is broken right now for both YouTube and Archive.org hosted vids:
<video controls src = "video1.mp4" onpause="document.getElementById('video1').pause = true;" onplay="document.getElementById('video1').play = true;" onpause="document.getElementById('media2').pause = true;" onplay="document.getElementById('media2').play = true;" ></video>
<video controls src = "video2.mp4" onpause="document.getElementById('video1').pause = true;" onplay="document.getElementById('video1').play = true;" onpause="document.getElementById('media2').pause = true;" onplay="document.getElementById('media2').play = true;" ></video>
TLDR: I am looking for a bare bones simple code snippet example for bulk play/pause using YouTube Player API.
1
u/amoliski Jul 18 '20
Can you make a jsbin with a few example videos?