Created
March 22, 2011 00:39
-
-
Save wjlafrance/880537 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#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