Comments (6)
Find a proper way to expose the player API which is returned by IndigoPlayer.init
You could have a prop called onPlayerDraw
or some such that fires after a player is ready and sends back the player along with anything else that is needed, like if (typeof onPlayerDraw === 'function') onPlayerDraw({player});
It would allow you to get the player API to the user if they want it (some may not need it) and allow them to run their own functionality to deal with the player draw (like autoplay checks and the like).
from indigo-player.
I've had to use the same thing on a React project to notify a parent component that a child component is now hidden.
from indigo-player.
Thought about it too but using a callback on a sync instruction (IndigoPlayer.init is sync) feels a bit counter-intuitive. One thing I'd like to try is using the useRef
hook to create a reference to the player in combination with the useImperativeHandle
hook to provide strictly the player API in the ref.
Eg:
const player = useRef();
// Access controller
// eg: player.current.play(), player.current.pause(), ...
// Access state
// indigo-player can provide these kind of hooks, eg: `usePlayerState(ref)`
const [playerState, setPlayerState] = useState(null);
useEffect(() => {
if (player.current) {
player.current.addListener(Events.STATE_CHANGE, state => setPlayerState(state));
return () => player.current.removeListener(Events.STATE_CHANGE);
}
}, [player.current]);
// eg: access state like playerState.playing, playerState.paused, ...
<Player ref={player} config={config} />
I'll have a play with this in the upcoming days.
from indigo-player.
Any updates on this idea @matvp91 ?
from indigo-player.
@FreddyJD not at the moment, I've recently merged in #53 which is a first step in a better module structure. Once I've cleared out the other roadblocks (and maintain backwards compatibility), you'll be able to install indigo-player
as a module. This would make it a whole lot easier to wrap it around a React component.
Edit: The following code should get you started, simply run yarn add indigo-player
(or npm) and you're good to go:
import React from "react";
import ReactDOM from "react-dom";
import indigoPlayer from "indigo-player";
import "indigo-player/lib/indigo-theme.css";
function App() {
const ref = React.useRef();
React.useEffect(() => {
indigoPlayer.init(ref.current, {
sources: [
{
type: "mp4",
src:
"https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4",
},
],
});
}, []);
return (
<div>
<div ref={ref} />
</div>
);
}
ReactDOM.render(<App />, document.getElementById("root"));
Although there is no official integration for indigo-player with React yet, the sample above should get anyone going who wants to implement this in React.
from indigo-player.
@matvp91 Thanks for the sample.
Unfortunately I'm new to both React and Typescript and thought I'd found a holy-grail here, but alas I can't get it to work as is.
Property 'init' does not exist on type 'typeof import("/home/jon/source/myapp/node_modules/indigo-player/src/index")'.
I did manage to fix an issue with the useRef usage by making the following change:
const ref = useRef<HTMLDivElement>(null);
from indigo-player.
Related Issues (20)
- Firefox not loading custom ThumbnailExtension
- Autoplay even if autoplay is set to false
- crossorigin attribute configuration
- Can't seek when two players are in one page
- full screen doesnt work on mobile
- sorry.... i mistaked.... :((((
- Live Indicator
- Quality Labels HOT 1
- theme.css is automatically loaded when imported as a module HOT 1
- Vertical cropping
- IMA Advertising in PIP-mode
- player often hangs on navigation HOT 3
- google drive support?
- can support blob? HOT 3
- Can we add multiple audio to hls?
- Missing return types in src/{index.d.ts,types.ts}
- Missing init function in src/{index.d.ts}
- Poster image.
- fit to screen
- Play videos one after the another based on the queue in Indigo player
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 indigo-player.