Created
January 25, 2012 20:59
-
-
Save anthonyherron/1678682 to your computer and use it in GitHub Desktop.
For @fablednet - simple audio playing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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