ios - addPeriodicTimeObserverForInterval called extra time -
i have avplayer 4 sec video (nstimeinterval duration = cmtimegetseconds(self.playeritem.asset.duration)
= 4).
i'd update ui changes:
self.periodictimeobserver = [self.player addperiodictimeobserverforinterval:cmtimemake(1, 1) queue:dispatch_get_main_queue() usingblock:^(cmtime time) { [weakself currenttimedidchange:cmtimegetseconds(time)]; }];
but reasons calls ui:
- (void)currenttimedidchange:(nstimeinterval)currenttime { nslog(@"timepassed %f, total: %f", currenttime, self.duration); }
logs:
2015-07-23 13:47:07.412 timepassed 0.000000, total: 4.000000 2015-07-23 13:47:07.448 timepassed 0.002814, total: 4.000000 2015-07-23 13:47:07.450 timepassed 0.005481, total: 4.000000 2015-07-23 13:47:08.447 timepassed 1.001473, total: 4.000000 2015-07-23 13:47:09.446 timepassed 2.001612, total: 4.000000 2015-07-23 13:47:10.446 timepassed 3.002021, total: 4.000000 2015-07-23 13:47:11.446 timepassed 4.002139, total: 4.000000 2015-07-23 13:47:12.445 timepassed 5.001977, total: 4.000000 2015-07-23 13:47:12.492 timepassed 5.046618, total: 4.000000
any appreciated
you need sure not calling periodictimeobserver many time write code
if (self.periodictimeobserver == nil){ self.periodictimeobserver = [self.player addperiodictimeobserverforinterval:cmtimemake(1, 1) queue:dispatch_get_main_queue() usingblock:^(cmtime time) { [weakself currenttimedidchange:cmtimegetseconds(time)]; }]; }
then video finishes playing remove observer
[player removetimeobserver:self.periodictimeobserver]; self.periodictimeobserver = nil;
Comments
Post a Comment