我开发了一款具有音频播放功能的iOS应用。我使用了进度视图来播放音频,并使用了水平滑块进行音量控制。
我需要帮助的2件事:
进度视图无法使用。通过这个,我的意思是当轨道正在播放时,用户应该能够将其拖动到某个点并从那里播放。与iOS音乐应用程序或Spotify ??
“音量”滑块允许用户调整音量,但它不能与iOS设备音频一起使用。意思是,当音频电平改变时,它应该在实际设备上改变。
这是我的代码:
NSString *stringPath = [[NSBundle mainBundle]pathForResource:@"01" ofType:@"MP3"];
NSURL *url = [NSURL fileURLWithPath:stringPath];
NSError *error;
avPlayer = [[AVAudioPlayer alloc]initWithContentsOfURL:url error:&error];
[avPlayer setNumberOfLoops:2];
[avPlayer setVolume:self.sliderVolumeOutlet.value];
[avPlayer stop];
[NSTimer scheduledTimerWithTimeInterval:.1 target:self selector:@selector(updateMyProgress) userInfo:nil repeats:YES];
-(void)updateMyProgress
{
float progress = [avPlayer currentTime]/[avPlayer duration];
self.myProgressView.progress = progress;
}
- (IBAction)sliderVolumeAction:(id)sender {
UISlider *mySlider = sender;
[avPlayer setVolume:mySlider.value];
}
- (IBAction)stopButton:(id)sender {
[avPlayer stop];
[avPlayer setCurrentTime:0];
}
- (IBAction)pauseButton:(id)sender {
[avPlayer pause];
}
- (IBAction)playButton:(id)sender {
[avPlayer play];
}
- (IBAction)backButtonEvent:(id)sender {
[self dismissViewControllerAnimated:YES completion:NULL];
}
- (void)viewWillDisappear:(BOOL)animated
{
[avPlayer stop];
}