Commit 7a82cd2d authored by Tobias's avatar Tobias

add long-press to play pause button to stop playback

parent a8b1544f
......@@ -244,4 +244,6 @@
"OBJECT_TYPE_ALBUM"="Album";
"OBJECT_TYPE_ALBUM_TRACK"="Album track";
"OBJECT_TYPE_FILE"="File";
"OBJECT_TYPE_FILE_AUDIO"="Audio file";
\ No newline at end of file
"OBJECT_TYPE_FILE_AUDIO"="Audio file";
"LONGPRESS_TO_STOP"="Long-press to stop playback."
......@@ -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
......
......@@ -176,9 +176,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;
......@@ -740,6 +746,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
......@@ -806,9 +841,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