Menu

1 / 2

Things That Bit Me Wrapping the YouTube IFrame API for a Kids' App

DEV Community: react·Yuriy Stasyuk·19 days ago
#UqZL656S
#devtoreact#devto#dev#youtube#film
Reading 0:00
15s threshold

I built WiseTube because the YouTube sidebar kept leading my kids somewhere I didn't want them. It's a free library of hand-picked learning videos that play inside my own player, with YouTube's suggestions, Shorts and autoplay-to-the-next-thing taken out.

The covering-up part gets most of the attention. This post is about the smaller stuff that cost me evenings. If you're wrapping the IFrame API for anything, some of these will probably find you too.

1. The API script can hang, so give it a deadline

You load https://www.youtube.com/iframe_api and wait for onYouTubeIframeAPIReady . Most of the time it's fine. On a flaky connection it can sit there forever, and a kid staring at a spinner will go find another app.

I wrap the load in a promise, cache it so it only happens once, and clear the cache if the script errors so the next try starts clean. The player also starts a 15 second timer. If onReady hasn't fired by then, it shows "The film didn't load" with a retry button.

2.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.