iOS播放音效

AVAudioPlayer *player = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"水滴声音" ofType:@"mp3"]] error:nil];//使用本地URL创建

player.volume = 1;

player.numberOfLoops = 1;//默认只播放一次

_player = player;

[player prepareToPlay];

[self performSelector:@selector(yinliang) withObject:nil afterDelay:2];

[player play];//播放

你可能感兴趣的:(iOS播放音效)