노래를 재생하는 동안 ProgressView가 업데이트되지 않습니다. 다른 게시물에서 읽음으로써 각 시간 간격마다 업데이트 방법을 사용했습니다.UIProgressView가 오디오 플레이어를 업데이트하지 않습니까?
- (void)viewDidLoad {
[super viewDidLoad];
NSString *filePath = [[NSBundle mainBundle]pathForResource:@"Fix you_Coldplay" ofType:@"mp3" inDirectory:@"Coldplay"];
NSLog(@"%@",filePath);
NSURL *url = [NSURL fileURLWithPath:filePath];
NSLog(@"%@",url);
musicPlayer = [[AVAudioPlayer alloc]initWithContentsOfURL:url error:nil];
[musicPlayer prepareToPlay];
[trackProgress setProgress:0.0];
}
나는 또한 updateTime : 메서드를 호출하는 데 사용되는 재생 단추가 있습니다.
- (IBAction)playButton:(id)sender {
[musicPlayer play];
[NSTimer scheduledTimerWithTimeInterval:0.0 target:self selector:@selector(updateTime:) userInfo:nil repeats:YES];
NSTimeInterval interval = musicPlayer.currentTime/musicPlayer.duration;
NSLog(@"%f",interval);
}
updateTime : 방법
-(void)updateTime:(NSTimer *)timer {
trackProgress.progress = (musicPlayer.currentTime/musicPlayer.duration);
}
나는 프로그래밍, 심지어 스택 오버 플로우에 아주 새로운 오전. 이것은 제가 게시하는 첫 번째 질문입니다. 도와 주시고 미리 감사드립니다. 모든 변경 타이머 값의
에 진행보기를 업데이트해야합니다. 내가 진행할 때 진행 표시 줄이 0 위치에서 조금 앞으로 이동하지만 그 후에는 다시 부지기가됩니다 – Finch
이 분류에 대해 얻은 최종 부동 소수점 값은 무엇인지 확인할 수 있습니까 : (musicPlayer.currentTime/musicPlayer.duration). –
updateTime : 메서드에 NSLog 문을 삽입 한 경우 float 값은 0.0에서 시작하고 최종 float 값은 0.999081입니다. 하지만 음악이 멈췄을 때 최종 트랙 끝에서 0.002723이었고 갑자기 0.993965로 올라가 0.999081로 끝났습니다. – Finch