AVPlayer를 활용하여 Slider에 재생 시간 표시

먼저 .h 에 선언
AVPlayer *player;
UISlider *slider;

.m 파일에 다음을 추가한다.

ViewDidLoad에 아래 타이머를 추가한다.

// 재생 상태 표시
[NSTimer scheduledTimerWithTimeInterval:0.2 target:self selector:@selector(updateSlider:) userInfo:nil repeats:YES];



-(void)updateSlider:(NSTimer *)timer
{
    sldDuration.value = CMTimeGetSeconds(player.currentTime);
}

-(IBAction)sldDurationValueChanged:(id)sender
{
    CMTime newTime = CMTimeMakeWithSeconds(sldDuration.value, 600);
     [player seekToTime:newTime];
}

슬라이더 바를 이동시키면 그에 해당하는 재생시간을 플레이한다.

댓글