0

Playing sound using AVAudioPlayer in iPhone

by Deepak Dhakal 11. May 2009 12:34

Add a audio framwork AVFoundation using

#import and use code below to play a sound

 ########################### #########
AVAudioPlayer *myExampleSound;
NSString *myExamplePath = [[NSBundle mainBundle] pathForResource:@"horror" ofType:@"wav"];
myExampleSound =[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:myExamplePath] error:NULL];
myExampleSound.delegate = self;
[myExampleSound play]; //play sound
//[myExampleSound stop]; you can stop like this
###########################################################

When you add a AVFoundation framwork, make sure to use absolute path.. Relative path is by default there and that gives compile error ..

Tags:

General | iPhone

Powered by BlogEngine.NET 1.5.0.7
Original Design by Laptop Geek, Adapted by onesoft