Created
May 22, 2017 18:57
-
-
Save gatamar/508ef23932b2408f55b2aad2b6d0e279 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // subscribe for KVO somewhere | |
| [_player addObserver:self | |
| forKeyPath:@"currentItem.loadedTimeRanges" | |
| options:NSKeyValueObservingOptionNew | |
| context:nil]; | |
| ... | |
| - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object | |
| change:(NSDictionary *)change context:(void *)contex | |
| { | |
| ... | |
| if (object == _player && [keyPath isEqualToString:@"currentItem.loadedTimeRanges"]) | |
| { | |
| NSArray *timeRanges = (NSArray*)[change objectForKey:NSKeyValueChangeNewKey]; | |
| if (timeRanges && [timeRanges count]) | |
| { | |
| CMTimeRange timerange; | |
| NSValue* val = [timeRanges objectAtIndex:0]; | |
| [val getValue:&timerange]; | |
| float currentBufferDuration = CMTimeGetSeconds(CMTimeAdd(timerange.start, timerange.duration)); | |
| CMTime duration = _player.currentItem.asset.duration; | |
| float seconds = CMTimeGetSeconds(duration); | |
| float hours=seconds/3600; | |
| NSLog(@"Movie takes %.2f hours", hours); | |
| if (currentBufferDuration == seconds) | |
| { | |
| // Ready to play. | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment