Hi,
I recently came across some code for creating a simple built in iSight app which displays a view using the iSight camera on the macbook. I thought I would play around and see if I could add features to the basic app to make it more interesting.
The code was all in the -awakeFromNib method. I have created a button and changed the method to -viewButton which is called when the user presses the button (the session then starts).
I would like to add a stop button but am slightly confused with the code required for my -stopButton method.
The QTkit is used (<QTkit/QTkit.h>)
The code I have is here:
iSight.h
iSight.m
I have commented out the code under the stopButton Method as it doesn't work (I kind of expected that but don't know how to approach it).
The idea is to stop the current session when the stop button is clicked.
I can't remember where the original code was from but it was a good example.
I recently came across some code for creating a simple built in iSight app which displays a view using the iSight camera on the macbook. I thought I would play around and see if I could add features to the basic app to make it more interesting.
The code was all in the -awakeFromNib method. I have created a button and changed the method to -viewButton which is called when the user presses the button (the session then starts).
I would like to add a stop button but am slightly confused with the code required for my -stopButton method.
The QTkit is used (<QTkit/QTkit.h>)
The code I have is here:
iSight.h
Code:
#import <Cocoa/Cocoa.h>
#import <QTKit/QTKit.h>
@interface iSight : NSObject {
IBOutlet QTCaptureView *outputView;
}
-(IBAction)viewButton:(id)sender;
-(IBAction)stopButton:(id)sender;
@end
iSight.m
Code:
#import "iSight.h"
@implementation iSight
-(IBAction)viewButton:(id)sender
{
//Create the QT capture session
QTCaptureSession *session = [[QTCaptureSession alloc] init];
/* Select the default Video input device */
QTCaptureDevice *iSight = [QTCaptureDevice defaultInputDeviceWithMediaType:QTMediaTypeVideo];
/* Passing nil for the NSError parameter may not be the best idea
but i will leave error handling up to you */
[iSight open:nil];
/* Create a QTKit input for the session using the iSight Device */
QTCaptureDeviceInput *myInput = [QTCaptureDeviceInput deviceInputWithDevice:iSight];
/* Create a capture session for the live vidwo and add inputs get the ball rolling etc */
[session addInput:myInput error:nil];
[outputView setCaptureSession:session];
/* Let the video madness begin */
[session startRunning];
}
-(IBAction)stopButton:(id)sender
{
//[session stopRunning]; error
}
@end
I have commented out the code under the stopButton Method as it doesn't work (I kind of expected that but don't know how to approach it).
The idea is to stop the current session when the stop button is clicked.
I can't remember where the original code was from but it was a good example.