Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AVPlayer Progress slider change with user dragging it

Tags:

ios

avplayer

I am using AVPlayer, and its working good.

I put slider and it is progression according to player duration. But i want if user drags slider then play time changes accordingly. i.e. Song forwards or backwards according to slider position.

I have tried

-(IBAction)sliderChange:(id)sender{
[player pause];
CMTime t = CMTimeMake(slider.value,1);
[player seekToTime:t];    
[player play];
}

But it again takes slider to starting point. Any help would be much appreciated.

EDIT (WORKING WITH BELOW LINK)

AVPlayer Video SeekToTime

like image 434
Mann Avatar asked Jun 12 '12 10:06

Mann


1 Answers

-(IBAction) valueChangeSliderTimer:(id)sender{
    [avplayer pause];
    isPlaying = FALSE;
    [btnPauseAndPlay setTitle:@"Play" forState:UIControlStateNormal];

    float timeInSecond = sliderTimer.value;

    timeInSecond *= 1000;
    CMTime cmTime = CMTimeMake(timeInSecond, 1000);

    [avplayer seekToTime:cmTime toleranceBefore:kCMTimeZero toleranceAfter:kCMTimeZero];
}

Edited Code .

And try this link as well : Try this link

like image 74
Dhruv Avatar answered Oct 05 '22 15:10

Dhruv