Skip to content

Instantly share code, notes, and snippets.

@dabing1022
Created July 8, 2015 03:25
Show Gist options
  • Select an option

  • Save dabing1022/649b8583b48d7808ae55 to your computer and use it in GitHub Desktop.

Select an option

Save dabing1022/649b8583b48d7808ae55 to your computer and use it in GitHub Desktop.
常用方法片段
// 01. init method forbidden
- (id)init {
@throw [NSException exceptionWithName:NSInternalInconsistencyException
reason:@"-init is not a valid initializer for the class Foo"
userInfo:nil];
return nil;
}
@dabing1022
Copy link
Author

// 04. Play sound

NSURL *soundurl  = [[NSBundle mainBundle] URLForResource: @"mysound" withExtension: @"caf"];
AVAudioPlayer *mySoundPlayer =[[AVAudioPlayer alloc] initWithContentsOfURL:soundurl error:&error];
mySoundPlayer .volume=0.4f; //between 0 and 1
[mySoundPlayer prepareToPlay];
mySoundPlayer.numberOfLoops=0; //or more if needed

[mySoundPlayer play];

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment