how To Add sound in iphone/ipad ?


first add Frameworks (AVFoundation.framework)

and import:

#import <AVFoundation/AVFoundation.h>

- (void)viewDidLoad {
    [super viewDidLoad];


NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/Sound.mp3", [[NSBundle mainBundle] resourcePath]]];
   AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil];
   audioPlayer.numberOfLoops =0;
   [audioPlayer play];

}
Reactions: