Skip to content

Instantly share code, notes, and snippets.

@wjlafrance
Created March 22, 2011 00:39
Show Gist options
  • Save wjlafrance/880537 to your computer and use it in GitHub Desktop.
Save wjlafrance/880537 to your computer and use it in GitHub Desktop.
#import <AVFoundation/AVFoundation.h>
// Initialize the music player
rickroll = [[AVAudioPlayer alloc]
initWithContentsOfURL:[[NSBundle mainBundle]
URLForResource:@"Rickroll"
withExtension:@"mp3"]
error:nil];
// Play music for 300ms
[self performSelectorInBackground:@selector(playAudio) withObject:nil];
// Code to do stuff - NSAutoreleasePool is necessary because it's in a background thread
- (void)playAudio {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
if ([rickroll isPlaying])
return;
[rickroll play];
[NSThread sleepForTimeInterval:0.3];
[rickroll pause];
[pool release];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment