-
Notifications
You must be signed in to change notification settings - Fork 19
Open
Description
AVPlayer is used to play loop video in my app.
So when one of this loops ends, the notification is called what ever item is currently playing.
So I simply fix this by changing the register for remote notifications.
- (void)setupNotifications {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleAVPlayerItemDidPlayToEndTime:)
name:AVPlayerItemDidPlayToEndTimeNotification object:_player.currentItem];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleAVPlayerItemFailedToPlayToEndTime:)
name:AVPlayerItemFailedToPlayToEndTimeNotification object:_player.currentItem];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleAVPlayerItemPlaybackStalled:)
name:AVPlayerItemPlaybackStalledNotification object:_player.currentItem];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleApplicationDidEnterBackground:)
name:UIApplicationDidEnterBackgroundNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleApplicationDidBecomeActive:)
name:UIApplicationDidBecomeActiveNotification object:nil];
}
#pragma mark - Notification Handlers
- (void)handleAVPlayerItemDidPlayToEndTime:(NSNotification *)notification {
if (notification.object == _player.currentItem)
{
[self stop];
[self onDidPlayToEndTime];
}
}
- (void)handleAVPlayerItemFailedToPlayToEndTime:(NSNotification *)notification {
if (notification.object == _player.currentItem)
{
[self stop];
[self onFailedToPlayToEndTime];
}
}
- (void)handleAVPlayerItemPlaybackStalled:(NSNotification *)notification {
if (notification.object == _player.currentItem)
{
[self pause];
[self.activityIndicatorView startAnimating];
[self onPlaybackStalled];
}
}
I can't pullrequest on this project. don't know why.
Thanks
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels