浏览代码

add long-press to play pause button to stop playback

(cherry picked from commit 7a82cd2d747211f7588a698215e46f55eea8df98)
Tobias Conradi 10 年之前
父节点
当前提交
4e56ed085b
共有 3 个文件被更改,包括 69 次插入9 次删除
  1. 二进制
      Resources/en.lproj/Localizable.strings
  2. 33 6
      Sources/VLCMiniPlaybackView.m
  3. 36 3
      Sources/VLCMovieViewController.m

二进制
Resources/en.lproj/Localizable.strings


+ 33 - 6
Sources/VLCMiniPlaybackView.m

@@ -67,7 +67,12 @@
     [_playPauseButton sizeToFit];
     _playPauseButton.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
     [_playPauseButton addTarget:self action:@selector(playPauseAction:) forControlEvents:UIControlEventTouchUpInside];
+    _playPauseButton.accessibilityLabel = NSLocalizedString(@"PLAY_PAUSE_BUTTON", nil);
+    _playPauseButton.accessibilityHint = NSLocalizedString(@"LONGPRESS_TO_STOP", nil);
+    _playPauseButton.isAccessibilityElement = YES;
     _playPauseButton.frame = previousRect = CGRectMake(previousRect.origin.x - buttonSize, (viewFrame.size.height - buttonSize) / 2., buttonSize, buttonSize);
+    UILongPressGestureRecognizer *longPressRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(playPauseLongPress:)];
+    [_playPauseButton addGestureRecognizer:longPressRecognizer];
     [self addSubview:_playPauseButton];
 
     _previousButton = [UIButton buttonWithType:UIButtonTypeCustom];
@@ -99,6 +104,24 @@
     [self.playbackController playPause];
 }
 
+- (void)playPauseLongPress:(UILongPressGestureRecognizer *)recognizer
+{
+    switch (recognizer.state) {
+        case UIGestureRecognizerStateBegan:
+            [_playPauseButton setImage:[UIImage imageNamed:@"stopIcon"] forState:UIControlStateNormal];
+            break;
+        case UIGestureRecognizerStateEnded:
+            [self.playbackController stopPlayback];
+            break;
+        case UIGestureRecognizerStateCancelled:
+        case UIGestureRecognizerStateFailed:
+            [self updatePlayPauseButton];
+            break;
+        default:
+            break;
+    }
+}
+
 - (void)nextAction:(id)sender
 {
     [self.playbackController forward];
@@ -109,13 +132,18 @@
     [[UIApplication sharedApplication] sendAction:@selector(showFullscreenPlayback) to:nil from:self forEvent:nil];
 }
 
+
+- (void)updatePlayPauseButton
+{
+    const BOOL isPlaying = self.playbackController.isPlaying;
+    UIImage *playPauseImage = isPlaying ? [UIImage imageNamed:@"pauseIcon"] : [UIImage imageNamed:@"playIcon"];
+    [_playPauseButton setImage:playPauseImage forState:UIControlStateNormal];
+}
+
 - (void)setupForWork:(VLCPlaybackController *)playbackController
 {
     self.playbackController = playbackController;
-    if (playbackController.isPlaying)
-        [_playPauseButton setImage:[UIImage imageNamed:@"pauseIcon"] forState:UIControlStateNormal];
-    else
-        [_playPauseButton setImage:[UIImage imageNamed:@"playIcon"] forState:UIControlStateNormal];
+    [self updatePlayPauseButton];
     playbackController.delegate = self;
     [playbackController recoverDisplayedMetadata];
 }
@@ -126,8 +154,7 @@ currentMediaHasTrackToChooseFrom:(BOOL)currentMediaHasTrackToChooseFrom
         currentMediaHasChapters:(BOOL)currentMediaHasChapters
           forPlaybackController:(VLCPlaybackController *)controller
 {
-    UIImage *playPauseImage = isPlaying ? [UIImage imageNamed:@"pauseIcon"] : [UIImage imageNamed:@"playIcon"];
-    [_playPauseButton setImage:playPauseImage forState:UIControlStateNormal];
+    [self updatePlayPauseButton];
 }
 
 - (void)displayMetadataForPlaybackController:(VLCPlaybackController *)controller

+ 36 - 3
Sources/VLCMovieViewController.m

@@ -185,9 +185,15 @@ typedef NS_ENUM(NSInteger, VLCPanType) {
     _videoFilterButtonLandscape.isAccessibilityElement = YES;
     _resetVideoFilterButton.accessibilityLabel = NSLocalizedString(@"VIDEO_FILTER_RESET_BUTTON", nil);
     _resetVideoFilterButton.isAccessibilityElement = YES;
+    UILongPressGestureRecognizer *longPressRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(playPauseLongPress:)];
+    [_playPauseButton addGestureRecognizer:longPressRecognizer];
     _playPauseButton.accessibilityLabel = NSLocalizedString(@"PLAY_PAUSE_BUTTON", nil);
+    _playPauseButton.accessibilityHint = NSLocalizedString(@"LONGPRESS_TO_STOP", nil);
     _playPauseButton.isAccessibilityElement = YES;
+    UILongPressGestureRecognizer *longPressRecognizerLandscape = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(playPauseLongPress:)];
+    [_playPauseButton addGestureRecognizer:longPressRecognizerLandscape];
     _playPauseButtonLandscape.accessibilityLabel = NSLocalizedString(@"PLAY_PAUSE_BUTTON", nil);
+    _playPauseButtonLandscape.accessibilityHint = NSLocalizedString(@"LONGPRESS_TO_STOP", nil);
     _playPauseButtonLandscape.isAccessibilityElement = YES;
     _bwdButton.accessibilityLabel = NSLocalizedString(@"BWD_BUTTON", nil);
     _bwdButton.isAccessibilityElement = YES;
@@ -763,6 +769,35 @@ typedef NS_ENUM(NSInteger, VLCPanType) {
     [self _resetIdleTimer];
 }
 
+- (void)playPauseLongPress:(UILongPressGestureRecognizer *)recognizer
+{
+    switch (recognizer.state) {
+        case UIGestureRecognizerStateBegan:
+        {   UIImage *image = [UIImage imageNamed:@"stopIcon"];
+            [_playPauseButton setImage:image forState:UIControlStateNormal];
+            [_playPauseButtonLandscape setImage:image forState:UIControlStateNormal];
+        }
+            break;
+        case UIGestureRecognizerStateEnded:
+            [self.playbackController stopPlayback];
+            break;
+        case UIGestureRecognizerStateCancelled:
+        case UIGestureRecognizerStateFailed:
+            [self updatePlayPauseButton];
+            break;
+        default:
+            break;
+    }
+}
+
+- (void)updatePlayPauseButton
+{
+    const BOOL isPlaying = self.playbackController.isPlaying;
+    UIImage *playPauseImage = isPlaying ? [UIImage imageNamed:@"pauseIcon"] : [UIImage imageNamed:@"playIcon"];
+    [_playPauseButton setImage:playPauseImage forState:UIControlStateNormal];
+    [_playPauseButtonLandscape setImage:playPauseImage forState:UIControlStateNormal];
+}
+
 #pragma mark - playback controller delegation
 
 - (VLCPlaybackController *)playbackController
@@ -829,9 +864,7 @@ currentMediaHasTrackToChooseFrom:(BOOL)currentMediaHasTrackToChooseFrom
     if (currentState == VLCMediaPlayerStateError)
         [self.statusLabel showStatusMessage:NSLocalizedString(@"PLAYBACK_FAILED", nil)];
 
-    UIImage *playPauseImage = isPlaying ? [UIImage imageNamed:@"pauseIcon"] : [UIImage imageNamed:@"playIcon"];
-    [_playPauseButton setImage:playPauseImage forState:UIControlStateNormal];
-    [_playPauseButtonLandscape setImage:playPauseImage forState:UIControlStateNormal];
+    [self updatePlayPauseButton];
 
     if (currentMediaHasTrackToChooseFrom) {
         self.trackSwitcherButton.hidden = NO;