2009-03-09 20 views
0

aşağıdaki bir QTCaptureSession iki girişi koymaya çalışıyorum:QTKit, giriş cihazlarını mı açıyorsunuz?

[QTCaptureDeviceInput initWithDevice:]- cannot intialize device input with device that is not open.

Ben ettik:

mainSession = [[QTCaptureSession alloc] init]; 

BOOL success; 
NSError* error; 

QTCaptureDevice *videoDevice = [QTCaptureDevice defaultInputDeviceWithMediaType:@"QTMediaTypeVideo"]; 
success = [videoDevice open:&error]; 

QTCaptureDevice *audioDevice = [QTCaptureDevice defaultInputDeviceWithMediaType:@"QTMediaTypeSound"]; 
success = [audioDevice open:&error]; 

//video = [[QTCaptureDeviceInput alloc] initWithDevice:videoDevice]; 
//success = [mainSession addInput:video error:&error]; 

//audio = [[QTCaptureDeviceInput alloc] initWithDevice:audioDevice]; 
//success = [mainSession addInput:audio error:&error]; 

output = [[QTCaptureMovieFileOutput alloc] init]; 
success = [mainSession addOutput:output error:&error]; 

[output setDelegate:self]; 

[movieView setCaptureSession:mainSession]; 

[mainWindow makeKeyAndOrderFront:NSApp]; 

[mainSession startRunning]; 

dışarı yorumladı bölüm hata kaynakları olduğunu tespit ettik Açık yöntemlerden sonra benim "başarı" değişkeni araştırdı ve evet. Öyleyse yöntem neden cihazın açık olmadığını düşünüyor?

+0

Zaten bu sormadı? http://stackoverflow.com/questions/622567/cocoa-qtkit-and-recording-movies –

+0

Bunu düşünmüştüm, ve 'tam olarak' bu soruyu sormadığımdan, muhtemelen daha fazla cevap alacağımı düşündüm. Bir önceki soruya detay eklemekten ziyade yeni bir soru, önceki sorum ise sadece genel geri bildirim istiyordu. – cemulate

cevap

1

Henüz bir yanıt bulamadıysanız, sorununun aslında belirttiğiniz ikinin üzerindeki satırlarda olduğunu düşünüyorum. Apple'ın belgelerini kontrol ettim ve QTMediaTypeSound ve QTMediaTypeVideo'nun sabit olduğunu, elle girmeniz gereken dizeleri değil sabit olduğunu öğrendim. Hızlı bir NSLog() ifadesi, örneğin, QTMediaTypeVideo sabitinin aslında "vide" değerine eşit olduğunu gösterir. Kısacası

, kodunuz olmalıdır:

mainSession = [[QTCaptureSession alloc] init]; 

BOOL success; 
NSError* error; 

QTCaptureDevice *videoDevice = [QTCaptureDevice defaultInputDeviceWithMediaType:QTMediaTypeVideo]; 
success = [videoDevice open:&error]; 

QTCaptureDevice *audioDevice = [QTCaptureDevice defaultInputDeviceWithMediaType:QTMediaTypeSound]; 
success = [audioDevice open:&error]; 

video = [[QTCaptureDeviceInput alloc] initWithDevice:videoDevice]; 
success = [mainSession addInput:video error:&error]; 

audio = [[QTCaptureDeviceInput alloc] initWithDevice:audioDevice]; 
success = [mainSession addInput:audio error:&error]; 

output = [[QTCaptureMovieFileOutput alloc] init]; 
success = [mainSession addOutput:output error:&error]; 

[output setDelegate:self]; 

[movieView setCaptureSession:mainSession]; 

[mainWindow makeKeyAndOrderFront:NSApp]; 

[mainSession startRunning];