-
Notifications
You must be signed in to change notification settings - Fork 8
How do you add a simple video player with LightingJS & SolidJS #10
Comments
You can get the VideoElement quite easily via document.getElementById. videoEl in this example is a global reference to the video player object. If I had time I'd create a VideoPlayer component in SolidJS which would wrap commands to the video player tag on the page. |
Ok I understand now lighting uses WebGL which doesnt use html you have to create a video element in the root and then overlay components over the top with LightingJS. <!DOCTYPE html>
<html>
<head>
<title>Solid App</title>
<meta charset="UTF-8" />
<style>
html, body, * { padding: 0; margin: 0}
canvas {
position: absolute;
z-index: 2;
}
</style>
</head>
<body>
<video id="video" style="z-index: 0; position: absolute; top: 0; left: 0; width: 100%; height: 100%;"></video>
<div id="app" style="background-color: transparent;"></div>
<script type="module" src="./src/index.jsx"></script>
</body>
</html> Shaka service import shaka from 'shaka-player';
export class VideoPlayerService {
constructor() {
// Ensure Shaka Player is supported on the platform
if (shaka.Player.isBrowserSupported()) {
// Instantiate Shaka Player
this.player = new shaka.Player(document.getElementById('video'));
this.videoEl = document.getElementById('video');
// Listen for errors
this.player.addEventListener('error', this.onErrorEvent);
} else {
console.error('Browser not supported for Shaka Player!');
}
}
onErrorEvent(event) {
// Log or handle errors
console.error('Error code', event.detail.code, 'object', event.detail);
}
// Method to load a video
loadVideo(manifestUri) {
this.player.load(manifestUri).catch(this.onErrorEvent);
}
play() {
this.videoEl.play();
}
} Video Component import Button from '../components/Button/Button';
import { Row } from '@lightningjs/solid-primitives';
import { VideoPlayerService } from '../components/Button/VideoPlayerService';
const VideoPage = () => {
const videoPlayerService = new VideoPlayerService();
videoPlayerService.loadVideo('https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4');
function onEnter(event, elm) {
this.states.toggle('disabled');
videoPlayerService.play();
}
const RowStyles = {
zIndex: 999,
display: 'flex',
justifyContent: 'flexStart',
width: 1500,
height: 300,
color: '00000000',
gap: 26,
y: 400,
x: 100
}
return (
<Row style={RowStyles}>
<Button autofocus onEnter={onEnter}>Play</Button>
</Row>
);
};
export default VideoPage; Add the z-index for the video player and canvas element and then make the background of the Canvas transparent which I cant figure out how this is done. From what I undertand you should use |
Let me know if you figured this out - sorry for the late reply. Also if you have time to add to the project would love the video player to be built out further - and I think the canvas is clear by default. Just have to make sure all the elements on top are clear as well |
Hi, i am reading through the docs here. https://github.com/Metrological/metrological-sdk/blob/master/docs/plugins/videoplayer.md
For the VideoPlayer plugin.
From what I understand the previous way to add a VideoPlayer was like this.
But this seem to have changed with the new setup with SolidJS. How can you setup a simple player with SolidJS? I know this is wrong as the video el is not outputted to the dom but what can you use in its place?
Any info would be great.
The text was updated successfully, but these errors were encountered: