简体   繁体   中英

AVPlayer seekToTime not correct With UISlider

- (void)viewDidLoad {
    [super viewDidLoad];
    self.slider.maximumValue = 30;
}

- (void)slide:(UISlider *)slider {
    NSLog(@"....progress  slider value:%d", (int)slider.value);
    CMTime showingTime = CMTimeMakeWithSeconds((int)slider.value, 1);
    [self.player seekToTime:showingTime];
}

Everytime I slide the UISlider, The console log the right number as I slided. like 6 seconds. But the slider would jump back to 0; If I slide it to value bigger than 10, like 14, It would slide back to 10.

Can anybody help me ? Thanks

Try this.

You gotta init a CMTime object based on UISlider's value at first. Then you call AVPlayer object's seek to time method. Pass the CMTime object as parameter.

CMTime showingTime = CMTimeMake(slider.value *1000, 1000);

[self.player seekToTime:showingTime toleranceBefore:kCMTimeZero toleranceAfter:kCMTimeZero];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM