How To: iPhone SDK – Play and Record Audio concurrently

Unfortunately, it’s quite a fiddly process to record audio and play it back at the same time on the iPhone.  By default, the sound output is very quiet from the iPhone’s speaker when you are recording sound.  So how do we fix this?

First, setup your audio session to record audio:

NSURL *url = [NSURL fileURLWithPath:@"/dev/null"];
NSDictionary *settings = [NSDictionary dictionaryWithObjectsAndKeys:
   [NSNumber numberWithFloat: 44100.0],                 AVSampleRateKey,
   [NSNumber numberWithInt: kAudioFormatAppleLossless], AVFormatIDKey,
   [NSNumber numberWithInt: 1],                         AVNumberOfChannelsKey,
   [NSNumber numberWithInt: AVAudioQualityMax],         AVEncoderAudioQualityKey, nil];

recorder = [[AVAudioRecorder alloc] initWithURL:url settings:settings error:&error];
if (recorder) {
   [recorder prepareToRecord]; 
   recorder.meteringEnabled = YES;
   [recorder record]; 
} else {
   NSLog(@"Error: %@", error);

Then tell the device you want to record and play audio at the same time:

AVAudioSession *audioSession = [AVAudioSession sharedInstance];
NSError *err = nil;
[audioSession setCategory :AVAudioSessionCategoryPlayAndRecord error:&err];

Then, and this is the key, allow the volume from the speakers to also be loud when recording:

UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute,

The end result? You can happily play audio at full volume while recording from the device’s microphone. Happy days.

Facebook Connect Mobile: XML Schema Error on Mobile Devices

If you’re getting an XML error when you’re using Facebook Connect to post to a users stream using the function:


Then ensure the following:

  • You don’t have any double quotes in your attachment
  • You don’t have any ampersands in your return URL

For some reason the content is being placed in a hidden field on the page on “mobile” devices.  This isn’t escaping the contents of the post, and hence breaks if you have any of the above.

Highly frustrating!  Hope this helps someone.

New iPhone: Torch, Flash and Front/Rear cameras?

After the recent release to developers of iPhone SDK 4.0, the inevitable scramble to review the new APIs has been on in earnest.  One of the first things noticed were the following new AVCaptureDevice class properties:

  • AVCaptureDevice – isFlashMode Supported
  • AVCaptureDevice – isTorchMode Supported
  • AVCaptureDevice – position (Front or Rear)

These new properties relating to the iPhone SDK class AVCaptureDevice, a class used for audio and video capture and management, suggest that the new iPhone (to be announced at WWDC 2010??) may well include a “Flash”, a “Torch” and a front camera.

If this was to turn out to be true, then a front camera for the phone would make video calls possible, the ability to take photos while viewing the camera feed, and the flash would allow you to take photos in the dark!

All very cool new potential features.  Let’s keep our fingers crossed that this turns out to be the case!

Product Ecology: LCA and Compliance meet usability

WSP Digital today released Product Ecology, a new web based sustainability tool providing Life Cycle Assessment (LCA) and Product Compliance support.

Aimed at product designers, industrial designers, product developers, engineers, environmental managers and brand owners the tool provides three key features:

  • Compliance Navigator – a compliance guidance tool, covering EU RoHS, EU Batteries and EPEAT with EuP and many other compliance requirements to be rolled out over the coming weeks and months
  • Lifecycle Designer – an easy to use and powerful LCA tool backed by data from the Swiss EcoInvent database
  • ecoCompare – a powerful material/process/transport/waste comparison tool

It’s clear that the tool has been developed with usability in mind, providing a unique and powerful web-based tool for the design community.

Online Tool to Convert .ICS file to Excel/CSV

I couldn’t find a decent way online to convert ICS files into an Excel type format for easy manipulation, or adding to documents etc.  So I’ve built a simple one that is now available online:

This takes an iCal URL and provides you with a CSV file as a download.  Makes it much easier to get a list of dates from ICS files and use them for other purposes.

Also available is the CSV2SQL converter that I made last year, taking CSV files and coverting them into INSERT/UPDATE statements for use on a database.

How-To: Force VMWare Restart/Shutdown (Mac)

I love using VMWare Fusion on Mac, it’s perfect as I can run everything I need on one machine, and minimise my exposure to windows.  However, sometimes things go astray – windows “goes to sleep” and won’t come back to allow me to restart or shutdown the virtual machine.  How do you fix this?

Screen shot 2010-02-12 at 9.04.33 AM

Hold down the “option” key and then go to the “Virtual Machine” menu option. You’ll notice that the options switch from “Shutdown” to “Force Shutdown” when you hold down the “option” key.  Simply choose your required “Force” option and you should be back in business!

How To: PHP OAuth Twitter

So, you’re building a web based twitter client in PHP.  Easy, just use a simple Twitter API client and call the Twitter API directly.  But what if you don’t want to store the user’s Twitter authentication information anywhere?  It’s a security risk anyway and some people don’t want to give up their account details to a 3rd party.  So what to do?  The solution is to use OAuth with Twitter. Continue reading “How To: PHP OAuth Twitter”

How-To: Remove Applications from Startup (Mac)

To remove applications that start automatically when you boot up is a simple process on the Mac, however still one that I get asked by friends and family regularly how to control. To manage the applications that launch when you first boot up, follow these steps:

  1. Click the Apple Icon in the top left corner of the screen
  2. Select “System Preferences” from the drop-down menu
  3. Select “Accounts” then click the “Login Items” tab
  4. From here you can now remove or add applications that start automatically when you log in

How-To: Backup all files on your Mac or PC

Okay, I normally don’t come straight out with a non-technical answer to something like “what’s the best way to backup all my files?”, except that there is a really really simple way to do this.

Backblaze is a backup-to-the-cloud service which costs $5 a month for unlimited backups. It deals with external hard drives, duplicate files, etc etc and requires zero configuration. Simply install and you’re done. Thoroughly recommended.