《30天精通iPhone手机编程》-Day20-DJ混音器

来源:互联网 发布:一维数组的表达方式 编辑:程序博客网 时间:2024/05/16 09:57

        这一章介绍了新的控件UISlider控件,建立UISwitch,UISlider,AVAudioPlayer对象的交互方法

- (void)viewDidLoad {    [super viewDidLoad];//获取吉他声音播放器所播放的声音文件的路径名NSString *guitarfilePath = [[NSBundle mainBundle] pathForResource:@"guitar" ofType:@"caf"];//转换字符类型变量的路径为URL链接路径NSURL *guitarfileURL = [[NSURL alloc] initFileURLWithPath:guitarfilePath];//初始化播放器,定义播放连接内容self.guitarPlayer = [[AVAudioPlayer alloc]initWithContentsOfURL:guitarfileURL error:nil];[self.guitarPlayer prepareToPlay];[guitarfilePath release];[guitarfileURL release];//获取节拍声音播放器所播放的声音文件的路径名NSString *beatsfilePath = [[NSBundle mainBundle] pathForResource:@"beats" ofType:@"caf"];//转换字符类型变量的路径为URL链接路径NSURL *beatsfileURL = [[NSURL alloc] initFileURLWithPath:beatsfilePath];//初始化播放器,定义播放连接内容self.beatsPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:beatsfileURL error:nil];[self.beatsPlayer prepareToPlay];[beatsfilePath release];[beatsfileURL release];}//调整吉他声音的音量-(IBAction)guitarVolumeChange{    //定义吉他声音播放器的音量属性值为吉他滑块的数值guitarPlayer.volume = guitarVolumeControl.value;}//调整节拍声音的音量-(IBAction)beatsVolumeChange{    //定义节拍声音播放器的音量属性值为吉他滑块的数值beatsPlayer.volume = beatsVolumeControl.value;}//吉他声音播放开关-(IBAction)guitarSwitch{if (includeGuitar.on) {//吉他声音播放时间点在开始位置    self.guitarPlayer.currentTime = 0;//吉他声音循环播放次数为5    self.guitarPlayer.numberOfLoops=5;//吉他声音播放器启动[self.guitarPlayer play];}else {[self.guitarPlayer stop];}}-(IBAction)beatsSwitch{if (includeBeats.on) {self.beatsPlayer.currentTime = 0;self.beatsPlayer.numberOfLoops=5;[self.beatsPlayer play];    }else {[self.beatsPlayer stop];    }}


原创粉丝点击