diff --git a/NRAVPlayerTracker/NRAVPlayerTracker/Tracker/NRTrackerAVPlayer.m b/NRAVPlayerTracker/NRAVPlayerTracker/Tracker/NRTrackerAVPlayer.m index ac1e0e9..06c342f 100644 --- a/NRAVPlayerTracker/NRAVPlayerTracker/Tracker/NRTrackerAVPlayer.m +++ b/NRAVPlayerTracker/NRAVPlayerTracker/Tracker/NRTrackerAVPlayer.m @@ -96,6 +96,11 @@ - (void)unregisterListeners { } @catch (id e) {} + @try { + [self.state removeObserver:self forKeyPath:@"isUserSeeking"]; + } + @catch (id e) {} + @try { [self.playerInstance removeTimeObserver:self.timeObserver]; self.timeObserver = nil; @@ -176,6 +181,11 @@ - (void)registerListeners { options:NSKeyValueObservingOptionNew context:NULL]; + [self.state addObserver:self + forKeyPath:@"isUserSeeking" + options:NSKeyValueObservingOptionNew + context:NULL]; + self.timeObserver = [self.playerInstance addPeriodicTimeObserverForInterval:CMTimeMake(1, 2) queue:NULL usingBlock:^(CMTime time) { @@ -210,19 +220,26 @@ - (void)observeValueForKeyPath:(NSString *)keyPath context:(void *)context { AV_LOG(@"(AVPlayerTracker) Observed keyPath = %@ , object = %@ , change = %@ , context = %@", keyPath, object, change, context); - - if ([keyPath isEqualToString:@"currentItem.playbackBufferEmpty"]) { - if (!self.state.isBuffering && self.state.isPaused && self.playerInstance.rate == 0.0) { - [self sendSeekStart]; - } - // The state isSeekingDuringPlayback can be set manually using the setIsSeekingDuringPlayback function - // Otherwise, KVO observers are not being notified that a seek happened during playback (rate == 1.0) - else if (!self.state.isBuffering && self.state.isSeekingDuringPlayback && !self.state.isPaused && self.playerInstance.rate == 1.0) { + // User seek event sent by the integrators + if ([keyPath isEqualToString:@"isUserSeeking"]) { + if (self.state.isUserSeeking) { [self sendSeekStart]; } } + else if ([keyPath isEqualToString:@"currentItem.playbackBufferEmpty"] && self.state.isSeeking && self.state.isPaused) { + [self sendBufferStart]; + } + else if ([keyPath isEqualToString:@"currentItem.playbackBufferFull"] && self.state.isSeeking && self.state.isPaused) { + [self sendBufferEnd]; + [self sendSeekEnd]; + } else if ([keyPath isEqualToString:@"currentItem.playbackLikelyToKeepUp"]) { [self sendRequest]; + + if (self.state.isSeeking && self.state.isPaused && self.playerInstance.currentItem.playbackLikelyToKeepUp) { + [self sendBufferEnd]; + [self sendSeekEnd]; + } } else if ([keyPath isEqualToString:@"status"]) { if (self.playerInstance.status == AVPlayerItemStatusReadyToPlay) { @@ -255,6 +272,7 @@ - (void)observeValueForKeyPath:(NSString *)keyPath } else { [self sendBufferEnd]; + [self sendSeekEnd]; } } else { // Fallback on earlier versions @@ -364,7 +382,7 @@ - (NSString *)getTrackerName { } - (NSString *)getTrackerVersion { - return @"1.0.0"; + return @"2.0.0"; } - (NSString *)getPlayerVersion { @@ -459,7 +477,6 @@ - (void)sendEnd { - (void)sendResume { //Make sure we close the previous blocks - [self sendSeekEnd]; // Send RESUME [super sendResume]; diff --git a/NRIMATracker/NRIMATracker/Tracker/NRTrackerIMA.m b/NRIMATracker/NRIMATracker/Tracker/NRTrackerIMA.m index 7975e01..959de2a 100644 --- a/NRIMATracker/NRIMATracker/Tracker/NRTrackerIMA.m +++ b/NRIMATracker/NRIMATracker/Tracker/NRTrackerIMA.m @@ -76,7 +76,7 @@ - (NSString *)getTrackerName { } - (NSString *)getTrackerVersion { - return @"1.0.0"; + return @"2.0.0"; } - (NSNumber *)getPlayhead { diff --git a/NewRelicVideoCore/NewRelicVideoCore/Model/NRTrackerState.h b/NewRelicVideoCore/NewRelicVideoCore/Model/NRTrackerState.h index a54def7..9e39d02 100644 --- a/NewRelicVideoCore/NewRelicVideoCore/Model/NRTrackerState.h +++ b/NewRelicVideoCore/NewRelicVideoCore/Model/NRTrackerState.h @@ -20,10 +20,10 @@ NS_ASSUME_NONNULL_BEGIN - (void)reset; /** - Set the state isSeekingDuringPlayback. - This function has to be called at least when seeking occurs during playback because the KVO observer methods will not catch this type of seek. + Set the state isUserSeeking to true. + This function has to be called whenever a seek event occurs during playback. */ -- (void)setIsSeekingDuringPlayback; +- (void)startSeekingEvent; /** Return state isPlayerReady. @@ -68,11 +68,11 @@ NS_ASSUME_NONNULL_BEGIN - (BOOL)isSeeking; /** - Return state isSeekingDuringPlayback. + Return state isUserSeeking. @return state.. */ -- (BOOL)isSeekingDuringPlayback; +- (BOOL)isUserSeeking; /** Return state isBuffering. diff --git a/NewRelicVideoCore/NewRelicVideoCore/Model/NRTrackerState.m b/NewRelicVideoCore/NewRelicVideoCore/Model/NRTrackerState.m index 6a90e55..9f51e39 100644 --- a/NewRelicVideoCore/NewRelicVideoCore/Model/NRTrackerState.m +++ b/NewRelicVideoCore/NewRelicVideoCore/Model/NRTrackerState.m @@ -15,7 +15,7 @@ @interface NRTrackerState () @property (nonatomic) BOOL isPlaying; @property (nonatomic) BOOL isPaused; @property (nonatomic) BOOL isSeeking; -@property (nonatomic) BOOL isSeekingDuringPlayback; +@property (nonatomic) BOOL isUserSeeking; @property (nonatomic) BOOL isBuffering; @property (nonatomic) BOOL isAd; @property (nonatomic) BOOL isAdBreak; @@ -38,19 +38,14 @@ - (void)reset { self.isPlaying = NO; self.isPaused = NO; self.isSeeking = NO; - self.isSeekingDuringPlayback = NO; + self.isUserSeeking = NO; self.isBuffering = NO; self.isAd = NO; self.isAdBreak = NO; } -- (void)setIsSeekingDuringPlayback { - if (self.isPlaying) { - self.isSeekingDuringPlayback = true; - } - else { - self.isSeekingDuringPlayback = false; - } +- (void)startSeekingEvent { + self.isUserSeeking = true; } - (BOOL)goPlayerReady { @@ -91,6 +86,7 @@ - (BOOL)goEnd { self.isPlaying = NO; self.isPaused = NO; self.isSeeking = NO; + self.isUserSeeking = NO; self.isBuffering = NO; return true; } @@ -155,7 +151,7 @@ - (BOOL)goSeekStart { - (BOOL)goSeekEnd { if (self.isStarted && self.isSeeking) { self.isSeeking = false; - self.isSeekingDuringPlayback = false; + self.isUserSeeking = false; self.isPlaying = true; return true; } diff --git a/NewRelicVideoCore/NewRelicVideoCore/NRVideoDefs.h b/NewRelicVideoCore/NewRelicVideoCore/NRVideoDefs.h index 3638e63..9a700f6 100644 --- a/NewRelicVideoCore/NewRelicVideoCore/NRVideoDefs.h +++ b/NewRelicVideoCore/NewRelicVideoCore/NRVideoDefs.h @@ -8,7 +8,7 @@ #ifndef NRVideoDefs_h #define NRVideoDefs_h -#define NRVIDEO_CORE_VERSION @"1.0.0" +#define NRVIDEO_CORE_VERSION @"2.0.0" #define NR_VIDEO_EVENT @"MobileVideo"