fix camera startup fallbacks

这个提交包含在:
cryptocommuniums-afk
2026-03-16 22:23:58 +08:00
父节点 09b1b95e2c
当前提交 a211562860
修改 3 个文件,包含 125 行新增11 行删除

查看文件

@@ -17,7 +17,7 @@ import { Slider } from "@/components/ui/slider";
import { Switch } from "@/components/ui/switch";
import { formatDateTimeShanghai } from "@/lib/time";
import { toast } from "sonner";
import { applyTrackZoom, type CameraQualityPreset, getCameraVideoConstraints, getLiveAnalysisBitrate, readTrackZoomState } from "@/lib/camera";
import { applyTrackZoom, type CameraQualityPreset, getLiveAnalysisBitrate, readTrackZoomState, requestCameraStream } from "@/lib/camera";
import {
ACTION_WINDOW_FRAMES,
AVATAR_PRESETS,
@@ -1221,20 +1221,24 @@ export default function LiveCamera() {
if (streamRef.current) {
streamRef.current.getTracks().forEach((track) => track.stop());
}
const constraints: MediaStreamConstraints = {
video: getCameraVideoConstraints(nextFacing, mobile, preset),
audio: false,
};
const stream = await navigator.mediaDevices.getUserMedia(constraints);
const { stream, appliedFacingMode, usedFallback } = await requestCameraStream({
facingMode: nextFacing,
isMobile: mobile,
preset,
});
streamRef.current = stream;
if (appliedFacingMode !== nextFacing) {
setFacing(appliedFacingMode);
}
if (videoRef.current) {
videoRef.current.srcObject = stream;
await videoRef.current.play();
}
await syncZoomState(preferredZoom, stream.getVideoTracks()[0] || null);
setCameraActive(true);
if (usedFallback) {
toast.info("当前设备已自动切换到兼容摄像头模式");
}
toast.success("摄像头已启动");
} catch (error: any) {
toast.error(`摄像头启动失败: ${error?.message || "未知错误"}`);