1.导入AVFoundation.framework这个依赖库存
2.把需要的声源拖入工程中。。。。
3.播放器类AVAudioPlayer(这个类必须播放一次创建一个)
4.AVAudioSession这个类一定要加,不然没有声音
代码如下:
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory:AVAudioSessionCategoryPlayback error:nil];
[audioSession setActive:YES error:nil];
NSString *path = [[NSBundle mainBundle] pathForResource:@"call_sound" ofType:@"mp3"];
yxPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path]error:nil];
[yxPlayer play];
[yxPlayer setNumberOfLoops:1000];//循环