AvPlayer seekToTime problem

I am working on a video application and playing videos on AVPlayer

. But the problem is that I am looking for a video at a specific time using UISlider

. The seekToTime

player method gets the time value in integer

, but I want it to get in float

. Please help Here is my code

Float32 sliderValue = (float) avPlayerSlider.value;
[mPlayer seekToTime:CMTimeMake(sliderValue, 1) toleranceBefore:kCMTimeZero toleranceAfter:kCMTimeZero];

      

+3


source to share


2 answers


You can set the correct timeline.

CMTimeMake(12345, 10000); //This is 1.2345 seconds 

      

Or use specific timelines



#define NSEC_PER_USEC   1000ull     /* nanoseconds per microsecond */
#define USEC_PER_SEC    1000000ull  /* microseconds per second */
#define NSEC_PER_SEC    1000000000ull   /* nanoseconds per second */
#define NSEC_PER_MSEC   1000000ull  /* nanoseconds per millisecond */

      

In my player app, I use conversations like this:

CMTime thumbTime = CMTimeMakeWithSeconds(self.currentPlaybackTime, NSEC_PER_SEC);

      

+3


source


I also suffered from this problem, fixed it and the code below:

[_playerItem cancelPendingSeeks];
[_player seekToTime:CMTimeMakeWithSeconds(leftPosition, NSEC_PER_SEC) toleranceBefore:kCMTimeZero toleranceAfter:kCMTimeZero];

      



leftPosition (CGFloat) - asset time, unit - second.

I hope I can help you.

-1


source