justinmahar / react-social-media-embed

📰 Easily embed social media posts from Facebook, Instagram, LinkedIn, Pinterest, TikTok, X (Twitter), and YouTube in React.
https://justinmahar.github.io/react-social-media-embed/
MIT License
215 stars 30 forks source link

disable autoplay with tiktok embeds #43

Open nicollegah opened 1 year ago

nicollegah commented 1 year ago

Hey,

awesome project, it really alleviates some pain of including all these social media posts. I am wondering if it's possible to disable autoplay for TikTok videos. It is automatically disabled for Instagram and Twitter videos but the TikTok ones play on load and eat up memory.

Or am I overlooking something?

Thanks,

Nico

PeterHueer commented 1 year ago

It's possible to improve the library by working with the oembed standard which tiktok offers.

https://www.tiktok.com/oembed?url=https://www.tiktok.com/@scout2015/video/6718335390845095173

As you can see the oembed endpoint gives you a bunch of informations. We're interested in the thumbnail data.

My implementation plan would be the following:

  1. Fetch oembed data for the passed url
  2. Save thumbnail data
  3. Show thumbnail as regular <img /> with the specified dimensions (or make it responsive with width 100%)
  4. Add onClick handler on the <img /> Tag where the <img /> will be replaced with the embedded code which automatically starts.

Hope this helps