<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>iOS Developers</title>
	<atom:link href="http://www.ios-developer.net/feed" rel="self" type="application/rss+xml" />
	<link>http://www.ios-developer.net</link>
	<description>iOS Developer Resources</description>
	<lastBuildDate>Wed, 25 Apr 2012 16:14:15 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Working With Files</title>
		<link>http://www.ios-developer.net/iphone-ipad-programmer/development/file-saving-and-loading/working-with-files</link>
		<comments>http://www.ios-developer.net/iphone-ipad-programmer/development/file-saving-and-loading/working-with-files#comments</comments>
		<pubDate>Fri, 23 Mar 2012 18:01:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[File Saving and Loading]]></category>

		<guid isPermaLink="false">http://www.ios-developer.net/?p=1235</guid>
		<description><![CDATA[Get File Size NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *URL = [documentsDirectory stringByAppendingPathComponent:@"SomeDirectoryName"]; URL = [URL stringByAppendingPathComponent:@"MyFileName.txt"]; NSError *AttributesError = nil; NSDictionary *FileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:URL error:&#038;AttributesError]; NSNumber *FileSizeNumber = [FileAttributes objectForKey:NSFileSize]; long FileSize = [FileSizeNumber longValue]; NSLog(@"File: %@, Size: %ld", URL, FileSize); Delete All Files In Directory [...]]]></description>
			<content:encoded><![CDATA[<h4>Get File Size</h4>
<pre><code>
	NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
	NSString *documentsDirectory = [paths objectAtIndex:0];
	NSString *URL = [documentsDirectory stringByAppendingPathComponent:@"SomeDirectoryName"];
	URL = [URL stringByAppendingPathComponent:@"MyFileName.txt"];
	NSError *AttributesError = nil;
	NSDictionary *FileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:URL error:&#038;AttributesError];
	NSNumber *FileSizeNumber = [FileAttributes objectForKey:NSFileSize];
	long FileSize = [FileSizeNumber longValue];
	NSLog(@"File: %@, Size: %ld", URL, FileSize);
</code></pre>
<p><span id="more-1235"></span></p>
<h4>Delete All Files In Directory</h4>
<pre><code>
	//DELETE ALL FILES IN DIRECTORY
	NSString *path;
	NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
	path = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"MyDirectoryName"];
	NSArray *directoryContent = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:path error:NULL];
	NSError *error = nil;
	if (error == nil)
	{
		for (NSString *Filename in directoryContent)
		{
			NSString *FilePath = [path stringByAppendingPathComponent:Filename];
			BOOL removeSuccess = [[NSFileManager defaultManager] removeItemAtPath:FilePath error:&#038;error];
			if (!removeSuccess)
			{
				// Error handling

			}
		}
	}
</code></pre>
<h4>Create Incrementing Numeric Value File</h4>
<pre><code>
	//###########################################
	//##### CREATE INCREMENTING NUMBER FILE #####
	//###########################################
	//Create array of data values
	UInt8 DataBytes[4];
	NSMutableData *FileData = [[NSMutableData alloc] init];
	UInt32 DataIndex = 0;
	for (DataIndex = 0; DataIndex &lt; (1024 * 1024 * 2); DataIndex += 4)
	{
		DataBytes[0] = (Byte)((DataIndex &#038; 0xff000000) &gt;&gt; 24);
		DataBytes[1] = (Byte)((DataIndex &#038; 0x00ff0000) &gt;&gt; 16);
		DataBytes[2] = (Byte)((DataIndex &#038; 0x0000ff00) &gt;&gt; 8);
		DataBytes[3] = (Byte)(DataIndex &#038; 0x000000ff);

		[FileData appendBytes:DataBytes length:4];
	}
	//Save to file
	NSString *DestFilename = @"test_file.txt";
	NSString *DestPath;
	NSArray *Paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
	DestPath = [[Paths objectAtIndex:0] stringByAppendingPathComponent:@"MyPathName"];
	DestPath = [DestPath stringByAppendingPathComponent:DestFilename];

	if (![[NSFileManager defaultManager] fileExistsAtPath:DestPath])
	{
		NSLog(@"Generating dummy file: %@", DestFilename);
		[[NSFileManager defaultManager] createFileAtPath:DestPath
												contents:FileData
											  attributes:nil];
	}
	[FileData release];
</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.ios-developer.net/iphone-ipad-programmer/development/file-saving-and-loading/working-with-files/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sharing Files With PC&#8217;s and MAC&#8217;s</title>
		<link>http://www.ios-developer.net/iphone-ipad-programmer/development/file-saving-and-loading/sharing-files-with-pcs-and-macs</link>
		<comments>http://www.ios-developer.net/iphone-ipad-programmer/development/file-saving-and-loading/sharing-files-with-pcs-and-macs#comments</comments>
		<pubDate>Thu, 22 Mar 2012 12:22:14 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[File Saving and Loading]]></category>

		<guid isPermaLink="false">http://www.ios-developer.net/?p=1221</guid>
		<description><![CDATA[Good resources http://mobiforge.com/developing/story/importing-exporting-documents-ios]]></description>
			<content:encoded><![CDATA[<h4>Good resources</h4>
<p><a href="http://mobiforge.com/developing/story/importing-exporting-documents-ios" target="_blank">http://mobiforge.com/developing/story/importing-exporting-documents-ios</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ios-developer.net/iphone-ipad-programmer/development/file-saving-and-loading/sharing-files-with-pcs-and-macs/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sharing Files Between Apps</title>
		<link>http://www.ios-developer.net/iphone-ipad-programmer/development/file-saving-and-loading/sharing-files-between-apps</link>
		<comments>http://www.ios-developer.net/iphone-ipad-programmer/development/file-saving-and-loading/sharing-files-between-apps#comments</comments>
		<pubDate>Thu, 22 Mar 2012 12:21:38 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[File Saving and Loading]]></category>

		<guid isPermaLink="false">http://www.ios-developer.net/?p=1218</guid>
		<description><![CDATA[Good resources http://mobiforge.com/developing/story/importing-exporting-documents-ios]]></description>
			<content:encoded><![CDATA[<h4>Good resources</h4>
<p><a href="http://mobiforge.com/developing/story/importing-exporting-documents-ios" target="_blank">http://mobiforge.com/developing/story/importing-exporting-documents-ios</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ios-developer.net/iphone-ipad-programmer/development/file-saving-and-loading/sharing-files-between-apps/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Progress Bar General</title>
		<link>http://www.ios-developer.net/iphone-ipad-programmer/development/progress-bar/progress-bar-general</link>
		<comments>http://www.ios-developer.net/iphone-ipad-programmer/development/progress-bar/progress-bar-general#comments</comments>
		<pubDate>Wed, 21 Mar 2012 16:07:02 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Progress Bar]]></category>

		<guid isPermaLink="false">http://www.ios-developer.net/?p=1214</guid>
		<description><![CDATA[Add Progress View Object Declare in the .h IBOutlet UIProgressView *MyProgressBar; In #ViewController.m //If view could be unloaded //********** VIEW DID UNLOAD ********** - (void)viewDidUnload { [super viewDidUnload]; [MyProgressBar release]; MyProgressBar = nil; } //********** DEALLOC ********** - (void)dealloc { [MyProgressBar release]; [super dealloc]; } Updating Progress Bar MyProgressBar.progress = 0.0; //Floating-point value between 0.0 [...]]]></description>
			<content:encoded><![CDATA[<h4>Add Progress View Object</h4>
<h5>Declare in the .h</h5>
<pre><code>
	IBOutlet UIProgressView *MyProgressBar;
</code></pre>
<p><span id="more-1214"></span></p>
<h5>In #ViewController.m</h5>
<pre><code>
//If view could be unloaded
//********** VIEW DID UNLOAD **********
- (void)viewDidUnload
{
	[super viewDidUnload];

	[MyProgressBar release];
	MyProgressBar = nil;
}

//********** DEALLOC **********
- (void)dealloc
{
	[MyProgressBar release];

	[super dealloc];
}
</code>
<h4>Updating Progress Bar</h4>
<pre><code>
	MyProgressBar.progress = 0.0;		//Floating-point value between 0.0 and 1.0
</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.ios-developer.net/iphone-ipad-programmer/development/progress-bar/progress-bar-general/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Record Video With AVCaptureSession</title>
		<link>http://www.ios-developer.net/iphone-ipad-programmer/development/camera/record-video-with-avcapturesession-2</link>
		<comments>http://www.ios-developer.net/iphone-ipad-programmer/development/camera/record-video-with-avcapturesession-2#comments</comments>
		<pubDate>Tue, 20 Mar 2012 18:09:17 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Camera]]></category>

		<guid isPermaLink="false">http://www.ios-developer.net/?p=1196</guid>
		<description><![CDATA[Apple Resources: Media Capture The following are typically required AVCaptureDevice &#8211; represents the input device (camera or microphone) AVCaptureInput &#8211; (a concrete subclass of) to configure the ports from the input device (has one or more input ports which are instances of AVCaptureInputPort) AVCaptureOutput &#8211; (a concrete subclass of) to manage the output to a [...]]]></description>
			<content:encoded><![CDATA[<p>Apple Resources:<br />
<a href="http://developer.apple.com/library/ios/#DOCUMENTATION/AudioVideo/Conceptual/AVFoundationPG/Articles/04_MediaCapture.html" target="_blank">Media Capture</a></p>
<p><span id="more-1196"></span></p>
<h5>The following are typically required</h5>
<p>AVCaptureDevice &#8211; represents the input device (camera or microphone)<br />
AVCaptureInput &#8211; (a concrete subclass of) to configure the ports from the input device (has one or more input ports which are instances of AVCaptureInputPort)<br />
AVCaptureOutput &#8211; (a concrete subclass of) to manage the output to a movie file or still image (accepts data from one or more sources, e.g. an AVCaptureMovieFileOutput object accepts both video and audio data)<br />
AVCaptureSession &#8211; coordinates the data flow from the input to the output<br />
AVCaptureVideoPreviewLayer &#8211; shows the user what a camera is recording<br />
AVCaptureConnection &#8211; connection between a capture input and a capture output in a capture session.  Can be used to enable or disable the flow of data from a given input or to a given output. Also to monitor the average and peak power levels in audio channels.</p>
<h5>Notifications</h5>
<p>A capture session posts notifications that you can observe to be notified, for example, when it starts or stops running, or when it is interrupted. You can also register to receive an AVCaptureSessionRuntimeErrorNotification if a runtime error occurs. You can also interrogate the session’s running property to find out if it is running, and its interrupted property to find out if it is interrupted.</p>
<h4>A Working Implementation</h4>
<p>Its surprisingly hard to find good working examples of recording video with AVCaptureSession.  This is the results of us coming up with a nice and simple implementation which works and can be expanded on as required.  All the basics are there to add clever things to get at the the audio and video data if desired.<br />
This example may be used with a standard ViewController class with .xib.<br />
It shows a preview of the camera in landscape orientation.  Two buttons can be added to your xib for start/stop recording and toggle camera.</p>
<h5>In your ViewController.h</h5>
<pre><code>
#import &lt;UIKit/UIKit.h&gt;

#import &lt;Foundation/Foundation.h&gt;
#import &lt;CoreMedia/CoreMedia.h&gt;
#import &lt;AVFoundation/AVFoundation.h&gt;

#import &lt;AssetsLibrary/AssetsLibrary.h&gt;		//&lt;&lt;Can delete if not storing videos to the photo library.  Delete the assetslibrary framework too requires this)

#define CAPTURE_FRAMES_PER_SECOND		20

@interface MyViewController_iPhone : UIViewController
					&lt;AVCaptureFileOutputRecordingDelegate&gt;
{
	BOOL WeAreRecording;

	AVCaptureSession *CaptureSession;
	AVCaptureMovieFileOutput *MovieFileOutput;
	AVCaptureDeviceInput *VideoInputDevice;
}

@property (retain) AVCaptureVideoPreviewLayer *PreviewLayer;

- (void) CameraSetOutputProperties;
- (AVCaptureDevice *) CameraWithPosition:(AVCaptureDevicePosition) Position;
- (IBAction)StartStopButtonPressed:(id)sender;
- (IBAction)CameraToggleButtonPressed:(id)sender;

@end
</code></pre>
<h5>In your ViewController.m</h5>
<pre><code>
#import "MyViewController_iPhone.h"

@implementation MyViewController_iPhone

@synthesize PreviewLayer;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

//********** VIEW DID LOAD **********
- (void)viewDidLoad
{
    [super viewDidLoad];

	//---------------------------------
	//----- SETUP CAPTURE SESSION -----
	//---------------------------------
	NSLog(@"Setting up capture session");
	CaptureSession = [[AVCaptureSession alloc] init];

	//----- ADD INPUTS -----
	NSLog(@"Adding video input");

	//ADD VIDEO INPUT
	AVCaptureDevice *VideoDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
	if (VideoDevice)
	{
		NSError *error;
		VideoInputDevice = [AVCaptureDeviceInput deviceInputWithDevice:VideoDevice error:&#038;error];
		if (!error)
		{
			if ([CaptureSession canAddInput:VideoInputDevice])
				[CaptureSession addInput:VideoInputDevice];
			else
				NSLog(@"Couldn't add video input");
		}
		else
		{
			NSLog(@"Couldn't create video input");
		}
	}
	else
	{
		NSLog(@"Couldn't create video capture device");
	}

	//ADD AUDIO INPUT
	NSLog(@"Adding audio input");
	AVCaptureDevice *audioCaptureDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeAudio];
	NSError *error = nil;
	AVCaptureDeviceInput *audioInput = [AVCaptureDeviceInput deviceInputWithDevice:audioCaptureDevice error:&#038;error];
	if (audioInput)
	{
		[CaptureSession addInput:audioInput];
	}

	//----- ADD OUTPUTS -----

	//ADD VIDEO PREVIEW LAYER
	NSLog(@"Adding video preview layer");
	[self setPreviewLayer:[[[AVCaptureVideoPreviewLayer alloc] initWithSession:CaptureSession] autorelease]];

	PreviewLayer.orientation = AVCaptureVideoOrientationLandscapeRight;		//&lt;&lt;SET ORIENTATION.  You can deliberatly set this wrong to flip the image and may actually need to set it wrong to get the right image

	[[self PreviewLayer] setVideoGravity:AVLayerVideoGravityResizeAspectFill];

	//ADD MOVIE FILE OUTPUT
	NSLog(@"Adding movie file output");
	MovieFileOutput = [[AVCaptureMovieFileOutput alloc] init];

	Float64 TotalSeconds = 60;			//Total seconds
	int32_t preferredTimeScale = 30;	//Frames per second
	CMTime maxDuration = CMTimeMakeWithSeconds(TotalSeconds, preferredTimeScale);	//&lt;&lt;SET MAX DURATION
	MovieFileOutput.maxRecordedDuration = maxDuration;

	MovieFileOutput.minFreeDiskSpaceLimit = 1024 * 1024;						//&lt;&lt;SET MIN FREE SPACE IN BYTES FOR RECORDING TO CONTINUE ON A VOLUME

	if ([CaptureSession canAddOutput:MovieFileOutput])
		[CaptureSession addOutput:MovieFileOutput];

	//SET THE CONNECTION PROPERTIES (output properties)
	[self CameraSetOutputProperties];			//(We call a method as it also has to be done after changing camera)

	//----- SET THE IMAGE QUALITY / RESOLUTION -----
	//Options:
	//	AVCaptureSessionPresetHigh - Highest recording quality (varies per device)
	//	AVCaptureSessionPresetMedium - Suitable for WiFi sharing (actual values may change)
	//	AVCaptureSessionPresetLow - Suitable for 3G sharing (actual values may change)
	//	AVCaptureSessionPreset640x480 - 640x480 VGA (check its supported before setting it)
	//	AVCaptureSessionPreset1280x720 - 1280x720 720p HD (check its supported before setting it)
	//	AVCaptureSessionPresetPhoto - Full photo resolution (not supported for video output)
	NSLog(@"Setting image quality");
	[CaptureSession setSessionPreset:AVCaptureSessionPresetMedium];
	if ([CaptureSession canSetSessionPreset:AVCaptureSessionPreset640x480])		//Check size based configs are supported before setting them
		[CaptureSession setSessionPreset:AVCaptureSessionPreset640x480];

	//----- DISPLAY THE PREVIEW LAYER -----
	//Display it full screen under out view controller existing controls
	NSLog(@"Display the preview layer");
	CGRect layerRect = [[[self view] layer] bounds];
	[PreviewLayer setBounds:layerRect];
	[PreviewLayer setPosition:CGPointMake(CGRectGetMidX(layerRect),
																  CGRectGetMidY(layerRect))];
	//[[[self view] layer] addSublayer:[[self CaptureManager] previewLayer]];
	//We use this instead so it goes on a layer behind our UI controls (avoids us having to manually bring each control to the front):
	UIView *CameraView = [[[UIView alloc] init] autorelease];
	[[self view] addSubview:CameraView];
	[self.view sendSubviewToBack:CameraView];

	[[CameraView layer] addSublayer:PreviewLayer];

	//----- START THE CAPTURE SESSION RUNNING -----
	[CaptureSession startRunning];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIDeviceOrientationLandscapeLeft);
}

//********** VIEW WILL APPEAR **********
//View about to be added to the window (called each time it appears)
//Occurs after other view's viewWillDisappear
- (void)viewWillAppear:(BOOL)animated
{
	[super viewWillAppear:animated];

	WeAreRecording = NO;
}

//********** CAMERA SET OUTPUT PROPERTIES **********
- (void) CameraSetOutputProperties
{
	//SET THE CONNECTION PROPERTIES (output properties)
	AVCaptureConnection *CaptureConnection = [MovieFileOutput connectionWithMediaType:AVMediaTypeVideo];

	//Set landscape (if required)
	if ([CaptureConnection isVideoOrientationSupported])
	{
		AVCaptureVideoOrientation orientation = AVCaptureVideoOrientationLandscapeRight;		//&lt;&lt;&lt;&lt;&lt;SET VIDEO ORIENTATION IF LANDSCAPE
		[CaptureConnection setVideoOrientation:orientation];
	}

	//Set frame rate (if requried)
	CMTimeShow(CaptureConnection.videoMinFrameDuration);
	CMTimeShow(CaptureConnection.videoMaxFrameDuration);

	if (CaptureConnection.supportsVideoMinFrameDuration)
		CaptureConnection.videoMinFrameDuration = CMTimeMake(1, CAPTURE_FRAMES_PER_SECOND);
	if (CaptureConnection.supportsVideoMaxFrameDuration)
		CaptureConnection.videoMaxFrameDuration = CMTimeMake(1, CAPTURE_FRAMES_PER_SECOND);

	CMTimeShow(CaptureConnection.videoMinFrameDuration);
	CMTimeShow(CaptureConnection.videoMaxFrameDuration);
}

//********** GET CAMERA IN SPECIFIED POSITION IF IT EXISTS **********
- (AVCaptureDevice *) CameraWithPosition:(AVCaptureDevicePosition) Position
{
	NSArray *Devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
	for (AVCaptureDevice *Device in Devices)
	{
		if ([Device position] == Position)
		{
			return Device;
		}
	}
	return nil;
}

//********** CAMERA TOGGLE **********
- (IBAction)CameraToggleButtonPressed:(id)sender
{
	if ([[AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo] count] &gt; 1)		//Only do if device has multiple cameras
	{
		NSLog(@"Toggle camera");
		NSError *error;
		//AVCaptureDeviceInput *videoInput = [self videoInput];
		AVCaptureDeviceInput *NewVideoInput;
		AVCaptureDevicePosition position = [[VideoInputDevice device] position];
		if (position == AVCaptureDevicePositionBack)
		{
			NewVideoInput = [[AVCaptureDeviceInput alloc] initWithDevice:[self CameraWithPosition:AVCaptureDevicePositionFront] error:&#038;error];
		}
		else if (position == AVCaptureDevicePositionFront)
		{
			NewVideoInput = [[AVCaptureDeviceInput alloc] initWithDevice:[self CameraWithPosition:AVCaptureDevicePositionBack] error:&#038;error];
		}

		if (NewVideoInput != nil)
		{
			[CaptureSession beginConfiguration];		//We can now change the inputs and output configuration.  Use commitConfiguration to end
			[CaptureSession removeInput:VideoInputDevice];
			if ([CaptureSession canAddInput:NewVideoInput])
			{
				[CaptureSession addInput:NewVideoInput];
				VideoInputDevice = NewVideoInput;
			}
			else
			{
				[CaptureSession addInput:VideoInputDevice];
			}

			//Set the connection properties again
			[self CameraSetOutputProperties];

			[CaptureSession commitConfiguration];
			[NewVideoInput release];
		}
	}
}

//********** START STOP RECORDING BUTTON **********
- (IBAction)StartStopButtonPressed:(id)sender
{

	if (!WeAreRecording)
	{
		//----- START RECORDING -----
		NSLog(@"START RECORDING");
		WeAreRecording = YES;

		//Create temporary URL to record to
		NSString *outputPath = [[NSString alloc] initWithFormat:@"%@%@", NSTemporaryDirectory(), @"output.mov"];
		NSURL *outputURL = [[NSURL alloc] initFileURLWithPath:outputPath];
		NSFileManager *fileManager = [NSFileManager defaultManager];
		if ([fileManager fileExistsAtPath:outputPath])
		{
			NSError *error;
			if ([fileManager removeItemAtPath:outputPath error:&#038;error] == NO)
			{
				//Error - handle if requried
			}
		}
		[outputPath release];
		//Start recording
		[MovieFileOutput startRecordingToOutputFileURL:outputURL recordingDelegate:self];
		[outputURL release];
	}
	else
	{
		//----- STOP RECORDING -----
		NSLog(@"STOP RECORDING");
		WeAreRecording = NO;

		[MovieFileOutput stopRecording];
	}
}

//********** DID FINISH RECORDING TO OUTPUT FILE AT URL **********
- (void)captureOutput:(AVCaptureFileOutput *)captureOutput
didFinishRecordingToOutputFileAtURL:(NSURL *)outputFileURL
	  fromConnections:(NSArray *)connections
				error:(NSError *)error
{

	NSLog(@"didFinishRecordingToOutputFileAtURL - enter");

    BOOL RecordedSuccessfully = YES;
    if ([error code] != noErr)
	{
        // A problem occurred: Find out if the recording was successful.
        id value = [[error userInfo] objectForKey:AVErrorRecordingSuccessfullyFinishedKey];
        if (value)
		{
            RecordedSuccessfully = [value boolValue];
        }
    }
	if (RecordedSuccessfully)
	{
		//----- RECORDED SUCESSFULLY -----
			NSLog(@"didFinishRecordingToOutputFileAtURL - success");
		ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
		if ([library videoAtPathIsCompatibleWithSavedPhotosAlbum:outputFileURL])
		{
			[library writeVideoAtPathToSavedPhotosAlbum:outputFileURL
										completionBlock:^(NSURL *assetURL, NSError *error)
			{
				if (error)
				{

				}
			}];
		}

		[library release];		

	}
}

//********** VIEW DID UNLOAD **********
- (void)viewDidUnload
{
	[super viewDidUnload];

	[CaptureSession release];
	CaptureSession = nil;
	[MovieFileOutput release];
	MovieFileOutput = nil;
	[VideoInputDevice release];
	VideoInputDevice = nil;
}

//********** DEALLOC **********
- (void)dealloc
{
	[CaptureSession release];
	[MovieFileOutput release];
	[VideoInputDevice release];

	[super dealloc];
}

@end
</code></pre>
<h4>Storing Directly To Your Documents Directory</h4>
<p>(i.e. instead of moving file to photo library after recording completes)</p>
<pre><code>
	NSString *DestFilename = @ "output.mov";

	//Set the file save to URL
	NSLog(@"Starting recording to file: %@", DestFilename);
	NSString *DestPath;
	NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
	DestPath = [[paths objectAtIndex:0] stringByAppendingPathComponent:RECORD_TO_ADD_DIRECTORY];
	DestPath = [DestPath stringByAppendingPathComponent:DestFilename];

	NSURL* saveLocationURL = [[NSURL alloc] initFileURLWithPath:DestPath];
	[MovieFileOutput startRecordingToOutputFileURL:saveLocationURL recordingDelegate:self];
	[saveLocationURL release];
</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.ios-developer.net/iphone-ipad-programmer/development/camera/record-video-with-avcapturesession-2/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Camera Properties</title>
		<link>http://www.ios-developer.net/iphone-ipad-programmer/development/camera/camera-properties</link>
		<comments>http://www.ios-developer.net/iphone-ipad-programmer/development/camera/camera-properties#comments</comments>
		<pubDate>Tue, 20 Mar 2012 15:20:02 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Camera]]></category>

		<guid isPermaLink="false">http://www.ios-developer.net/?p=1189</guid>
		<description><![CDATA[Selecting Camera //********** GET CAMERA IN SPECIFIED POSITION IF IT EXISTS ********** - (AVCaptureDevice *) CameraWithPosition:(AVCaptureDevicePosition) Position { NSArray *Devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo]; for (AVCaptureDevice *Device in Devices) { if ([Device position] == Position) { return Device; } } return nil; } //Then to use a specific camera: [self CameraWithPosition:AVCaptureDevicePositionFront] [self CameraWithPosition:AVCaptureDevicePositionBack] Does Device Have [...]]]></description>
			<content:encoded><![CDATA[<h4>Selecting Camera</h4>
<pre><code>
//********** GET CAMERA IN SPECIFIED POSITION IF IT EXISTS **********
- (AVCaptureDevice *) CameraWithPosition:(AVCaptureDevicePosition) Position
{
	NSArray *Devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
	for (AVCaptureDevice *Device in Devices)
	{
		if ([Device position] == Position)
		{
			return Device;
		}
	}
	return nil;
}
//Then to use a specific camera:
	[self CameraWithPosition:AVCaptureDevicePositionFront]

<span id="more-1189"></span>

	[self CameraWithPosition:AVCaptureDevicePositionBack]
</code></pre>
<h4>Does Device Have Multiple Cameras?</h4>
<pre><code>
	if ([[AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo] count] &gt; 1)
</code></pre>
<h4>Which Camera Is Selected</h4>
<pre><code>
		AVCaptureDevicePosition position = [[VideoInputDevice device] position];
		if (position == AVCaptureDevicePositionBack)
		{

		}
		else if (position == AVCaptureDevicePositionFront)
		{

		}
</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.ios-developer.net/iphone-ipad-programmer/development/camera/camera-properties/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Z order</title>
		<link>http://www.ios-developer.net/iphone-ipad-programmer/development/window-uiviewcontroller-etc/z-order</link>
		<comments>http://www.ios-developer.net/iphone-ipad-programmer/development/window-uiviewcontroller-etc/z-order#comments</comments>
		<pubDate>Mon, 19 Mar 2012 16:06:38 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Window, UIViewController etc]]></category>

		<guid isPermaLink="false">http://www.ios-developer.net/?p=1177</guid>
		<description><![CDATA[Bringing Objects To Front And Sending To Back Remember that UI objects such as buttons etc are all actually subviews [self.view bringSubviewToFront:MyButton]; [self.view sendSubviewToBack:MyButton]; Layers MyView.layer.zPosition = 1; //1 = front]]></description>
			<content:encoded><![CDATA[<h4>Bringing Objects To Front And Sending To Back</h4>
<p>Remember that UI objects such as buttons etc are all actually subviews<br />
<span id="more-1177"></span></p>
<pre><code>
	[self.view bringSubviewToFront:MyButton];

	[self.view sendSubviewToBack:MyButton];
</code></pre>
<h4>Layers</h4>
<pre><code>
	MyView.layer.zPosition = 1;	//1 = front
</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.ios-developer.net/iphone-ipad-programmer/development/window-uiviewcontroller-etc/z-order/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Camera As A Subview</title>
		<link>http://www.ios-developer.net/iphone-ipad-programmer/development/camera/camera-as-a-subview</link>
		<comments>http://www.ios-developer.net/iphone-ipad-programmer/development/camera/camera-as-a-subview#comments</comments>
		<pubDate>Mon, 19 Mar 2012 13:42:26 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Camera]]></category>

		<guid isPermaLink="false">http://www.ios-developer.net/?p=1163</guid>
		<description><![CDATA[Good Resources http://stackoverflow.com/questions/5915943/use-camera-as-subview]]></description>
			<content:encoded><![CDATA[<h4>Good Resources</h4>
<p><a href="http://stackoverflow.com/questions/5915943/use-camera-as-subview" target="_blank">http://stackoverflow.com/questions/5915943/use-camera-as-subview</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ios-developer.net/iphone-ipad-programmer/development/camera/camera-as-a-subview/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Camera Preview On A View Controller</title>
		<link>http://www.ios-developer.net/iphone-ipad-programmer/development/camera/camera-preview-on-a-view-controller</link>
		<comments>http://www.ios-developer.net/iphone-ipad-programmer/development/camera/camera-preview-on-a-view-controller#comments</comments>
		<pubDate>Fri, 16 Mar 2012 16:45:08 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Camera]]></category>

		<guid isPermaLink="false">http://www.ios-developer.net/?p=1152</guid>
		<description><![CDATA[This is based on the superb example here: http://red-glasses.com/index.php/tutorials/ios4-take-photos-with-live-video-preview-using-avfoundation/ Adding Live Preview NOTE &#8211; this works for portrait. There seems to currently be an issue making this work with Landscape due to the apple API lacking the required orientation setting Define in the .h file @interface MyViewController : UIViewController { IBOutlet UIView *vImagePreview; //&#60;&#60;&#60;&#60;&#60;ADD THIS [...]]]></description>
			<content:encoded><![CDATA[<p>This is based on the superb example here:<br />
<a href="http://red-glasses.com/index.php/tutorials/ios4-take-photos-with-live-video-preview-using-avfoundation/" target="_blank">http://red-glasses.com/index.php/tutorials/ios4-take-photos-with-live-video-preview-using-avfoundation/</a></p>
<p><span id="more-1152"></span></p>
<h4>Adding Live Preview</h4>
<p>NOTE &#8211; this works for portrait.  There seems to currently be an issue making this work with Landscape due to the apple API lacking the required orientation setting</p>
<h5>Define in the .h file</h5>
<pre><code>
@interface MyViewController : UIViewController
{
	IBOutlet UIView *vImagePreview;             //&lt;&lt;&lt;&lt;&lt;ADD THIS
}
@property(nonatomic, retain) IBOutlet UIView *vImagePreview;             //&lt;&lt;&lt;&lt;&lt;ADD THIS
</code></pre>
<h5>Define in the .m file</h5>
<pre><code>
@implementation MyViewController

@synthesize vImagePreview;             //&lt;&lt;&lt;&lt;&lt;ADD THIS

//********** VIEW DID UNLOAD **********
- (void)viewDidUnload
{
	[super viewDidUnload];

	[vImagePreview release];
	vImagePreview = nil;
}

//********** DEALLOC **********
- (void)dealloc
{
	[vImagePreview release];

	[super dealloc];
}
</code></pre>
<h5>In your Interface Builder .xib file</h5>
<p>Add a UIView and link vImagePreview to it.</p>
<h5>Create The Live Preview</h5>
<pre><code>
//*************************************
//*************************************
//********** VIEW DID APPEAR **********
//*************************************
//*************************************
//View about to be added to the window (called each time it appears)
//Occurs after other view's viewWillDisappear
- (void)viewDidAppear:(BOOL)animated
{
	[super viewDidAppear:animated];

	//----- SHOW LIVE CAMERA PREVIEW -----
	AVCaptureSession *session = [[AVCaptureSession alloc] init];
	session.sessionPreset = AVCaptureSessionPresetMedium;

	CALayer *viewLayer = self.vImagePreview.layer;
	NSLog(@"viewLayer = %@", viewLayer);

	AVCaptureVideoPreviewLayer *captureVideoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:session];

	captureVideoPreviewLayer.frame = self.vImagePreview.bounds;
	[self.vImagePreview.layer addSublayer:captureVideoPreviewLayer];

	AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];

	NSError *error = nil;
	AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device error:&#038;error];
	if (!input) {
		// Handle the error appropriately.
		NSLog(@"ERROR: trying to open camera: %@", error);
	}
	[session addInput:input];

	[session startRunning];
}
</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.ios-developer.net/iphone-ipad-programmer/development/camera/camera-preview-on-a-view-controller/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Overlaying Controls On Camera View</title>
		<link>http://www.ios-developer.net/iphone-ipad-programmer/development/camera/overlaying-controls-on-camera-view</link>
		<comments>http://www.ios-developer.net/iphone-ipad-programmer/development/camera/overlaying-controls-on-camera-view#comments</comments>
		<pubDate>Fri, 16 Mar 2012 16:07:37 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Camera]]></category>

		<guid isPermaLink="false">http://www.ios-developer.net/?p=1150</guid>
		<description><![CDATA[Good resources http://www.musicalgeometry.com/?p=1273]]></description>
			<content:encoded><![CDATA[<h4>Good resources</h4>
<p><a href="http://www.musicalgeometry.com/?p=1273" target="_blank">http://www.musicalgeometry.com/?p=1273</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ios-developer.net/iphone-ipad-programmer/development/camera/overlaying-controls-on-camera-view/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

