当前位置: 动力学知识库 > 问答 > 编程问答 >

audio - iOS - adding a sound on demand in iOS application

问题描述:

Ok, here is the situation. I am writing an iOS application, and I have a text scrolling from bottom to top. At a certain point, let's say when the word "EXAMPLE" shows up, I would like to my app automatically play particular sound, let's say "JINGLE".

How do I do it?

网友答案:
import <AudioToolbox/AudioToolbox.h>

-(void) playSound {
    NSString *soundPath = [[NSBundle mainBundle] pathForResource:@"changeTrack" ofType:@"mp3"];
    SystemSoundID soundID;
    AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath: soundPath], &soundID);
    AudioServicesPlaySystemSound (soundID);
    //[soundPath release];
}

you call in every condition you want

分享给朋友:
您可能感兴趣的文章:
随机阅读: