Skip to content

Listen for failedToPlayToEndTimeNotification #261

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 37 additions & 18 deletions MUXSDKStats/MUXSDKStats/MUXSDKPlayerBinding.m
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ - (void)attachAVPlayer:(AVPlayer *)player {
context:MUXSDKAVPlayerTimeControlStatusObservationContext];

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleDidPlayToEndTimeNotification:) name:AVPlayerItemDidPlayToEndTimeNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleFailedToPlayToEndTimeNotification:) name:AVPlayerItemFailedToPlayToEndTimeNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleAVPlayerAccess:) name:AVPlayerItemNewAccessLogEntryNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleRenditionChange:) name:RenditionChangeNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleAVPlayerError:) name:AVPlayerItemNewErrorLogEntryNotification object:nil];
Expand Down Expand Up @@ -195,15 +196,38 @@ - (void)handleApplicationWillTerminate:(NSNotification *)notification {

}

- (void)dispatchEndedEvent {
MUXSDKEndedEvent *endedEvent = [[MUXSDKEndedEvent alloc] init];
MUXSDKPlayerData *playerData = [self getPlayerData];
endedEvent.playerData = playerData;
[MUXSDKCore dispatchEvent:endedEvent forPlayer:_name];
}

# pragma mark AVPlayerItemDidPlayToEndTimeNotification

- (void)handleDidPlayToEndTimeNotification:(NSNotification *)notification {
if ([self isNotificationAboutCurrentPlayerItem:notification]) {
MUXSDKEndedEvent *endedEvent = [[MUXSDKEndedEvent alloc] init];
MUXSDKPlayerData *playerData = [self getPlayerData];
endedEvent.playerData = playerData;
[MUXSDKCore dispatchEvent:endedEvent forPlayer:_name];
if (![self isNotificationAboutCurrentPlayerItem:notification]) {
return;
}

[self dispatchEndedEvent];
}

# pragma mark AVPlayerItemFailedToPlayToEndTimeNotification

- (void)handleFailedToPlayToEndTimeNotification:(NSNotification *)notification {
if (![self isNotificationAboutCurrentPlayerItem:notification]) {
return;
}

// TODO: further test behavior here, make sure we're not sending the error twice:

if (_automaticErrorTracking) {
NSError *error = notification.userInfo[AVPlayerItemFailedToPlayToEndTimeErrorKey];
[self dispatchError:error];
}

[self dispatchEndedEvent];
}

# pragma mark AVPlayerItemAccessLog
Expand Down Expand Up @@ -874,28 +898,23 @@ - (void)dispatchError {
if (!_automaticErrorTracking) {
return;
}

[self dispatchError:(_player.error ?: _playerItem.error)];
}

- (void)dispatchError:(NSError *)error {
if (![self hasPlayer]) {
return;
}
[self checkVideoData];
MUXSDKPlayerData *playerData = [self getPlayerData];

// Derived from the player.
if (_player.error) {
NSInteger errorCode = _player.error.code;
if (errorCode != 0 && errorCode != NSNotFound) {
[playerData setPlayerErrorCode:[NSString stringWithFormat:@"%ld", (long)errorCode]];
}
NSString *errorLocalizedDescription = _player.error.localizedDescription;
if (errorLocalizedDescription != nil) {
[playerData setPlayerErrorMessage:errorLocalizedDescription];
}
} else if (_playerItem && _playerItem.error) {
NSInteger errorCode = _playerItem.error.code;
if (error) {
NSInteger errorCode = error.code;
if (errorCode != 0 && errorCode != NSNotFound) {
[playerData setPlayerErrorCode:[NSString stringWithFormat:@"%ld", (long)errorCode]];
}
NSString *errorLocalizedDescription = _playerItem.error.localizedDescription;
NSString *errorLocalizedDescription = error.localizedDescription;
if (errorLocalizedDescription != nil) {
[playerData setPlayerErrorMessage:errorLocalizedDescription];
}
Expand Down