Comments (5)
Could be solved if we could just use a ref prop that would be forwarded to the iframe, so it could be programatically controlled.
from react-lite-youtube-embed.
Hey @ibrahimcesar somehow ref
is always null for me.
"use client"
import LiteYouTubeEmbed from 'react-lite-youtube-embed';
import 'react-lite-youtube-embed/dist/LiteYouTubeEmbed.css';
import {useRef} from "react";
export function VideoPlayer() {
const myRef = useRef<HTMLIFrameElement>(null)
return <div style={{width: '800px'}}>
<LiteYouTubeEmbed
id="zjkBMFhNj_g" // Default none, id of the video or playlist
adNetwork={true} // Default true, to preconnect or not to doubleclick addresses called by YouTube iframe (the adnetwork from Google)
params="" // any params you want to pass to the URL, assume we already had '&' and pass your parameters string
playlist={false} // Use true when your ID be from a playlist
playlistCoverId="L2vS_050c-M" // The ids for playlists did not bring the cover in a pattern to render so you'll need pick up a video from the playlist (or in fact, whatever id) and use to render the cover. There's a programmatic way to get the cover from YouTube API v3 but the aim of this component is do not make any another call and reduce requests and bandwidth usage as much as possibe
poster="hqdefault" // Defines the image size to call on first render as poster image. Possible values are "default","mqdefault", "hqdefault", "sddefault" and "maxresdefault". Default value for this prop is "hqdefault". Please be aware that "sddefault" and "maxresdefault", high resolution images are not always avaialble for every video. See: https://stackoverflow.com/questions/2068344/how-do-i-get-a-youtube-video-thumbnail-from-the-youtube-api
title="YouTube Embed" // a11y, always provide a title for iFrames: https://dequeuniversity.com/tips/provide-iframe-titles Help the web be accessible ;)
noCookie={true} // Default false, connect to YouTube via the Privacy-Enhanced Mode using https://www.youtube-nocookie.com
ref={myRef} // Use this ref prop to programmatically access the underlying iframe element
/>
<button style={{marginTop: '100px'}} onClick={() => {
console.log(myRef) // outputs {current: null}
// @ts-ignore
myRef.current.play()
}}>Play
</button>
</div>
}
I'm using v2.4
from react-lite-youtube-embed.
onIframeAdded
is not that helpful, we need the instance of the video object in return. That will help us manage the play and pause state of the video. Thanks :)
from react-lite-youtube-embed.
Solved by #87
from react-lite-youtube-embed.
Related Issues (20)
- Trouble using both ref and onIframeAdded
- When playing a Safari video, a black margin appears on the left side
- Announce property is not optional HOT 4
- Add poster fallback quality HOT 5
- Add custom thumbnail import HOT 1
- Have to press pay button twice on safari HOT 6
- Iframe/component should display decent view once video completes HOT 2
- If I parse LiteYouTubeEmbed as html on the server side, will it not work?
- Lazy load thumbnail image HOT 4
- you need to double click while using this on mobile HOT 6
- iframe doesn't exist when onIframeAdded is called HOT 1
- Initially render with a low quality thumbnail for loading speeds, then load a higher res thumbnail when idle HOT 3
- usage of --aspect-ratio variable without fallback
- Vertical video - aspect ratio props don't seem to have an effect HOT 1
- Set option for prefetch or preload for Image thumbnail HOT 1
- The LiteYouTube interface export HOT 1
- Improve SEO
- Generated dist file uses .jsx ending, but not JSX syntax, making it difficult to import from Node
- Can we hide the suggested videos after completing the video? HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-lite-youtube-embed.