CameraContext.flip
Bắt đầu hỗ trợ ở phiên bản:
- SDK: 2.39.0
Chuyển camera trước/sau
import React, { useEffect, useRef } from "react";
import { Box, Button, Page } from "zmp-ui";
import api, { FacingMode, ZMACamera } from "zmp-sdk";
const HomePage = () => {
const cameraRef = (useRef < ZMACamera) | (null > null);
const videoRef = useRef < HTMLVideoElement > null;
useEffect(() => {
const videoElement = videoRef.current;
if (!videoElement) {
console.log("Media component not ready");
return;
}
if (!cameraRef.current) {
cameraRef.current = api.createCameraContext({
videoElement: videoElement,
mediaConstraints: {
width: 640,
height: 480,
facingMode: FacingMode.BACK,
audio: false,
},
});
}
}, []);
return (
<Page>
<Box>
<video
style={{ width: "100vw", height: "auto" }}
ref={videoRef}
muted
playsInline
webkit-playsinline
/>
</Box>
<Box mt={5} flex alignContent={"center"}>
<Button
size={"small"}
variant="primary"
onClick={async () => await cameraRef.current?.start()}
>
Start Stream
</Button>
<Button
size={"small"}
variant="primary"
onClick={async () => await cameraRef.current?.flip()}
>
Flip Camera
</Button>
</Box>
</Page>
);
};
export default HomePage;