AVFoundation サンプル


/ Published in: Objective C
Save to your folder(s)



Copy this code and paste it in your HTML
  1. - (void) playSoundWithURL: (NSURL*) fileURL{
  2. NSError *error = nil;
  3. AVAudioPlayer *player =
  4. [[AVAudioPlayer alloc] initWithContentsOfURL: fileURL
  5. error: &error];
  6. if(error){
  7. NSLog(@"error = %@",error);
  8. NSLog(@"[error code] = %d",[error code]);
  9. return;
  10. }
  11. player.delegate = self;
  12. [player play];
  13. }
  14.  
  15. -(void) audioPlayerDidFinishPlaying: (AVAudioPlayer *)player successfully:(BOOL) flag{
  16.  
  17. [player release];
  18. }
  19.  
  20.  
  21. // 呼び出し
  22. -(void) viewDidLoad{
  23. NSString *path = [[NSBundle mainBundle] pathForResource:@"pad"
  24. ofType:@"aif"];
  25. NSURL *fileURL = [NSURL fileURLWithPath:path];
  26. [self playSoundWithURL:fileURL];
  27. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.