From 471f02daa722854a63ff5ac29aee2e451d3f4f40 Mon Sep 17 00:00:00 2001 From: Phil Larson Date: Tue, 2 May 2017 13:13:16 -0700 Subject: [PATCH] Automatically resume ASVideoNode after returning from background (#13) --- Source/ASVideoNode.mm | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Source/ASVideoNode.mm b/Source/ASVideoNode.mm index 53c36faf0a..a8d0150450 100644 --- a/Source/ASVideoNode.mm +++ b/Source/ASVideoNode.mm @@ -108,6 +108,9 @@ static NSString * const kRate = @"rate"; [self addTarget:self action:@selector(tapped) forControlEvents:ASControlNodeEventTouchUpInside]; _lastPlaybackTime = kCMTimeZero; + NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter]; + [notificationCenter addObserver:self selector:@selector(applicationDidBecomeActive:) name:UIApplicationDidBecomeActiveNotification object:nil]; + return self; } @@ -714,6 +717,13 @@ static NSString * const kRate = @"rate"; #pragma mark - Playback observers +- (void)applicationDidBecomeActive:(NSNotification *)notification +{ + if (self.shouldBePlaying && self.isVisible) { + [self play]; + } +} + - (void)didPlayToEnd:(NSNotification *)notification { self.playerState = ASVideoNodePlayerStateFinished; @@ -825,6 +835,9 @@ static NSString * const kRate = @"rate"; _timeObserver = nil; [self removePlayerItemObservers:_currentPlayerItem]; [self removePlayerObservers:_player]; + + NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter]; + [notificationCenter removeObserver:self name:UIApplicationDidBecomeActiveNotification object:nil]; } @end