バーコードスキャナーを実装したいiOS用のネイティブ拡張機能を構築しています。
AVCamの例に従って、ネイティブ アプリケーション (完全な xcode) で試してみましたが、問題なく動作します。
今、私は Flex モバイル プロジェクトからこのコードを使用したいと考えています。ANE を作成して Flex Mobile プロジェクトに配置することができ、ANE の関数を呼び出すことができます。
問題ないように見えますが、私の問題は、カメラを通して見ているものが見えないことです。つまり、カメラを起動してキャプチャを開始するために呼び出すメソッドがあります。私はまた、captureOutput デリゲートを実装しました。最も奇妙なことは、アプリを実行すると、アプリケーションがデータをキャプチャしているように initcapture と captureOutput 内のログを確認できることですが、iPad ではカメラ。
これは私が使用するコードの一部です:
- (void)initCapture
{
NSLog(@"camera view capture init");
/*We setup the input*/
self.device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
AVCaptureDeviceInput *captureInput = [AVCaptureDeviceInput deviceInputWithDevice:self.device error:nil];
/*We setupt the output*/
captureOutput = [[AVCaptureVideoDataOutput alloc] init];
// If the queue is blocked when new frames are captured, those frames will be automatically dropped
captureOutput.alwaysDiscardsLateVideoFrames = YES;
//captureOutput.minFrameDuration = CMTimeMake(1, 10); Uncomment it to specify a minimum duration for each video frame
[captureOutput setSampleBufferDelegate:self queue:dispatch_get_main_queue()];
// Set the video output to store frame in BGRA (It is supposed to be faster)
NSString* key = (NSString*)kCVPixelBufferPixelFormatTypeKey;
// Set the video output to store frame in 422YpCbCr8(It is supposed to be faster)
//************************Note this line
NSNumber* value = [NSNumber numberWithUnsignedInt:kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange];
NSDictionary* videoSettings = [NSDictionary dictionaryWithObject:value forKey:key];
[captureOutput setVideoSettings:videoSettings];
//And we create a capture session
self.captureSession = [[AVCaptureSession alloc] init];
//We add input and output
[self.captureSession addInput:captureInput];
[self.captureSession addOutput:captureOutput];
if ([self.captureSession canSetSessionPreset:AVCaptureSessionPreset1280x720])
{
NSLog(@"camera view Set preview port to 1280X720");
self.captureSession.sessionPreset = AVCaptureSessionPreset1280x720;
} else
//set to 640x480 if 1280x720 not supported on device
if ([self.captureSession canSetSessionPreset:AVCaptureSessionPreset640x480])
{
NSLog(@"camera view Set preview port to 640X480");
self.captureSession.sessionPreset = AVCaptureSessionPreset640x480;
}
/*We add the preview layer*/
self.prevLayer = [AVCaptureVideoPreviewLayer layerWithSession: self.captureSession];
if ([self.prevLayer respondsToSelector:@selector(connection)])
self.prevLayer.connection.videoOrientation = AVCaptureVideoOrientationLandscapeLeft;
else
self.prevLayer.orientation = AVCaptureVideoOrientationLandscapeLeft;
self.prevLayer.frame = CGRectMake(150, 0, 700, 700);
self.prevLayer.videoGravity = AVLayerVideoGravityResizeAspect;
[self.view.layer addSublayer: self.prevLayer];
}
- (void) startScanning {
NSLog(@"camera view start scanning");
self.state = LAUNCHING_CAMERA;
[self.captureSession startRunning];
self.prevLayer.hidden = NO;
self.state = CAMERA;
}
#pragma mark AVCaptureSession delegate
- (void)captureOutput:(AVCaptureOutput *)captureOutput
didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
fromConnection:(AVCaptureConnection *)connection
{
NSLog(@"camera view Capture output");
}
これをどのように解決すればよいですか?
どうもありがとうございました。