XCode 9.4(Mac)中Logitech C525摄像头不被识别为AVMediaTypeVideo问题
Hey there, let's walk through some practical steps to figure out why your Logitech C525 isn't being recognized as a video device in your AVFoundation code. Here's what to check:
Inspect the device's actual supported media types
When looping through[AVCaptureDevice devices], add a log to print exactly what media types the C525 reports:for (AVCaptureDevice *device in [AVCaptureDevice devices]) { NSLog(@"Device: %@, Supported media types: %@", device.localizedName, device.mediaTypes); }Sometimes USB cameras list
AVMediaTypeMuxed(combined audio/video) instead of pureAVMediaTypeVideo, or have unexpected type strings. If you see this, you could adjust your filtering to include those types, or check if there's a way to force the device to expose a dedicated video stream.Double-check your AVFoundation setup
Make sure you've properly imported the AVFoundation framework in your code, and that you're using the correct constant forAVMediaTypeVideo(typos happen easier than you think!). Also confirm your app targets macOS 10.13 or later—Xcode 9.4 is tied to High Sierra, and older OS versions have different device handling logic.Verify camera permissions
Even if you can see the device in the full list, missing camera permissions might restrict how AVFoundation categorizes it. Check your app'sInfo.plistto ensure you've added theNSCameraUsageDescriptionkey with a clear reason for needing camera access. macOS might block full video capability access without this, even if the device shows up in the device list.Check if the camera is in use elsewhere
If another app (like FaceTime, Photo Booth, or a background process) is using the C525, AVFoundation might not mark it as an available video device. Quit all other camera-accessing apps, restart your project, and test again.Reset the camera and system connections
USB devices can get into glitchy states. Unplug the C525, wait 10 seconds, then plug it back in. A full Mac restart can also clear lingering USB driver hiccups—Logitech cameras occasionally have these on macOS.Try the newer device discovery API
The olddevicesWithMediaType:method has some limitations. GiveAVCaptureDeviceDiscoverySessiona shot instead—it's more reliable for external devices:AVCaptureDeviceDiscoverySession *session = [AVCaptureDeviceDiscoverySession discoverySessionWithDeviceTypes:@[AVCaptureDeviceTypeExternalUnknown] mediaType:AVMediaTypeVideo position:AVCaptureDevicePositionUnspecified]; NSArray *devices = session.devices;AVCaptureDeviceTypeExternalUnknownis designed to catch USB cameras like the C525 that don't fit into specific built-in categories.
内容的提问来源于stack exchange,提问作者BitHead

