question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Description

How can I use React components along with VideoJS like in your example https://naver.github.io/egjs-view360/examples/panoviewer/etc/videojs.html ?

I have components:

export const useVideoJS = (videoJsOptions) => {
	const videoNode = useRef(null)
	const player = useRef(null)

	let changedKey = videoJsOptions.key;

	useEffect(() => {
		player.current = videojs(videoNode.current, videoJsOptions)

		return () => {
			player.current.dispose()
		}
	}, [changedKey])

	const Video = useCallback(
		({ children, ...props }) => {
			return (
				<div data-vjs-player key={changedKey}>
					<video ref={videoNode} className="video-js" {...props}>
						{children}
					</video>
				</div>
			)
		},
		[changedKey],
	)
	return { Video, player: player.current }
}

I use it like

import './App.css';
import { useVideoJS } from './hooks/useVideoJS';

import vid from './source/vid2.mp4'

function App() {

	const video = {
		url: vid,
		subtitlesUrl: vid
	}

	const { Video } = useVideoJS({
		sources: [{ src: video.url }],
		controls: true,
		playbackRates: [0.5, 1, 1.5, 2],
		responsive: true,
		key: 'VideoJS'
	})

	return (
		<div>
			<Video playsInline muted>
				<track
					src={video.subtitlesUrl}
					kind="subtitles"
					srcLang="en"
					label="English"
				/>
			</Video>
		</div>
	);
}

export default App;

and have simple

<PanoViewer
		tag="div"
		id='viewer'
		video={video.src}
		projectionType={PROJECTION_TYPE.EQUIRECTANGULAR}
		useZoom={false}
		onViewChange={e => {}}
		onReady={e =>{}}
		showPolePoint={true}
	>
	</PanoViewer>

Help me please. I have been working on this problem for several days. Nothing works

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
WoodNeckcommented, Apr 14, 2022

Hello @stormofe! Sorry for the long wait, I missed checking this issue by mistake. Here’s the working demo:

import React from "react";
import videojs from "video.js";
import { PanoViewer } from "@egjs/react-view360";
import "video.js/dist/video-js.css";

export default class VideoJSDemo extends React.Component {
  private _panoViewer: PanoViewer;
  private _videoRef: HTMLVideoElement;

  public componentDidMount() {
    videojs(this._videoRef).ready(() => {
      this._videoRef.style.display = "none";
      this._panoViewer.setVideo(this._videoRef, {
        projectionType: "equirectangular",
      });
    });
  }

  public render() {
    return <div>
      <PanoViewer ref={ref => {
        ref && (this._panoViewer = ref);
      }} id="viewer" data-vjs-player>
        <video ref={ref => {
          ref && (this._videoRef = ref);
        }} className="video-js vjs-fluid vjs-default-skin vjs-big-play-centered vjs-controls-enabled" crossOrigin="anonymous" playsinline={true} controls loop
        style={{ width: "100%", height: "100%" }}>
          <source src="https://naver.github.io/egjs-view360/examples/panoviewer/etc/img/seven.mp4" type="video/mp4" />
          <source src="https://naver.github.io/egjs-view360/examples/panoviewer/etc/img/seven.webm" type="video/webm"></source>
        </video>
      </PanoViewer>
    </div>
  }
}

I promise to add this demo to the next version 😃

0reactions
tap2kcommented, Oct 12, 2022

I tried using this example code exactly as written and the video does not take up the whole viewport. Am I doing something wrong?

Read more comments on GitHub >

github_iconTop Results From Across the Web

React and Video.js
A brief guide to using Video.js with React. ... These are several React and Video.js player implementations and examples. Don't forget to include...
Read more >
A sample Video.js with React project - CodeSandbox
A sample Video.js with React project. See https://github.com/videojs/video.js/blob/master/docs/guides/react.md for more info.
Read more >
videojs-react-enhanced - npm
React.js wrapper component for Video.js player with handy and powerful features. NOTE: The basic feature is working, but still it's currently ...
Read more >
Video.js with React Hooks - Barstool Engineering
js documentation gives an example of how to use Video.js with React but the example uses class based components and is a bit...
Read more >
How to use videojs in React | Swift Discovery - onmyway133
Issue #803 import React from 'react'; import videojs from 'video.js' import 'video.js/dist/video-js.css'; export default class VideoPlayer ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found