播放wav聲音格式

1.

#import <AudioToolbox/AudioToolbox.h>

 

2.聲明 成員变量 

    SystemSoundID soundID;

 

 

3.播放

- (void)playSoundWith:(int)index

{

    

    if (soundID ) {

        AudioServicesDisposeSystemSoundID(soundID);

    }

    NSString *path = [[NSBundlemainBundle] pathForResource:[NSStringstringWithFormat:@"ring%d",index] ofType:@"wav"];

    AudioServicesCreateSystemSoundID((__bridgeCFURLRef)[NSURLfileURLWithPath:path], &soundID);

    

    AudioServicesPlaySystemSound(soundID);

 

 

}

 

你可能感兴趣的:(播放wav聲音格式)