Browse Source

playback: pause playback when headphones get unplugged

Carola Nitz 11 years ago
parent
commit
5fa6b85742
1 changed files with 11 additions and 0 deletions
  1. 11 0
      Sources/VLCMovieViewController.m

+ 11 - 0
Sources/VLCMovieViewController.m

@@ -218,6 +218,8 @@
                    name:UIApplicationDidBecomeActiveNotification object:nil];
                    name:UIApplicationDidBecomeActiveNotification object:nil];
     [center addObserver:self selector:@selector(applicationDidEnterBackground:)
     [center addObserver:self selector:@selector(applicationDidEnterBackground:)
                    name:UIApplicationDidEnterBackgroundNotification object:nil];
                    name:UIApplicationDidEnterBackgroundNotification object:nil];
+    [center addObserver:self selector:@selector(audioSessionRouteChange:)
+                   name:AVAudioSessionRouteChangeNotification object:nil];
 
 
     _playingExternallyTitle.text = NSLocalizedString(@"PLAYING_EXTERNALLY_TITLE", @"");
     _playingExternallyTitle.text = NSLocalizedString(@"PLAYING_EXTERNALLY_TITLE", @"");
     _playingExternallyDescription.text = NSLocalizedString(@"PLAYING_EXTERNALLY_DESC", @"");
     _playingExternallyDescription.text = NSLocalizedString(@"PLAYING_EXTERNALLY_DESC", @"");
@@ -1377,6 +1379,15 @@
     }
     }
 }
 }
 
 
+- (void)audioSessionRouteChange:(NSNotification *)notification
+{
+    NSArray *outputs = [[AVAudioSession sharedInstance] currentRoute].outputs;
+    NSString *portName = [[outputs objectAtIndex:0] portName];
+
+    if (![portName isEqualToString:@"Headphones"])
+        [_listPlayer pause];
+}
+
 - (void)mediaDidFinishParsing:(VLCMedia *)aMedia
 - (void)mediaDidFinishParsing:(VLCMedia *)aMedia
 {
 {
     [self _updateDisplayedMetadata];
     [self _updateDisplayedMetadata];