How To Play Sounds In iPhone ?

The iphone media player is very easy to use.

Step 1: First, create a view based iPhone application in xcode and add a button to your view that will play the sound.

Step 2: Drag in the Audio Toolbox framework into your frameworks group in XCode. Just Right click Frameworks from Groups&Files>add>existing framework>Framework>Audio ToolBox.framework>then add to project.

Step 3: Add  a short sound file to your project . Simple,just play the sound in an IBAction “playSound”.


-(IBAction) playSound:(id) sender {





Step 4: If you want to play  .mp3 sound to your application, you need to play the sound in an IBAction “playSong”.


   -(IBAction) playSong:(id) sender {
            NSError *error = nil;
            player = [[AVAudioPlayer alloc] initWithContentsOfURL:
            [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:
            @"music"ofType:@"mp3"]] error:&error];

             player.delegate = self;
             if(error != NULL) {

             NSLog([error description]);

            [error release];
      [player play];



You can downloaded SourceCode from here MusicPlayer

Leave a Comment: