Kopie van https://gitlab.com/studieverenigingvia/ict/centurion met een paar aanpassingen
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

32 lines
862 B

import {roomTime, useRoom, useRoomRunningChanged, useRoomTime, useTick} from "../lib/Connection";
import {useRef} from "react";
const Player = () => {
const roomRunning = useRoomRunningChanged();
const _ = useRoomTime()
console.log('PLAYER RENDER', roomTime)
const player = useRef(new Audio("centurion.m4a"));
if (roomRunning?.running) {
let targetTime = roomTime() / 1000;
let diff = player.current.currentTime - targetTime;
console.log('PLAYER DIFF', diff);
if (Math.abs(diff) > 0.1) {
player.current.currentTime = targetTime;
}
if (player.current.paused) {
player.current.play().catch(e => {
console.error('Error playing', e);
})
}
} else {
player.current.pause();
}
return null;
}
export default Player;