我是在使用qtplayer之类的avfoundation录制iPhone屏幕的osx(mac(应用程序。
但是,当我的手机屏幕导向更改时,我不konw如何获取通知。我尝试从代表那里寻求解决方案,通知,但一无所获。我无法获得iPhone屏幕大小。
我使用了avcaptureInput avcapturesession avcapturedevice等。
我该怎么办?
已解决。您需要添加一个称为 avCaptureInputportformatDescriptionDidDidchangenotification 的通知,如:
NSNotificationCenter *notiCenter = [NSNotificationCenter defaultCenter];
id inputPortFormatDescriptionOberserver = [notiCenter addObserverForName:AVCaptureInputPortFormatDescriptionDidChangeNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification * _Nonnull note) {
didGetVideoDimensions = YES;
[wself.screenRecorderDelegate captureInputPortDidChanged];
NSLog(@"AVCaptureInputPortFormatDescriptionDidChangeNotification");
}];
您可以得到这样的屏幕大小:
- (CGSize)optedDeviceSize{
CGSize size = CGSizeZero;
AVCaptureInputPort *port = self.videoDeviceInput.ports.firstObject;
if (port) {
CMVideoDimensions videoDimensions = CMVideoFormatDescriptionGetDimensions(port.formatDescription);
size = CGSizeMake(videoDimensions.width, videoDimensions.height);
}
return size;
}