Skip to content

Commit 009b295

Browse files
committed
click video enables sound
1 parent 71edf09 commit 009b295

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

app/page.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
1+
'use client';
2+
13
import Image from "next/image";
4+
import { useEffect, useRef } from "react";
25

36
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+
415
return (
516
<>
617
<div className="flex justify-center items-center min-h-screen bg-purple-200">
@@ -11,7 +22,7 @@ export default function Page() {
1122
width={500}
1223
height={500} />
1324
<div>
14-
<video loop autoPlay muted height="500" width="500">
25+
<video ref={videoRef} onClick={unmuteVideo} className="cursor-pointer" loop autoPlay muted height="500" width="500">
1526
<source src="/never-gonna-give-up.mp4" type="video/mp4" />
1627
</video>
1728
</div>

0 commit comments

Comments
 (0)