IPhone 系统声音AP 适合余短音播放 不超过5秒 使用框架AudioToolbox

 

#import <UIKit/UIKit.h>

#import <AudioToolbox/AudioToolbox.h>

@interface SoundViewController : UIViewController {

}

-(IBAction) buttonPressed;

@end

 

 

#import “SoundViewController.h”

@implementation SoundViewController

– (void)didReceiveMemoryWarning {

// Releases the view if it doesn’t have a superview.

   [super didReceiveMemoryWarning];

// Release any cached data, images, etc that aren’t in use.

}

– (void)viewDidUnload {

// Release any retained subviews of the main view.

// e.g. self.myOutlet = nil;

}

– (void)dealloc {

   [super dealloc];

}

-(IBAction) buttonPressed {

 

NSString *path = [[NSBundle mainBundle] pathForResource:@”懒猪起床” ofType:@”caf”];

NSURL *url = [NSURL fileURLWithPath:path];

SystemSoundID outSystemSoundID;

AudioServicesCreateSystemSoundID((__bridge CFURLRef)url,&outSystemSoundID);

//播放声音

AudioServicesPlaySystemSound(outSystemSoundID);

//播放震动

AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);

}

@end