Open davidevaliante opened 4 years ago
Have you figure out how to use it in react? I want to ask same question.
Have you figure out how to use it in react? I want to ask same question.
@jacksun0124 yeah i kind of did
import React, { useRef, useState, useEffect } from 'react';
import videojs from 'video.js'
import 'video.js/dist/video-js.css';
// those imports are important
import qualitySelector from 'videojs-hls-quality-selector';
import qualityLevels from 'videojs-contrib-quality-levels'
const LivePlayer = ({ videoLink }) => {
const videoRef = useRef()
const [player, setPlayer] = useState(undefined)
useEffect(() => {
const videoJsOptions = {
autoplay: false,
controls: true,
fluid: true,
muted: true,
responsive: true,
sources: [{
src: videoLink,
}],
}
videojs.registerPlugin('hlsQualitySelector', qualitySelector)
const p = videojs(videoRef.current, videoJsOptions, function onPlayerReaady() {
console.log('onPlayerReady')
})
setPlayer(p)
return () => {
if (player) player.dispose()
};
}, [])
useEffect(() => {
if (player) player.hlsQualitySelector({ displayCurrentQuality: true })
}, [player])
return (
<div data-vjs-player>
<video ref={videoRef} className="video-js"></video>
</div>
);
};
I did run into an issue recently where the quality selector no longer worked. I ended up having to do this.
import contribQualityLevels from 'videojs-contrib-quality-levels'
videojs.registerPlugin('qualityLevels', contribQualityLevels)
@kobaltz can you please share the full implementation of quality selector?
I was having same issues if someone is looking for code or an answer this is how I got it work:
import 'videojs-contrib-quality-levels';
import 'videojs-hls-quality-selector';
and in my useEffect hook
useEffect(() => {
const player = videojs(
playerRef.current,
{
controls: true
},
() => {
player.src(videoSrc);
player.hlsQualitySelector({
displayCurrentQuality: true
});
}
);
It is important to call your player.hlsQualitySelector
after you set player.src
This worked for me
import React, { useRef, useState, useEffect } from 'react';
import videojs from 'video.js';
// those imports are important
import qualitySelector from 'videojs-hls-quality-selector';
import qualityLevels from 'videojs-contrib-quality-levels';
const VideoPlayer = ({ liveURL }) => {
const videoRef = useRef();
const [player, setPlayer] = useState(undefined);
useEffect(() => {
if (player) {
player.src([liveURL]);
}
}, [liveURL]);
useEffect(() => {
const videoJsOptions = {
preload: 'auto',
autoplay: 'any',
controls: true,
fluid: true,
responsive: true,
sources: [
{
src: liveURL,
},
],
};
videojs.registerPlugin('hlsQualitySelector', qualitySelector);
const p = videojs(videoRef.current, videoJsOptions, function onPlayerReaady() {
// console.log('onPlayerReady');
});
setPlayer(p);
return () => {
if (player) player.dispose();
};
}, []);
useEffect(() => {
if (player) player.hlsQualitySelector({ displayCurrentQuality: true });
}, [player]);
return (
<div data-vjs-player>
<video ref={videoRef} className="video-js vjs-default-skin vjs-big-play-centered"></video>
</div>
);
};
export default VideoPlayer;
@AbdelazizEid can you share your package.json or the version of videojs, videojs-hls-quality-selector, videojs-contrib-quality-levels
what i have tried so far :
The player shows and starts playing but it only has the default controls