This is a newbie question.
I have a very simple app that is supposed to only play an audio file when a button on the main view is tapped.
I am using XCode version 4.6.
I added an audio file 'audioclip.wav' to my project. I have added the AVFoundation.framework
.
My project only has ViewController.h
and ViewController.m
.
I double clicked and dragged from the button in the storyboard to the .h file using the assistant editor to create my IBAction
connection.
My ViewController.h:
#import <UIKit/UIKit.h>
#import<AVFoundation/AVAudioPlayer.h>
@interface ViewController : UIViewController <AVAudioPlayerDelegate> {
}
- (IBAction)playAudio:(id)sender;
@end
My ViewController.m:
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)playAudio:(id)sender {
AVAudioPlayer *audioPlayer;
NSString *audioPath = [[NSBundle mainBundle] pathForResource:@"audioclip" ofType:@"wav" ];
NSURL *audioURL = [NSURL fileURLWithPath:audioPath];
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:audioURL error:nil];
[audioPlayer play];
}
@end
For whatever reason (probably something silly I left out) The audioclip.wav file does not play when I click the button. I have tested on the iPhone 6.1 simulator and on my device.