1] Add AVFoundation.framwork in Project
2] then import this framwork in code
#import <AVFoundation/AVFoundation.h>
3] Make the object for AVAudioPlayer and make property synthesise for it
@property(strong,nonatomic)AVAudioPlayer *player;
4] And then add following code where you want to play sound/audio file
NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:@"Snake sound"
ofType:@".mp3"];
NSURL *soundFileURL = [NSURL fileURLWithPath:soundFilePath];
self.player = [[AVAudioPlayer alloc] initWithContentsOfURL:soundFileURL
error:nil];
[self.player play];
No comments:
Post a Comment