Skip to content

Instantly share code, notes, and snippets.

@anthonyherron
Created January 25, 2012 20:59
Show Gist options
  • Save anthonyherron/1678682 to your computer and use it in GitHub Desktop.
Save anthonyherron/1678682 to your computer and use it in GitHub Desktop.
For @fablednet - simple audio playing
@implementation ViewController
@synthesize player = _player;
-(IBAction)playSound
{
if (![_player isPlaying]) {
[_player play];
}
}
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *path = [[NSBundle mainBundle] pathForResource:@"Cat" ofType:@"mp3"];
NSURL *url = [NSURL URLWithString:path];
NSError *error = nil;
_player = [[AVAudioPlayer alloc]initWithContentsOfURL:url error:&error];
if (!_player) {
NSLog(@"Error: %@", [error localizedDescription]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment