akborana4 commited on
Commit
d3c70b5
·
verified ·
1 Parent(s): d5174df

Update client/src/Player.jsx

Browse files
Files changed (1) hide show
  1. client/src/Player.jsx +2 -4
client/src/Player.jsx CHANGED
@@ -30,7 +30,7 @@ export default function Player({ socket, roomId, state, isHost }) {
30
  if (busyRef.current) return;
31
  busyRef.current = true;
32
  try {
33
- // set src only when url changes
34
  if (lastAppliedRef.current.url !== state.track.url) {
35
  el.src = state.track.url;
36
  el.load();
@@ -41,7 +41,7 @@ export default function Player({ socket, roomId, state, isHost }) {
41
  try { el.currentTime = Math.max(0, target); } catch {}
42
  }
43
  if (state.isPlaying) {
44
- await el.play().catch(() => {}); // ignore gesture errors
45
  } else {
46
  el.pause();
47
  }
@@ -67,13 +67,11 @@ export default function Player({ socket, roomId, state, isHost }) {
67
  useEffect(() => {
68
  const el = mediaType === 'video' ? videoRef.current : audioRef.current;
69
  if (!el) return;
70
- // drift correction without causing play/pause races
71
  const target = logicalTime();
72
  const delta = target - el.currentTime;
73
  if (Math.abs(delta) > 0.35) {
74
  try { el.currentTime = Math.max(0, target); } catch {}
75
  }
76
- // only adjust if needed
77
  if (state.isPlaying && el.paused) {
78
  el.play().catch(() => {});
79
  } else if (!state.isPlaying && !el.paused) {
 
30
  if (busyRef.current) return;
31
  busyRef.current = true;
32
  try {
33
+ // Reload source only when URL changes
34
  if (lastAppliedRef.current.url !== state.track.url) {
35
  el.src = state.track.url;
36
  el.load();
 
41
  try { el.currentTime = Math.max(0, target); } catch {}
42
  }
43
  if (state.isPlaying) {
44
+ await el.play().catch(() => {}); // ignore user-gesture errors
45
  } else {
46
  el.pause();
47
  }
 
67
  useEffect(() => {
68
  const el = mediaType === 'video' ? videoRef.current : audioRef.current;
69
  if (!el) return;
 
70
  const target = logicalTime();
71
  const delta = target - el.currentTime;
72
  if (Math.abs(delta) > 0.35) {
73
  try { el.currentTime = Math.max(0, target); } catch {}
74
  }
 
75
  if (state.isPlaying && el.paused) {
76
  el.play().catch(() => {});
77
  } else if (!state.isPlaying && !el.paused) {