In iOS Avplayer, Addperiodictimeobserverforinterval Seems to Be Missing

In iOS AVPlayer, addPeriodicTimeObserverForInterval seems to be missing

Check this func addPeriodicTimeObserver(forInterval interval: CMTime,
queue: DispatchQueue?,
using block: @escaping (CMTime) -> Void) -> Any

It is in the documents also for example check this code snippet

let timeObserverToken = player.addPeriodicTimeObserver(forInterval: interval, queue: DispatchQueue.main) { [unowned self] time in 
}

Referenced from here

AVPlayer removing a periodicTimeObserver

Glad to see weakSelf worked for you ...

In the above I don't see you assigning the result of

  [player addPeriodicTimeObserverForInterval ...

to self.timeObserver it may be a typo but it should be ;

   self.timeObserver =  [player addPeriodicTimeObserverForInterval ...

if you intend to call

   [player removeTimeObserver:self.timeObserver]; 

you also missed the ";" above.

Is KVO on AVPlayerItem.loadedTimeRanges possible?

Actually, I'm using KVO for loadedTimeRanges without any trouble. Maybe you're just not setting the right options? The following is a very slight modification of some of the code in Apple's AVPlayerDemo, and it's working quite nicely for me.

//somewhere near the top of the file
NSString * const kLoadedTimeRangesKey = @"loadedTimeRanges";
static void *AudioControllerBufferingObservationContext = &AudioControllerBufferingObservationContext;

- (void)someFunction
{
// ...

//somewhere after somePlayerItem has been initialized
[somePlayerItem addObserver:self
forKeyPath:kLoadedTimeRangesKey
options:NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew
context:AudioControllerBufferingObservationContext];

// ...
}

- (void)observeValueForKeyPath:(NSString*) path
ofObject:(id)object
change:(NSDictionary*)change
context:(void*)context
{
if (context == AudioControllerBufferingObservationContext)
{
NSLog(@"Buffering status: %@", [object loadedTimeRanges]);
}
}

Is there a free or commercial dvd burner sdk for cocoa?

Apple provide an API of their very own: the Disc Recording Framework.

There is even a Disc Recording UI Framework, too.



Related Topics



Leave a reply



Submit