简体   繁体   中英

Update UISlider from AVPlayer (iOS / objective-c)

I would like my AVPlayer object to automaticly update my UISlider when playing.

I have found a code on this forum that seems to work for other but I'm broken at some point:

CMTime interval = CMTimeMakeWithSeconds(1.0, NSEC_PER_SEC); // 1 second
self.playbackTimeObserver = [self.player addPeriodicTimeObserverForInterval:interval queue:NULL usingBlock:^(CMTime time) {
    // update slider value here...
}];

I have inserted this code in my viewDidLoad but I removed "self.playbackTimeObserver" as I can't find what type of object is this. I guess that's why it s not working correctly.

Can you please tell me what type is it and where/how to declare it?

Here is my current code:

- (void)viewDidLoad
{
    [super viewDidLoad];

    CMTime interval = CMTimeMakeWithSeconds(1.0, NSEC_PER_SEC); // 1 second
    [songPlayer addPeriodicTimeObserverForInterval:interval queue:NULL usingBlock:^(CMTime time) {
        NSLog(@"seconds = %f", CMTimeGetSeconds(songPlayer.currentTime));
    }];

    self.mmContainerSearch.hidden = NO;
    self.mmContainerDownload.hidden = YES;
    self.mmContainerLibrary.hidden = YES;

}

Its type is id . It right in the documentation .

Return Value

An opaque object that you pass as the argument to removeTimeObserver: to cancel observation.

If you never need to remove the time observer, then you don't really need to save the return value. My guess is that as some point you will want to cleanup. At that point, then you will need to call -removeTimeObserver: .

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