Browse Source

prevent repeated notifications

(cherry picked from commit 75f6f9f0567dc5d864350c7c58151c900fdf67f3)
Signed-off-by: Felix Paul Kühne <fkuehne@videolan.org>
Tobias Conradi 10 years ago
parent
commit
53c01e7a86
1 changed files with 17 additions and 10 deletions
  1. 17 10
      Sources/VLCPlaybackController.m

+ 17 - 10
Sources/VLCPlaybackController.m

@@ -85,6 +85,23 @@ NSString *const VLCPlaybackControllerPlaybackDidFail = @"VLCPlaybackControllerPl
     [[NSNotificationCenter defaultCenter] removeObserver:self];
 }
 
+- (instancetype)init
+{
+    self = [super init];
+    if (self) {
+        NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];
+        [defaultCenter addObserver:self selector:@selector(audioSessionRouteChange:)
+                              name:AVAudioSessionRouteChangeNotification object:nil];
+        [defaultCenter addObserver:self selector:@selector(applicationWillResignActive:)
+                              name:UIApplicationWillResignActiveNotification object:nil];
+        [defaultCenter addObserver:self selector:@selector(applicationDidBecomeActive:)
+                              name:UIApplicationDidBecomeActiveNotification object:nil];
+        [defaultCenter addObserver:self selector:@selector(applicationDidEnterBackground:)
+                              name:UIApplicationDidEnterBackgroundNotification object:nil];
+    }
+    return self;
+}
+
 #pragma mark - playback management
 
 - (BOOL)_blobCheck
@@ -197,16 +214,6 @@ NSString *const VLCPlaybackControllerPlaybackDidFail = @"VLCPlaybackControllerPl
 
     [[AVAudioSession sharedInstance] setDelegate:self];
 
-    NSNotificationCenter *defaultCenter = [NSNotificationCenter defaultCenter];
-    [defaultCenter addObserver:self selector:@selector(audioSessionRouteChange:)
-                          name:AVAudioSessionRouteChangeNotification object:nil];
-    [defaultCenter addObserver:self selector:@selector(applicationWillResignActive:)
-                          name:UIApplicationWillResignActiveNotification object:nil];
-    [defaultCenter addObserver:self selector:@selector(applicationDidBecomeActive:)
-                          name:UIApplicationDidBecomeActiveNotification object:nil];
-    [defaultCenter addObserver:self selector:@selector(applicationDidEnterBackground:)
-                          name:UIApplicationDidEnterBackgroundNotification object:nil];
-
     NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
 
     _aspectRatios = @[@"DEFAULT", @"FILL_TO_SCREEN", @"4:3", @"16:9", @"16:10", @"2.21:1"];