video player commands

This commit is contained in:
Evert Prants 2022-04-09 22:01:48 +03:00
parent a6dd97f777
commit 53ce49257b
Signed by: evert
GPG Key ID: 1688DA83D222D0B5
2 changed files with 19 additions and 1 deletions

View File

@ -53,10 +53,16 @@ export class Game {
return; return;
} }
if (message.startsWith('!stop')) { if (message.startsWith('!stop') || message.startsWith('!pause')) {
this.videoTest.stop(); this.videoTest.stop();
return; return;
} }
if (message.startsWith('!volume')) {
const [cmd, vol] = message.split(' ');
this.videoTest.setVolume(parseInt(vol.replace('%', ''), 10));
return;
}
// end of // end of
this.socket.emit('chat-send', message); this.socket.emit('chat-send', message);

View File

@ -6,6 +6,7 @@ import {
PlaneGeometry, PlaneGeometry,
VideoTexture, VideoTexture,
} from 'three'; } from 'three';
import { clamp } from 'three/src/math/MathUtils';
export class VideoPlayer { export class VideoPlayer {
public video = document.createElement('video'); public video = document.createElement('video');
@ -28,6 +29,12 @@ export class VideoPlayer {
this.video.addEventListener('canplay', () => { this.video.addEventListener('canplay', () => {
this.playable = true; this.playable = true;
}); });
this.video.addEventListener('error', () => {
this.playable = false;
this.video.pause();
this.video.src = undefined;
});
} }
public setSource(source: string, autoplay = false) { public setSource(source: string, autoplay = false) {
@ -82,4 +89,9 @@ export class VideoPlayer {
this.hls.stopLoad(); this.hls.stopLoad();
} }
} }
public setVolume(percent: number) {
const setter = clamp(percent, 0, 100) / 100;
this.video.volume = setter;
}
} }