fix camera

This commit is contained in:
Michael committed 2026-01-22 17:35:33 +01:00
1 parent b4347d068d
commit ff9453a3e4
1 file changed
+23 -16
+23 -16
View File
@@ -52,32 +52,39 @@ export function CameraRecorder({ onCapture, onCancel }: CameraRecorderProps) {
const config = QUALITY_CONFIGS[quality]; const config = QUALITY_CONFIGS[quality];
console.log(`📸 Starting camera: ${config.label}, facing: ${facingMode}`); console.log(`📸 Starting camera: ${config.label}, facing: ${facingMode}`);
const constraints: MediaStreamConstraints = { // Simple constraints that work on all devices
audio: { const simpleConstraints: MediaStreamConstraints = {
echoCancellation: true, audio: true,
noiseSuppression: true,
},
video: { video: {
facingMode: facingMode, facingMode: facingMode,
width: { ideal: config.width, min: 640 }, width: { ideal: config.width },
height: { ideal: config.height, min: 480 }, height: { ideal: config.height },
frameRate: { ideal: 30 },
// @ts-ignore - Advanced constraints for iOS stabilization
advanced: [
{ zoom: 1.0 },
// Enable video stabilization on supported devices (iOS)
{ videoStabilizationMode: 'cinematic' },
{ videoStabilizationMode: 'auto' },
]
} }
}; };
const newStream = await navigator.mediaDevices.getUserMedia(constraints); let newStream: MediaStream;
try {
// Try to get camera with simple constraints
newStream = await navigator.mediaDevices.getUserMedia(simpleConstraints);
console.log('✅ Camera obtained with simple constraints');
} catch (err) {
console.warn('⚠️ Simple constraints failed, trying minimal:', err);
// Fallback to minimal constraints
newStream = await navigator.mediaDevices.getUserMedia({
audio: true,
video: { facingMode: facingMode }
});
console.log('✅ Camera obtained with minimal constraints');
}
setStream(newStream); setStream(newStream);
if (videoRef.current) { if (videoRef.current) {
videoRef.current.srcObject = newStream; videoRef.current.srcObject = newStream;
videoRef.current.volume = 0; videoRef.current.volume = 0;
// Ensure video plays on iOS
await videoRef.current.play().catch(() => { });
} }
// Check actual resolution // Check actual resolution