Posts Tagged ‘iPhone’

iPhone App Development Tips – Playing multiple sounds using AVAudioPlayer

Tuesday, June 16th, 2009

During my journey through App development for the iPhone I will be posting some code that initially gave me a headache and I either managed to solve myself or my good friend Hardy from Catamount Software helped me with.

The first block of code is something that i was struggling with for my latest app called iAnnoyance which is an annoying sounds app. The result i wanted was to have multiple sounds ready to play (.mp3) but each one if triggered must be stopped upon triggering another. In laymens terms “I wanted to stop one sound when another was playing”.

The avenue I decided to go up was the AVAudioPlayer route which I chose for the functionality such as looping and play, stop, pause functions.

So rather than create a seperate player for each sound it was decided that the app could use a single player that would watch the button presses and work out which sound needed to be loaded on the fly. This was achieved using the following code in my MainViewController.m

-(void)playSound:(NSString*)soundName
{
	if (self.currentSound.isPlaying)
	{
		[self.currentSound stop];
	}

	if (![self.lastSoundPlayed isEqual:soundName])
	{
		NSString *soundPath = [[NSBundle mainBundle]
                   pathForResource:soundName ofType:@"mp3"];
		AVAudioPlayer *player =  [[AVAudioPlayer alloc]
                  initWithContentsOfURL:[NSURL fileURLWithPath:soundPath] error:NULL];
		[player setDelegate:self];
		[player prepareToPlay];
		[player play];

		self.currentSound = player;
		[player release];

		self.lastSoundPlayed = soundName;
	}
}

Each button would then look like so:- (more…)

Are you using the iPhone to its maximum ability?

Friday, November 28th, 2008

How to Jailbreak your iPhone

OK, Before i start, I love my iPhone 3G but…….. It is somewhat lacking of certain features found on even bargain bin mobile phones. Why apple have decided to leave these features out is a bit of a dark area but as we have such a great community of developers we have certain ways around them. Some of these methods are not supported by Apple but I paid for my iPhone and I will do what I wish with it. I am going to explain certain methods to you so you can unlock the true potential of this glorious gadget. 

Michael Schofield In Disguise

The most popular method of getting the best out of your iPhone is to Jailbreak it. The simplest method of Jailbreaking your device is by using a popular program called Quickpwn. Quickpwn allows you to run software on your iPhone that is not supported by apple but this doesn’t mean that it will break your new toy! Instead it opens up a world of new opportunities left out by Apple such as Video Recording, MMS and custom ringtones to name but a few.

To Jailbreak your iPhone do the following: (more…)