Commit 4e56ed08 authored by Tobias's avatar Tobias Committed by Felix Paul Kühne

add long-press to play pause button to stop playback

(cherry picked from commit 7a82cd2d)
parent 687fa3a7
B"CHOOSE_AUDIO_TRACK"="Choose Audio Track";
......
......@@ -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
......
......@@ -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;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment