Question

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;

}
Was it helpful?

Solution

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:.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top