AVPlayer seekToTime not correct With UISlider
Asked Answered
F

2

2
- (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

Flaw answered 6/7, 2015 at 3:30 Comment(0)
Z
5

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];
Zantos answered 18/7, 2015 at 2:20 Comment(0)
H
0

Swift AVPlayer.seek(to:)

Swift version

When you skip toleranceBefore and toleranceAfter - .positiveInfinity is used by default and it is extends limits in which system can return an optimized result

Be as you wish:

self.player.seek(
    to: CMTimeMake(
        value: Int64(playbackSlider.value * 1000),
        timescale: 1000
    )
)

Be at time:

self.player.seek(
    to: CMTimeMake(
        value: Int64(playbackSlider.value * 1000),
        timescale: 1000
    ),
    toleranceBefore: .zero, 
    toleranceAfter: .zero
)

[Swift AVAssetImageGenerator.copyCGImage(at:actualTime:)]

Hereabouts answered 17/2 at 15:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.