OvenPlayer
OvenPlayer copied to clipboard
OvenPlayer in React.js component
i need help about using OvenPlayer in React.js component couldn't find any way to do that , is it possible ? if yes can you please add here a code snippet ?
I've started work on a Vue wrapper for OvenPlayer, so I may soon be able to offer some tips, as Vue's component lifecycle is similar. I'll keep you posted.
@command-tab okay bro thank you when you make it work just inform me please
With the release of OvenPlayer 0.10.15, it's pretty straightforward to wrap OvenPlayer in a Vue or React component:
- Add
ovenplayer
to your package.json and install it - Create a new component file and import the library with
import OvenPlayer from 'ovenplayer'
- Make the component accept an
options
prop - In React's equivalent of
mounted
(i.e. when the DOM node for the component is actually applied to the DOM), instantiate OvenPlayer and pass in a reference to the target DOM node and theoptions
prop:OvenPlayer.create(this.$refs.player, this.options)
- (Maybe Vue-specific?) Bind OvenPlayer events to component events so OvenPlayer events trigger component-level events that consumers of your component can act upon
- In the component's teardown/deconstructor method, clean up OvenPlayer:
this.player.remove()
Here's a minimal but working Vue component example: https://gist.github.com/command-tab/e8809b0857fbf6a223eb4bbf7e236751
thank you so much bro im gonna try it and i will ask you if i have any questions about it
While I haven't tried it, it appears you need to include hls.js in your <head>
to make it available:
<script src="https://cdn.jsdelivr.net/npm/hls.js@latest/dist/hls.min.js"></script>
Then, wherever you invoke OvenPlayer, tell it to use a source that's type: 'hls'
and ensure you pass a .m3u8
HLS playlist URL to the file
option.
With the release of OvenPlayer 0.10.15, it's pretty straightforward to wrap OvenPlayer in a Vue or React component:
- Add
ovenplayer
to your package.json and install it- Create a new component file and import the library with
import OvenPlayer from 'ovenplayer'
- Make the component accept an
options
prop- In React's equivalent of
mounted
(i.e. when the DOM node for the component is actually applied to the DOM), instantiate OvenPlayer and pass in a reference to the target DOM node and theoptions
prop:OvenPlayer.create(this.$refs.player, this.options)
- (Maybe Vue-specific?) Bind OvenPlayer events to component events so OvenPlayer events trigger component-level events that consumers of your component can act upon
- In the component's teardown/deconstructor method, clean up OvenPlayer:
this.player.remove()
Here's a minimal but working Vue component example: https://gist.github.com/command-tab/e8809b0857fbf6a223eb4bbf7e236751
in es modules and vue 3 error
Error initializing HLS.