0

I am trying to play a button click sound,also that i should be able to manage click sound along with volume button.

What i have done is Added AVFoundationFramework to project,

in .h file

#import <AVFoundation/AVAudioPlayer.h>
#import <AVFoundation/AVFoundation.h>

in .m file under button click method

NSString *soundPath = [[NSBundle mainBundle] pathForResource:@"sound1" ofType:@"mp3"];
NSURL *soundUrl = [NSURL fileURLWithPath:soundPath];

AVAudioPlayer *player = [[AVAudioPlayer alloc] initWithURL:soundUrl];

[player play];

but i get the above error.Any help would be appreciated.

Michael Dautermann
  • 88,797
  • 17
  • 166
  • 215
Suraj K Thomas
  • 5,773
  • 4
  • 52
  • 64

1 Answers1

2

It's "initWithContentsOfURL:" not "initWithURL:".

As in:

AVAudioPlayer *player = [[AVAudioPlayer alloc] 
                          initWithContentsOfURL:soundUrl];
Michael Dautermann
  • 88,797
  • 17
  • 166
  • 215
  • Thanks bro.Error is removed.Problem is sound is not getting played.Any thoughts? – Suraj K Thomas Jan 02 '14 at 07:32
  • Yeah, check to see if you really have the correct URL by using "`[soundURL checkResourceIsReachableAndReturnError: &error]`" before you play the sound. [There's more information about making certain you have the right URL in this question](http://stackoverflow.com/questions/1927754/testing-file-existence-using-nsurl). – Michael Dautermann Jan 02 '14 at 07:34