开发者

Playing short selfmade sound with immediate start in iOS

I have a self-generated DTMF sound (with a wav header) generated by program that I want to be able to play quickly, in fact as soon as the user touches a bu开发者_运维技巧tton. This DTMF sound must play/loop infinitely, until I stop it. Some other sounds must be able to be played at the same time.

I'm very new to Audio programming, and I tested many ways of doing that and I'm lost now.

How can I achieve that ?

Needs :

  • very quick playback start (including the first time)
  • many sounds at the same time (short sounds +- 2-6 seconds)
  • infinite DTMF sound without gaps
  • having control over the different sounds that are playing / being able to stop just one played sound


AVAudioPlayer if you can live with some latency, OpenAL (for example Finch) if you really need to have the latency as low as possible.


I use already exist .wav file. and I can easily play it.

For run following code. include AudioToolbox framework.

write into .h file #import <AudioToolbox/AudioToolbox.h>
Write into .m file

-(IBAction)startSound{

    //Get the filename of the sound file:
    NSString *path = [NSString stringWithFormat:@"%@%@", [[NSBundle mainBundle] resourcePath], @"/sound1.wav"];

        //declare a system sound
        SystemSoundID soundID;

    //Get a URL for the sound file
    NSURL *filePath = [NSURL fileURLWithPath:path isDirectory:NO];

    //Use audio sevices to create the sound
    AudioServicesCreateSystemSoundID((CFURLRef)filePath, &soundID);
    //Use audio services to play the sound
    [self sound];
    timer =[ [NSTimer scheduledTimerWithTimeInterval:2.1 target:self selector:@selector(sound) userInfo:nil repeats:YES]retain];

}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜