Skip to content

Instantly share code, notes, and snippets.

@jdelStrother
Last active December 29, 2015 10:29
Show Gist options
  • Select an option

  • Save jdelStrother/7657209 to your computer and use it in GitHub Desktop.

Select an option

Save jdelStrother/7657209 to your computer and use it in GitHub Desktop.
@interface MyAudioPlayer() {
AVAudioPlayer* currentPlayer;
}
@end
@implementation MyAudioPlayer
+(instance_type)sharedPlayer {
static MyAudioPlayer* sharedPlayer;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedPlayer = [[MyAudioPlayer alloc] init];
});
return sharedPlayer;
}
-(void)playURL:(NSURL*)url {
[currentPlayer stop];
currentPlayer = [[AVAudioPlayer alloc] initWithURL: url];
[currentPlayer prepareToPlay];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment