Skip to content

Commit 7819814

Browse files
committed
click video to enable sound
1 parent 19b1428 commit 7819814

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

app/page.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ import Image from "next/image";
44
import { useEffect, useRef } from "react";
55

66
export default function Page() {
7+
const videoRef = useRef<HTMLVideoElement>(null);
8+
9+
function unmuteVideo() {
10+
if (videoRef.current) {
11+
videoRef.current.muted = false;
12+
}
13+
}
14+
715
return (
816
<>
917
<div className="flex justify-center items-center min-h-screen bg-purple-200">
@@ -14,7 +22,7 @@ export default function Page() {
1422
width={500}
1523
height={500} />
1624
<div>
17-
<video loop autoPlay muted playsInline height="500" width="500">
25+
<video ref={videoRef} onClick={unmuteVideo} className="cursor-pointer" loop autoPlay muted playsInline height="500" width="500">
1826
<source src="/never-gonna-give-up.mp4" type="video/mp4" />
1927
</video>
2028
</div>

0 commit comments

Comments
 (0)