Skip to content
Snippets Groups Projects
Commit 2c69b68b authored by DuckyDuck69's avatar DuckyDuck69
Browse files

video feature

parent 2f0d1382
No related branches found
No related tags found
1 merge request!3video feature
import TimeDuration from "./components/TimeDuration"
import Title from "./components/Title"
import Video from "./components/Video"
function App() {
return (
<>
<div className="page-container">
<Title/>
<Video/>
<TimeDuration/>
</div>
</>
......
......@@ -55,8 +55,7 @@ function TimeDuration() {
onChange={(e) => setMinute(e.target.value)}
/>
</div>
<button onClick={()=>console.log(handleTimeInput())}>rereive time</button>
<button onClick={startTimer}>Timer</button>
<button onClick={startTimer}>Start timer</button>
<button onClick={() => clearInterval(intervalID.current)}>Stop timer</button>
<button onClick={runTime}>Resume</button>
<button onClick={() => setSecond(0)}>Reset timer</button>
......
import { useRef } from "react";
function Video() {
const videoRef = useRef(null);
const streamRef = useRef(null);
function stopCam(){
if(streamRef.current){
streamRef.current.getTracks().forEach(track => {
track.stop();
});
streamRef.current = null //clean the ref
}
}
function startCam(){
navigator.mediaDevices
.getUserMedia({ video: true })
.then((stream) => {
if (videoRef.current) {
streamRef.current = stream;
videoRef.current.srcObject = stream; // Connect the stream to the <video>
videoRef.current.play(); // Start playing the video
}
})
.catch((error) => {
console.log("Error:", error);
});
}
return (
<>
<video
ref={videoRef}
width="640"
height="480"
autoPlay
muted
style={{ transform: "scaleX(-1)" }}
></video>
<button onClick={startCam}>Start Camera</button>
<button onClick={stopCam}>Stop Camera</button>
</>
);
}
export default Video;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment