0
如何將音量按鈕與我的音量滑塊連接?按音量按鈕時更改音量滑塊位置
我使用AVAudioPlayer和滑塊音量和物理音量按鈕工作正常,但事情是,他們正在單獨工作,所以我需要實現的是,當我按音量滑塊物理音量按鈕也改變位置。
我的代碼是按照下文:
-(IBAction)btnClked:(id)sender {
NSURL *musicFile;
musicFile = [NSURL fileURLWithPath:[[NSBundle mainBundle]
pathForResource:@"music"
ofType:@"mp3"]];
myAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:musicFile error:nil];
[self.button setBackgroundImage:[UIImage imageNamed:@"Play.png"] forState:UIControlStateNormal];
if (self.button.tag == 0) {
self.button.tag = 1;
[self.button setImage:[UIImage imageNamed:@"Stop.png"] forState:UIControlStateNormal];
[myAudio play];
myAudio.numberOfLoops = -1;
myAudio.currentTime = 0;
myAudio.volume = 0.5;
} else {
self.button.tag = 0;
[self.button setImage:[UIImage imageNamed:@"Play.png"] forState:UIControlStateNormal];
[myAudio stop];
}
}
我的滑塊調整方法如下:提前
- (IBAction)sliderChange:(UISlider *)sender {
myAudio.volume = sender.value/1;
}
謝謝!
使用MPVolumeView那麼它會工作:) –