Programming

효과음 및 진동 - 특정 음악파일 실행

 2016. 11. 17. 10:22
반응형
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
 
#import "SoundUtil.h"
#import <AudioToolbox/AudioToolbox.h>
 
 
@implementation SoundUtil
 
+ (void) makeSoundEffect // 스마트폰 효과음
{
    //Retrieve audio file
    NSString *path  = [[NSBundle mainBundle] pathForResource:@"Pickup_Coin10" ofType:@"m4a"];
    NSURL *pathURL = [NSURL fileURLWithPath : path];
    
    SystemSoundID audioEffect;
    AudioServicesCreateSystemSoundID((__bridge CFURLRef) pathURL, &audioEffect);
    AudioServicesPlaySystemSound(audioEffect);
    // Using GCD, we can use a block to dispose of the audio effect without using a NSTimer or something else to figure out when it'll be finished playing.
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(30 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        AudioServicesDisposeSystemSoundID(audioEffect);
    });
 
    AudioServicesPlayAlertSoundWithCompletion(kSystemSoundID_Vibrate, nil);// 스마트폰 진동
 
}
 
@end
cs



반응형