Commit a5bdb95c authored by Felix Paul Kühne's avatar Felix Paul Kühne

playback: replace action sheets for audio / SPU selection with a custom-styled...

playback: replace action sheets for audio / SPU selection with a custom-styled table view, which allows the selection of either track in a single view
parent a7f285d7
......@@ -22,6 +22,8 @@
#import "UIDevice+SpeedCategory.h"
#import "VLCBugreporter.h"
#import "VLCThumbnailsCache.h"
#import "VLCTrackSelectorTableViewCell.h"
#import "VLCTrackSelectorHeaderView.h"
#import "OBSlider.h"
#import "VLCStatusLabel.h"
......@@ -30,7 +32,10 @@
#define FORWARD_SWIPE_DURATION 30
#define BACKWARD_SWIPE_DURATION 10
@interface VLCMovieViewController () <UIGestureRecognizerDelegate, AVAudioSessionDelegate, VLCMediaDelegate>
#define TRACK_SELECTOR_TABLEVIEW_CELL @"track selector table view cell"
#define TRACK_SELECTOR_TABLEVIEW_SECTIONHEADER @"track selector table view section header"
@interface VLCMovieViewController () <UIGestureRecognizerDelegate, AVAudioSessionDelegate, VLCMediaDelegate, UITableViewDataSource, UITableViewDelegate>
{
VLCMediaListPlayer *_listPlayer;
VLCMediaPlayer *_mediaPlayer;
......@@ -63,6 +68,9 @@
UISwipeGestureRecognizer *_swipeRecognizerRight;
UITapGestureRecognizer *_tapRecognizer;
UITapGestureRecognizer *_tapOnVideoRecognizer;
UIView *_trackSelectorContainer;
UITableView *_trackSelectorTableView;
}
@property (nonatomic, strong) UIPopoverController *masterPopoverController;
......@@ -140,6 +148,8 @@
- (void)viewDidLoad
{
[super viewDidLoad];
CGRect rect;
self.wantsFullScreenLayout = YES;
self.videoFilterView.hidden = YES;
......@@ -278,7 +288,7 @@
self.toolbar.tintColor = [UIColor whiteColor];
self.toolbar.barStyle = UIBarStyleBlack;
CGRect rect = self.resetVideoFilterButton.frame;
rect = self.resetVideoFilterButton.frame;
rect.origin.y = rect.origin.y + 5.;
self.resetVideoFilterButton.frame = rect;
rect = self.toolbar.frame;
......@@ -296,7 +306,7 @@
rect.size.width += 19.;
self.positionSlider.frame = rect;
} else {
CGRect rect = self.positionSlider.frame;
rect = self.positionSlider.frame;
rect.origin.y = rect.origin.y + 3.;
self.positionSlider.frame = rect;
[self.aspectRatioButton setBackgroundImage:[UIImage imageNamed:@"ratioButton"] forState:UIControlStateNormal];
......@@ -339,6 +349,28 @@
[self.movieView setAccessibilityLabel:NSLocalizedString(@"VO_VIDEOPLAYER_TITLE", nil)];
[self.movieView setAccessibilityHint:NSLocalizedString(@"VO_VIDEOPLAYER_DOUBLETAP", nil)];
rect = self.view.frame;
_trackSelectorTableView = [[UITableView alloc] initWithFrame:CGRectMake(0., 0., 300., 320.) style:UITableViewStylePlain];
_trackSelectorTableView.delegate = self;
_trackSelectorTableView.dataSource = self;
_trackSelectorTableView.separatorColor = [UIColor VLCDarkBackgroundColor];
_trackSelectorTableView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
[_trackSelectorTableView registerClass:[VLCTrackSelectorTableViewCell class] forCellReuseIdentifier:TRACK_SELECTOR_TABLEVIEW_CELL];
[_trackSelectorTableView registerClass:[VLCTrackSelectorHeaderView class] forHeaderFooterViewReuseIdentifier:TRACK_SELECTOR_TABLEVIEW_SECTIONHEADER];
_trackSelectorContainer = [[VLCFrostedGlasView alloc] initWithFrame:CGRectMake((rect.size.width - 300.) / 2., (rect.size.height - 320.) / 2., 300., 320.)];
[_trackSelectorContainer addSubview:_trackSelectorTableView];
_trackSelectorContainer.hidden = YES;
if ([[UIDevice currentDevice] speedCategory] >= 3) {
_trackSelectorTableView.opaque = NO;
_trackSelectorTableView.backgroundColor = [UIColor clearColor];
} else
_trackSelectorTableView.backgroundColor = [UIColor VLCDarkBackgroundColor];
[self.view addSubview:_trackSelectorContainer];
}
- (BOOL)_blobCheck
......@@ -829,6 +861,8 @@
_videoFilterView.hidden = _videoFiltersHidden;
_playbackSpeedView.alpha = 0.0f;
_playbackSpeedView.hidden = _playbackSpeedViewHidden;
_trackSelectorContainer.alpha = 0.0f;
_trackSelectorContainer.hidden = YES;
}
void (^animationBlock)() = ^() {
......@@ -837,6 +871,7 @@
_toolbar.alpha = alpha;
_videoFilterView.alpha = alpha;
_playbackSpeedView.alpha = alpha;
_trackSelectorContainer.alpha = alpha;
};
void (^completionBlock)(BOOL finished) = ^(BOOL finished) {
......@@ -845,6 +880,7 @@
_toolbar.hidden = _controlsHidden;
_videoFilterView.hidden = _videoFiltersHidden;
_playbackSpeedView.hidden = _playbackSpeedViewHidden;
_trackSelectorContainer.hidden = YES;
};
UIStatusBarAnimation animationType = animated? UIStatusBarAnimationFade: UIStatusBarAnimationNone;
......@@ -1069,67 +1105,135 @@
- (IBAction)switchAudioTrack:(id)sender
{
_audiotrackActionSheet = [[UIActionSheet alloc] initWithTitle:NSLocalizedString(@"CHOOSE_AUDIO_TRACK", @"audio track selector") delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles: nil];
NSArray *audioTracks = [_mediaPlayer audioTrackNames];
NSArray *audioTrackIndexes = [_mediaPlayer audioTrackIndexes];
[_trackSelectorTableView reloadData];
_trackSelectorContainer.hidden = NO;
NSUInteger count = [audioTracks count];
for (NSUInteger i = 0; i < count; i++) {
NSString *indexIndicator = ([audioTrackIndexes[i] intValue] == [_mediaPlayer currentAudioTrackIndex])? @"\u2713": @"";
NSString *buttonTitle = [NSString stringWithFormat:@"%@ %@", indexIndicator, audioTracks[i]];
[_audiotrackActionSheet addButtonWithTitle:buttonTitle];
if (!_playbackSpeedViewHidden)
self.playbackSpeedView.hidden = _playbackSpeedViewHidden = YES;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
if (!_controlsHidden) {
self.controllerPanel.hidden = _controlsHidden = YES;
self.controllerPanelLandscape.hidden = YES;
}
}
[_audiotrackActionSheet addButtonWithTitle:NSLocalizedString(@"BUTTON_CANCEL", @"cancel button")];
[_audiotrackActionSheet setCancelButtonIndex:[_audiotrackActionSheet numberOfButtons] - 1];
[_audiotrackActionSheet showInView:(UIButton *)sender];
self.videoFilterView.hidden = _videoFiltersHidden = YES;
}
- (IBAction)switchSubtitleTrack:(id)sender
{
NSArray *spuTracks = [_mediaPlayer videoSubTitlesNames];
NSArray *spuTrackIndexes = [_mediaPlayer videoSubTitlesIndexes];
[self switchAudioTrack:sender];
}
NSUInteger count = [spuTracks count];
if (count <= 1)
return;
_subtitleActionSheet = [[UIActionSheet alloc] initWithTitle:NSLocalizedString(@"CHOOSE_SUBTITLE_TRACK", @"subtitle track selector") delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles: nil];
- (IBAction)toggleTimeDisplay:(id)sender
{
_displayRemainingTime = !_displayRemainingTime;
for (NSUInteger i = 0; i < count; i++) {
NSString *indexIndicator = ([spuTrackIndexes[i] intValue] == [_mediaPlayer currentVideoSubTitleIndex])? @"\u2713": @"";
NSString *buttonTitle = [NSString stringWithFormat:@"%@ %@", indexIndicator, spuTracks[i]];
[_subtitleActionSheet addButtonWithTitle:buttonTitle];
}
[self _resetIdleTimer];
}
#pragma mark - track selector table view
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
NSInteger ret = 0;
if (_mediaPlayer.audioTrackIndexes.count > 2)
ret++;
[_subtitleActionSheet addButtonWithTitle:NSLocalizedString(@"BUTTON_CANCEL", @"cancel button")];
[_subtitleActionSheet setCancelButtonIndex:[_subtitleActionSheet numberOfButtons] - 1];
[_subtitleActionSheet showInView:(UIButton *)sender];
if (_mediaPlayer.videoSubTitlesIndexes.count > 1)
ret++;
return ret;
}
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
if (buttonIndex == [actionSheet cancelButtonIndex])
return;
UITableViewHeaderFooterView *view = [tableView dequeueReusableHeaderFooterViewWithIdentifier:TRACK_SELECTOR_TABLEVIEW_SECTIONHEADER];
if (!view)
view = [[VLCTrackSelectorHeaderView alloc] initWithReuseIdentifier:TRACK_SELECTOR_TABLEVIEW_SECTIONHEADER];
return view;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
if (_mediaPlayer.audioTrackIndexes.count > 2 && section == 0)
return NSLocalizedString(@"CHOOSE_AUDIO_TRACK", nil);
if (_mediaPlayer.videoSubTitlesIndexes.count > 1)
return NSLocalizedString(@"CHOOSE_SUBTITLE_TRACK", nil);
return @"unknown track type";
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:TRACK_SELECTOR_TABLEVIEW_CELL forIndexPath:indexPath];
if (!cell)
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:TRACK_SELECTOR_TABLEVIEW_CELL];
NSString *itemSelectionIndicator = @"";
NSArray *indexArray;
if (actionSheet == _subtitleActionSheet) {
indexArray = _mediaPlayer.videoSubTitlesIndexes;
if (buttonIndex <= indexArray.count) {
_mediaPlayer.currentVideoSubTitleIndex = [indexArray[buttonIndex] intValue];
}
} else if (actionSheet == _audiotrackActionSheet) {
if (_mediaPlayer.audioTrackIndexes.count > 2 && indexPath.section == 0) {
indexArray = _mediaPlayer.audioTrackIndexes;
if (buttonIndex <= indexArray.count) {
_mediaPlayer.currentAudioTrackIndex = [indexArray[buttonIndex] intValue];
}
if ([indexArray indexOfObjectIdenticalTo:[NSNumber numberWithInt:_mediaPlayer.currentAudioTrackIndex]] == indexPath.row)
itemSelectionIndicator = @"\u2713";
cell.textLabel.text = [NSString stringWithFormat:@"%@%@", itemSelectionIndicator, _mediaPlayer.audioTrackNames[indexPath.row]];
} else {
indexArray = _mediaPlayer.videoSubTitlesIndexes;
if ([indexArray indexOfObjectIdenticalTo:[NSNumber numberWithInt:_mediaPlayer.currentVideoSubTitleIndex]] == indexPath.row)
itemSelectionIndicator = @"\u2713";
cell.textLabel.text = [NSString stringWithFormat:@"%@%@", itemSelectionIndicator, _mediaPlayer.videoSubTitlesNames[indexPath.row]];
}
return cell;
}
- (IBAction)toggleTimeDisplay:(id)sender
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
_displayRemainingTime = !_displayRemainingTime;
NSInteger audioTrackCount = _mediaPlayer.audioTrackIndexes.count;
[self _resetIdleTimer];
if (audioTrackCount > 2 && section == 0)
return audioTrackCount;
return _mediaPlayer.videoSubTitlesIndexes.count;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:NO];
NSInteger index = indexPath.row;
NSArray *indexArray;
if (_mediaPlayer.audioTrackIndexes.count > 2 && indexPath.section == 0) {
indexArray = _mediaPlayer.audioTrackIndexes;
if (index <= indexArray.count)
_mediaPlayer.currentAudioTrackIndex = [indexArray[index] intValue];
} else {
indexArray = _mediaPlayer.videoSubTitlesIndexes;
if (index <= indexArray.count)
_mediaPlayer.currentVideoSubTitleIndex = [indexArray[index] intValue];
}
CGFloat alpha = 0.0f;
_trackSelectorContainer.alpha = 1.0f;
void (^animationBlock)() = ^() {
_trackSelectorContainer.alpha = alpha;
};
void (^completionBlock)(BOOL finished) = ^(BOOL finished) {
_trackSelectorContainer.hidden = YES;
};
NSTimeInterval animationDuration = .3;
[UIView animateWithDuration:animationDuration animations:animationBlock completion:completionBlock];
}
#pragma mark - multi-touch gestures
......
/*****************************************************************************
* VLCTrackSelectorHeaderView.h
* VLC for iOS
*****************************************************************************
* Copyright (c) 2014 VideoLAN. All rights reserved.
* $Id$
*
* Authors: Felix Paul Kühne <fkuehne # videolan.org>
*
* Refer to the COPYING file of the official project for license.
*****************************************************************************/
#import <UIKit/UIKit.h>
@interface VLCTrackSelectorHeaderView : UITableViewHeaderFooterView
@end
/*****************************************************************************
* VLCTrackSelectorHeaderView.m
* VLC for iOS
*****************************************************************************
* Copyright (c) 2014 VideoLAN. All rights reserved.
* $Id$
*
* Authors: Felix Paul Kühne <fkuehne # videolan.org>
*
* Refer to the COPYING file of the official project for license.
*****************************************************************************/
#import "VLCTrackSelectorHeaderView.h"
#import "UIDevice+SpeedCategory.h"
@implementation VLCTrackSelectorHeaderView
- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithReuseIdentifier:reuseIdentifier];
if (!self)
return self;
self.contentView.backgroundColor = [UIColor VLCDarkBackgroundColor];
self.textLabel.textColor = [UIColor whiteColor];
if ([[UIDevice currentDevice] speedCategory] >= 3) {
self.opaque = NO;
self.alpha = .8;
}
return self;
}
@end
/*****************************************************************************
* VLCTrackSelectorTableViewCell.h
* VLC for iOS
*****************************************************************************
* Copyright (c) 2014 VideoLAN. All rights reserved.
* $Id$
*
* Authors: Felix Paul Kühne <fkuehne # videolan.org>
*
* Refer to the COPYING file of the official project for license.
*****************************************************************************/
#import <UIKit/UIKit.h>
@interface VLCTrackSelectorTableViewCell : UITableViewCell
@end
/*****************************************************************************
* VLCTrackSelectorTableViewCell.m
* VLC for iOS
*****************************************************************************
* Copyright (c) 2014 VideoLAN. All rights reserved.
* $Id$
*
* Authors: Felix Paul Kühne <fkuehne # videolan.org>
*
* Refer to the COPYING file of the official project for license.
*****************************************************************************/
#import "VLCTrackSelectorTableViewCell.h"
@implementation VLCTrackSelectorTableViewCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (!self)
return self;
self.backgroundColor = [UIColor clearColor];
self.textLabel.textColor = [UIColor VLCLightTextColor];
return self;
}
@end
......@@ -242,6 +242,8 @@
7D514D4417F779C6007B960C /* Drive.png in Resources */ = {isa = PBXBuildFile; fileRef = 7D514D4017F779C6007B960C /* Drive.png */; };
7D588D64187DD9B700469FCF /* modernSliderKnob@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 7D588D62187DD9B700469FCF /* modernSliderKnob@2x.png */; };
7D588D65187DD9B700469FCF /* modernSliderKnob.png in Resources */ = {isa = PBXBuildFile; fileRef = 7D588D63187DD9B700469FCF /* modernSliderKnob.png */; };
7D5CAA891A4AD763003F2CBC /* VLCTrackSelectorTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D5CAA881A4AD763003F2CBC /* VLCTrackSelectorTableViewCell.m */; };
7D5CAA8C1A4AD8E5003F2CBC /* VLCTrackSelectorHeaderView.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D5CAA8B1A4AD8E5003F2CBC /* VLCTrackSelectorHeaderView.m */; };
7D5DD5C717590ABF001421E3 /* About Contents.html in Resources */ = {isa = PBXBuildFile; fileRef = 7D5DD5C617590ABF001421E3 /* About Contents.html */; };
7D5E39CA174FC2F3007DAFA1 /* dropbox-white.png in Resources */ = {isa = PBXBuildFile; fileRef = 7D5E39C8174FC2F3007DAFA1 /* dropbox-white.png */; };
7D5E39CB174FC2F3007DAFA1 /* dropbox-white@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 7D5E39C9174FC2F3007DAFA1 /* dropbox-white@2x.png */; };
......@@ -882,6 +884,10 @@
7D5C204B17999A64004F9443 /* da */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = da; path = "da.lproj/badgeUnread~ipad.png"; sourceTree = "<group>"; };
7D5C204C17999A64004F9443 /* da */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = da; path = "da.lproj/badgeUnread~iphone.png"; sourceTree = "<group>"; };
7D5C204D17999A74004F9443 /* da */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = da; path = da.lproj/Localizable.strings; sourceTree = "<group>"; };
7D5CAA871A4AD763003F2CBC /* VLCTrackSelectorTableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = VLCTrackSelectorTableViewCell.h; path = Sources/VLCTrackSelectorTableViewCell.h; sourceTree = SOURCE_ROOT; };
7D5CAA881A4AD763003F2CBC /* VLCTrackSelectorTableViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = VLCTrackSelectorTableViewCell.m; path = Sources/VLCTrackSelectorTableViewCell.m; sourceTree = SOURCE_ROOT; };
7D5CAA8A1A4AD8E5003F2CBC /* VLCTrackSelectorHeaderView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = VLCTrackSelectorHeaderView.h; path = Sources/VLCTrackSelectorHeaderView.h; sourceTree = SOURCE_ROOT; };
7D5CAA8B1A4AD8E5003F2CBC /* VLCTrackSelectorHeaderView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = VLCTrackSelectorHeaderView.m; path = Sources/VLCTrackSelectorHeaderView.m; sourceTree = SOURCE_ROOT; };
7D5DD5C617590ABF001421E3 /* About Contents.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "About Contents.html"; sourceTree = "<group>"; };
7D5E39C8174FC2F3007DAFA1 /* dropbox-white.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "dropbox-white.png"; sourceTree = "<group>"; };
7D5E39C9174FC2F3007DAFA1 /* dropbox-white@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "dropbox-white@2x.png"; sourceTree = "<group>"; };
......@@ -1864,6 +1870,10 @@
7D37848E183A98B6009EE944 /* VLCMovieViewController.m */,
7D378490183A98BF009EE944 /* VLCExternalDisplayController.h */,
7D378491183A98BF009EE944 /* VLCExternalDisplayController.m */,
7D5CAA871A4AD763003F2CBC /* VLCTrackSelectorTableViewCell.h */,
7D5CAA881A4AD763003F2CBC /* VLCTrackSelectorTableViewCell.m */,
7D5CAA8A1A4AD8E5003F2CBC /* VLCTrackSelectorHeaderView.h */,
7D5CAA8B1A4AD8E5003F2CBC /* VLCTrackSelectorHeaderView.m */,
);
name = Playback;
sourceTree = "<group>";
......@@ -3082,6 +3092,7 @@
9B5BEF2917FBAEA50016F9CB /* GTLDrive_Sources.m in Sources */,
7DC19ADF1868C7BB00810BF7 /* VLCFirstStepsViewController.m in Sources */,
7DC72D6317B7ED24008A26D0 /* WhiteRaccoon.m in Sources */,
7D5CAA891A4AD763003F2CBC /* VLCTrackSelectorTableViewCell.m in Sources */,
7D63C19018774B1700BD5256 /* VLCFirstStepsSecondPageViewController.m in Sources */,
8F91EC79195CEC7900F5BCBA /* VLCOpenInActivity.m in Sources */,
7D37848F183A98B6009EE944 /* VLCMovieViewController.m in Sources */,
......@@ -3113,6 +3124,7 @@
7D30F3C3183AB24C00FFC021 /* VLCHTTPFileDownloader.m in Sources */,
7D30F3C4183AB24C00FFC021 /* VLCHTTPUploaderController.m in Sources */,
7D30F3C7183AB26F00FFC021 /* VLCOpenNetworkStreamViewController.m in Sources */,
7D5CAA8C1A4AD8E5003F2CBC /* VLCTrackSelectorHeaderView.m in Sources */,
4171D35018A2C19000A16EF9 /* VLCFolderCollectionViewFlowLayout.m in Sources */,
7D30F3CA183AB27A00FFC021 /* VLCDownloadViewController.m in Sources */,
7D30F3CD183AB29300FFC021 /* VLCMenuTableViewController.m in Sources */,
......
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