Skip to content

Commit 398b634

Browse files
committed
Try to improve touch controls
1 parent 9cec182 commit 398b634

1 file changed

Lines changed: 16 additions & 5 deletions

File tree

src/components/VideoPlayer.tsx

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,14 @@ export const VideoPlayer: React.FC<VideoPlayerProps> = ({ src, playbackRate, onE
2222
videoRef.current.appendChild(videoElement);
2323

2424
const player = videojs(videoElement, {
25-
controls: false,
25+
controls: false, // No UI controls since we want tap to play/pause
2626
userActions: {
27-
click: true
27+
click: true // Let Video.js handle clicks
2828
},
2929
autoplay: false,
3030
preload: 'auto',
31-
fluid: true,
31+
fluid: true, // Responsive by default
32+
playsinline: true, // Important for iOS
3233
techOrder: ['youtube'],
3334
sources: [{
3435
type: 'video/youtube',
@@ -45,10 +46,14 @@ export const VideoPlayer: React.FC<VideoPlayerProps> = ({ src, playbackRate, onE
4546
}, () => {
4647
player.playbackRate(playbackRate);
4748

48-
// Explicit click handler for touch/interaction
49+
// Tap/click to play/pause - using Video.js's built-in click handler
50+
// since we set userActions.click = true
4951
player.on('click', () => {
5052
if (player.paused()) {
51-
player.play();
53+
player.play().catch((err: any) => {
54+
// Autoplay may be blocked - that's okay
55+
console.log('Playback requires user interaction on some devices');
56+
});
5257
} else {
5358
player.pause();
5459
}
@@ -59,6 +64,11 @@ export const VideoPlayer: React.FC<VideoPlayerProps> = ({ src, playbackRate, onE
5964
console.error('VideoJS Error:', err);
6065
if (onError) onError(err);
6166
});
67+
68+
// Handle mobile touch events gracefully
69+
player.on('touchstart', () => {
70+
// No need to prevent default - let browser handle naturally
71+
});
6272
});
6373

6474
playerRef.current = player;
@@ -67,6 +77,7 @@ export const VideoPlayer: React.FC<VideoPlayerProps> = ({ src, playbackRate, onE
6777
const player = playerRef.current;
6878
if (player.currentSrc() !== src) {
6979
player.src({ type: 'video/youtube', src });
80+
player.load();
7081
}
7182
}
7283
}, [src]);

0 commit comments

Comments
 (0)