Use System Sound Services


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



Copy this code and paste it in your HTML
  1. -(void)playSystemSound:(NSURL*)fileURL{
  2. SystemSoundID systemSoundID;
  3. OSStatus err;
  4.  
  5. err = AudioServicesCreateSystemSoundID((CFURLRef) fileURL,
  6. &systemSoundID);
  7.  
  8. if(err){
  9. NSLog(@"AudioServicesCreateSystemSoundID err = %d",err);
  10. return;
  11. }
  12.  
  13. // systemSoundCompletionProcFunctionはサウンド再生完了時に呼び出されるコールバック関数
  14. AudioServicesAddSystemSoundCompletion(systemSoundID,
  15. NULL,
  16. NULL,
  17. systemSoundCompletionProcFunction,
  18. NULL);
  19. // コールバック関数を削除
  20. //AudioServicesRemoveSystemSoundCompletion(systemSoundID);
  21.  
  22. // 再生開始
  23. AudioServicesPlaySystemSound(systemSoundID);
  24.  
  25. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.