0

I just want to play a little ding on when the splash screen loads. I'm guesing that goes in the RootViewControler.m under viewDidLoad. As for playing the audio file I'm googled and found a lot of things I haven't been able to make work.

What type of audio file should it be? wav mp3 etc. or does it matter.

I'm not sure what ofType@"caf" is, but here is what I have found, when I try it I get AVAudioplayer undeclared (which I'm thinking is a total newb error but don't know):

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    NSURL* musicFile = [NSURL fileURLWithPath:[[NSBundle mainBundle] 
                                               pathForResource:@"click"
                                               ofType:@"caf"]];
    AVAudioPlayer *click = [[AVAudioPlayer alloc] initWithContentsOfURL:musicFile error:nil];
    [click play];
    [click release];
    [super viewDidLoad];
}

Thank you for any help, R

rd42
  • 3,584
  • 15
  • 56
  • 68

2 Answers2

1

I think the problem is that you haven't added the AVFoundation framework. Once you add the AVFoundation.framework, you'll need to #import <AVFoundation/AVAudioPlayer.h> and hopefully it will work.

Aii
  • 11
  • 2
1

From the Apple Documentation : pathForResource:ofType:

Returns the full pathname for the resource identified by the specified name and file extension.

  - (NSString *)pathForResource:(NSString *)name ofType:(NSString *)extension

The program looks for a file called click.caf in your main bundle. The warning about AVPlayer being undeclared means that you have to add the AVFoundationFramework to your project and import the proper .h - file with #import <AVFoundation/AVAudioPlayer.h>.

Philipp
  • 1,903
  • 2
  • 24
  • 33