VLCMovieViewController.m 61 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663
  1. /*****************************************************************************
  2. * VLCMovieViewController.m
  3. * VLC for iOS
  4. *****************************************************************************
  5. * Copyright (c) 2013-2017 VideoLAN. All rights reserved.
  6. * $Id$
  7. *
  8. * Authors: Felix Paul Kühne <fkuehne # videolan.org>
  9. * Gleb Pinigin <gpinigin # gmail.com>
  10. * Carola Nitz <caro # videolan.org>
  11. * Tobias Conradi <videolan # tobias-conradi.de>
  12. * Ahmad Harb <harb.dev.leb # gmail.com>
  13. * Fabio Ritrovato <sephiroth87 # videolan.org>
  14. * Pierre SAGASPE <pierre.sagaspe # me.com>
  15. * Filipe Cabecinhas <vlc # filcab dot net>
  16. * Marc Etcheverry <marc # taplightsoftware dot com>
  17. * Christopher Loessl <cloessl # x-berg dot de>
  18. * Sylver Bruneau <sylver.bruneau # gmail dot com>
  19. *
  20. * Refer to the COPYING file of the official project for license.
  21. *****************************************************************************/
  22. #import "VLCMovieViewController.h"
  23. #import "VLCExternalDisplayController.h"
  24. #import "VLCEqualizerView.h"
  25. #import "VLCMultiSelectionMenuView.h"
  26. #import "VLCPlaybackController.h"
  27. #import "UIDevice+VLC.h"
  28. #import "VLCTimeNavigationTitleView.h"
  29. #import "VLCPlayerDisplayController.h"
  30. #import "VLCAppDelegate.h"
  31. #import "VLCStatusLabel.h"
  32. #import "VLCMovieViewControlPanelView.h"
  33. #import "VLCSlider.h"
  34. #import "VLCLibraryViewController.h"
  35. #import "VLCTrackSelectorView.h"
  36. #import "VLCMetadata.h"
  37. #import "UIDevice+VLC.h"
  38. #define FORWARD_SWIPE_DURATION 30
  39. #define BACKWARD_SWIPE_DURATION 10
  40. #define SHORT_JUMP_DURATION 10
  41. #define ZOOM_SENSITIVITY 2.99f
  42. #define DEFAULT_FOV 80.f
  43. #define MAX_FOV 150.f
  44. #define MIN_FOV 20.f
  45. #define LOCKCHECK \
  46. if (_interfaceIsLocked) \
  47. return
  48. typedef NS_ENUM(NSInteger, VLCPanType) {
  49. VLCPanTypeNone,
  50. VLCPanTypeBrightness,
  51. VLCPanTypeSeek,
  52. VLCPanTypeVolume,
  53. VLCPanTypeProjection
  54. };
  55. @interface VLCMovieViewController () <UIGestureRecognizerDelegate, VLCMultiSelectionViewDelegate, VLCEqualizerViewUIDelegate>
  56. {
  57. BOOL _controlsHidden;
  58. BOOL _videoFiltersHidden;
  59. BOOL _playbackSpeedViewHidden;
  60. UIActionSheet *_subtitleActionSheet;
  61. UIActionSheet *_audiotrackActionSheet;
  62. NSTimer *_idleTimer;
  63. BOOL _viewAppeared;
  64. BOOL _displayRemainingTime;
  65. BOOL _positionSet;
  66. BOOL _isScrubbing;
  67. BOOL _interfaceIsLocked;
  68. BOOL _audioOnly;
  69. BOOL _volumeGestureEnabled;
  70. BOOL _playPauseGestureEnabled;
  71. BOOL _brightnessGestureEnabled;
  72. BOOL _seekGestureEnabled;
  73. BOOL _closeGestureEnabled;
  74. BOOL _variableJumpDurationEnabled;
  75. BOOL _mediaHasProjection;
  76. BOOL _playbackWillClose;
  77. BOOL _isTapSeeking;
  78. VLCMovieJumpState _previousJumpState;
  79. UIPinchGestureRecognizer *_pinchRecognizer;
  80. VLCPanType _currentPanType;
  81. UIPanGestureRecognizer *_panRecognizer;
  82. UISwipeGestureRecognizer *_swipeRecognizerLeft;
  83. UISwipeGestureRecognizer *_swipeRecognizerRight;
  84. UISwipeGestureRecognizer *_swipeRecognizerUp;
  85. UISwipeGestureRecognizer *_swipeRecognizerDown;
  86. UITapGestureRecognizer *_tapRecognizer;
  87. UITapGestureRecognizer *_tapOnVideoRecognizer;
  88. UITapGestureRecognizer *_tapToToggleiPhoneXRatioRecognizer;
  89. UITapGestureRecognizer *_tapToSeekRecognizer;
  90. VLCTrackSelectorView *_trackSelectorContainer;
  91. VLCEqualizerView *_equalizerView;
  92. VLCMultiSelectionMenuView *_multiSelectionView;
  93. VLCPlaybackController *_vpc;
  94. UIView *_sleepTimerContainer;
  95. UIDatePicker *_sleepTimeDatePicker;
  96. NSTimer *_sleepCountDownTimer;
  97. NSInteger _mediaDuration;
  98. NSInteger _numberOfTapSeek;
  99. CGFloat _fov;
  100. CGPoint _saveLocation;
  101. CGSize _screenSizePixel;
  102. }
  103. @property (nonatomic, strong) VLCMovieViewControlPanelView *controllerPanel;
  104. @property (nonatomic, strong) UIPopoverController *masterPopoverController;
  105. @property (nonatomic, strong) UIWindow *externalWindow;
  106. @end
  107. @implementation VLCMovieViewController
  108. + (void)initialize
  109. {
  110. NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
  111. NSDictionary *appDefaults = @{kVLCShowRemainingTime : @(YES)};
  112. [defaults registerDefaults:appDefaults];
  113. }
  114. - (void)dealloc
  115. {
  116. [[NSNotificationCenter defaultCenter] removeObserver:self];
  117. }
  118. - (void)viewDidLoad
  119. {
  120. [super viewDidLoad];
  121. CGRect rect;
  122. _vpc = [VLCPlaybackController sharedInstance];
  123. self.extendedLayoutIncludesOpaqueBars = YES;
  124. self.edgesForExtendedLayout = UIRectEdgeAll;
  125. self.videoFilterView.hidden = YES;
  126. _videoFiltersHidden = YES;
  127. _hueLabel.text = NSLocalizedString(@"VFILTER_HUE", nil);
  128. _hueSlider.accessibilityLabel = _hueLabel.text;
  129. _contrastLabel.text = NSLocalizedString(@"VFILTER_CONTRAST", nil);
  130. _contrastSlider.accessibilityLabel = _contrastLabel.text;
  131. _brightnessLabel.text = NSLocalizedString(@"VFILTER_BRIGHTNESS", nil);
  132. _brightnessSlider.accessibilityLabel = _brightnessLabel.text;
  133. _saturationLabel.text = NSLocalizedString(@"VFILTER_SATURATION", nil);
  134. _saturationSlider.accessibilityLabel = _saturationLabel.text;
  135. _gammaLabel.text = NSLocalizedString(@"VFILTER_GAMMA", nil);
  136. _gammaSlider.accessibilityLabel = _gammaLabel.text;
  137. _playbackSpeedLabel.text = NSLocalizedString(@"PLAYBACK_SPEED", nil);
  138. _playbackSpeedSlider.accessibilityLabel = _playbackSpeedLabel.text;
  139. _audioDelayLabel.text = NSLocalizedString(@"AUDIO_DELAY", nil);
  140. _audioDelaySlider.accessibilityLabel = _audioDelayLabel.text;
  141. _spuDelayLabel.text = NSLocalizedString(@"SPU_DELAY", nil);
  142. _spuDelaySlider.accessibilityLabel = _spuDelayLabel.text;
  143. _resetVideoFilterButton.accessibilityLabel = NSLocalizedString(@"VIDEO_FILTER_RESET_BUTTON", nil);
  144. _sleepTimerButton.accessibilityLabel = NSLocalizedString(@"BUTTON_SLEEP_TIMER", nil);
  145. [_sleepTimerButton setTitle:NSLocalizedString(@"BUTTON_SLEEP_TIMER", nil) forState:UIControlStateNormal];
  146. _multiSelectionView = [[VLCMultiSelectionMenuView alloc] init];
  147. _multiSelectionView.delegate = self;
  148. _multiSelectionView.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin;
  149. _multiSelectionView.hidden = YES;
  150. [self.view addSubview:_multiSelectionView];
  151. _scrubHelpLabel.text = NSLocalizedString(@"PLAYBACK_SCRUB_HELP", nil);
  152. self.playbackSpeedView.hidden = YES;
  153. _playbackSpeedViewHidden = YES;
  154. NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
  155. [center addObserver:self selector:@selector(handleExternalScreenDidConnect:)
  156. name:UIScreenDidConnectNotification object:nil];
  157. [center addObserver:self selector:@selector(handleExternalScreenDidDisconnect:)
  158. name:UIScreenDidDisconnectNotification object:nil];
  159. [center addObserver:self
  160. selector:@selector(appBecameActive:)
  161. name:UIApplicationDidBecomeActiveNotification
  162. object:nil];
  163. [center addObserver:self
  164. selector:@selector(playbackDidStop:)
  165. name:VLCPlaybackControllerPlaybackDidStop
  166. object:nil];
  167. _playingExternallyTitle.text = NSLocalizedString(@"PLAYING_EXTERNALLY_TITLE", nil);
  168. _playingExternallyDescription.text = NSLocalizedString(@"PLAYING_EXTERNALLY_DESC", nil);
  169. if ([[UIDevice currentDevice] VLCHasExternalDisplay])
  170. [self showOnExternalDisplay];
  171. self.trackNameLabel.text = self.artistNameLabel.text = self.albumNameLabel.text = @"";
  172. _movieView.userInteractionEnabled = NO;
  173. [self setupGestureRecognizers];
  174. _isTapSeeking = NO;
  175. _previousJumpState = VLCMovieJumpStateDefault;
  176. _numberOfTapSeek = 0;
  177. rect = self.resetVideoFilterButton.frame;
  178. rect.origin.y = rect.origin.y + 5.;
  179. self.resetVideoFilterButton.frame = rect;
  180. [self.movieView setAccessibilityLabel:NSLocalizedString(@"VO_VIDEOPLAYER_TITLE", nil)];
  181. [self.movieView setAccessibilityHint:NSLocalizedString(@"VO_VIDEOPLAYER_DOUBLETAP", nil)];
  182. _trackSelectorContainer = [[VLCTrackSelectorView alloc] initWithFrame:CGRectZero];
  183. _trackSelectorContainer.hidden = YES;
  184. void (^completionBlock)(BOOL finished) = ^(BOOL finished) {
  185. for (UIGestureRecognizer *recognizer in self.view.gestureRecognizers)
  186. [recognizer setEnabled:YES];
  187. _trackSelectorContainer.hidden = YES;
  188. };
  189. _trackSelectorContainer.completionHandler = completionBlock;
  190. _trackSelectorContainer.translatesAutoresizingMaskIntoConstraints = NO;
  191. [self.view addSubview:_trackSelectorContainer];
  192. _equalizerView = [[VLCEqualizerView alloc] initWithFrame:CGRectMake(0, 0, 450., 240.)];
  193. _equalizerView.delegate = [VLCPlaybackController sharedInstance];
  194. _equalizerView.UIdelegate = self;
  195. _equalizerView.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleTopMargin;
  196. _equalizerView.hidden = YES;
  197. [self.view addSubview:_equalizerView];
  198. //Sleep Timer initialization
  199. [self sleepTimerInitializer];
  200. [self setupControlPanel];
  201. CGRect screenBounds = [[UIScreen mainScreen] bounds];
  202. CGFloat screenScale = [[UIScreen mainScreen] scale];
  203. _screenSizePixel = CGSizeMake(screenBounds.size.width * screenScale, screenBounds.size.height * screenScale);
  204. _saveLocation = CGPointMake(-1.f, -1.f);
  205. [self setupConstraints];
  206. }
  207. - (void)setupGestureRecognizers
  208. {
  209. _tapOnVideoRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(toggleControlsVisible)];
  210. _tapOnVideoRecognizer.delegate = self;
  211. [self.view addGestureRecognizer:_tapOnVideoRecognizer];
  212. _pinchRecognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(handlePinchGesture:)];
  213. _pinchRecognizer.delegate = self;
  214. if ([[UIDevice currentDevice] isiPhoneX]) {
  215. _tapToToggleiPhoneXRatioRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:_vpc action:@selector(switchIPhoneXFullScreen)];
  216. _tapToToggleiPhoneXRatioRecognizer.numberOfTapsRequired = 2;
  217. [self.view addGestureRecognizer:_tapToToggleiPhoneXRatioRecognizer];
  218. } else {
  219. _tapToSeekRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapToSeekRecognized:)];
  220. [_tapToSeekRecognizer setNumberOfTapsRequired:2];
  221. [self.view addGestureRecognizer:_tapToSeekRecognizer];
  222. [_tapOnVideoRecognizer requireGestureRecognizerToFail:_tapToSeekRecognizer];
  223. }
  224. _tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(togglePlayPause)];
  225. [_tapRecognizer setNumberOfTouchesRequired:2];
  226. _currentPanType = VLCPanTypeNone;
  227. _panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panRecognized:)];
  228. [_panRecognizer setMinimumNumberOfTouches:1];
  229. [_panRecognizer setMaximumNumberOfTouches:1];
  230. _swipeRecognizerLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeRecognized:)];
  231. _swipeRecognizerLeft.direction = UISwipeGestureRecognizerDirectionLeft;
  232. _swipeRecognizerRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeRecognized:)];
  233. _swipeRecognizerRight.direction = UISwipeGestureRecognizerDirectionRight;
  234. _swipeRecognizerUp = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeRecognized:)];
  235. _swipeRecognizerUp.direction = UISwipeGestureRecognizerDirectionUp;
  236. _swipeRecognizerUp.numberOfTouchesRequired = 2;
  237. _swipeRecognizerDown = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeRecognized:)];
  238. _swipeRecognizerDown.direction = UISwipeGestureRecognizerDirectionDown;
  239. _swipeRecognizerDown.numberOfTouchesRequired = 2;
  240. [self.view addGestureRecognizer:_pinchRecognizer];
  241. [self.view addGestureRecognizer:_swipeRecognizerLeft];
  242. [self.view addGestureRecognizer:_swipeRecognizerRight];
  243. [self.view addGestureRecognizer:_swipeRecognizerUp];
  244. [self.view addGestureRecognizer:_swipeRecognizerDown];
  245. [self.view addGestureRecognizer:_panRecognizer];
  246. [self.view addGestureRecognizer:_tapRecognizer];
  247. [_panRecognizer requireGestureRecognizerToFail:_swipeRecognizerLeft];
  248. [_panRecognizer requireGestureRecognizerToFail:_swipeRecognizerRight];
  249. [_panRecognizer requireGestureRecognizerToFail:_swipeRecognizerUp];
  250. [_panRecognizer requireGestureRecognizerToFail:_swipeRecognizerDown];
  251. _panRecognizer.delegate = self;
  252. _swipeRecognizerRight.delegate = self;
  253. _swipeRecognizerLeft.delegate = self;
  254. _swipeRecognizerUp.delegate = self;
  255. _swipeRecognizerDown.delegate = self;
  256. _tapRecognizer.delegate = self;
  257. _tapToSeekRecognizer.delegate = self;
  258. }
  259. - (void)setupControlPanel
  260. {
  261. _controllerPanel = [[VLCMovieViewControlPanelView alloc] initWithFrame:CGRectZero];
  262. [_controllerPanel.bwdButton addTarget:self action:@selector(backward:) forControlEvents:UIControlEventTouchUpInside];
  263. [_controllerPanel.fwdButton addTarget:self action:@selector(forward:) forControlEvents:UIControlEventTouchUpInside];
  264. [_controllerPanel.playPauseButton addTarget:self action:@selector(playPause) forControlEvents:UIControlEventTouchUpInside];
  265. [_controllerPanel.moreActionsButton addTarget:self action:@selector(moreActions:) forControlEvents:UIControlEventTouchUpInside];
  266. [_controllerPanel.playbackSpeedButton addTarget:self action:@selector(showPlaybackSpeedView) forControlEvents:UIControlEventTouchUpInside];
  267. [_controllerPanel.trackSwitcherButton addTarget:self action:@selector(switchTrack:) forControlEvents:UIControlEventTouchUpInside];
  268. [_controllerPanel.videoFilterButton addTarget:self action:@selector(videoFilterToggle:) forControlEvents:UIControlEventTouchUpInside];
  269. // HACK: get the slider from volume view
  270. UISlider *volumeSlider = nil;
  271. for (id aView in _controllerPanel.volumeView.subviews){
  272. if ([aView isKindOfClass:[UISlider class]]){
  273. volumeSlider = (UISlider *)aView;
  274. break;
  275. }
  276. }
  277. [volumeSlider addTarget:self action:@selector(volumeSliderAction:) forControlEvents:UIControlEventValueChanged];
  278. _controllerPanel.translatesAutoresizingMaskIntoConstraints = NO;
  279. [self.view addSubview:_controllerPanel];
  280. }
  281. - (void)setupConstraints
  282. {
  283. NSArray *hConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|[panel]|"
  284. options:0
  285. metrics:nil
  286. views:@{@"panel":_controllerPanel}];
  287. NSArray *vConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"V:[panel]|"
  288. options:0
  289. metrics:nil
  290. views:@{@"panel":_controllerPanel}];
  291. [self.view addConstraints:hConstraints];
  292. [self.view addConstraints:vConstraints];
  293. //constraint within _trackSelectorContainer is setting it's height to the tableviews contentview
  294. NSLayoutConstraint *widthConstraint = [NSLayoutConstraint constraintWithItem:_trackSelectorContainer attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeWidth multiplier:2.0/3.0 constant:0];
  295. widthConstraint.priority = UILayoutPriorityRequired - 1;
  296. NSArray *constraints = @[
  297. [NSLayoutConstraint constraintWithItem:_trackSelectorContainer attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterX multiplier:1 constant:0],
  298. [NSLayoutConstraint constraintWithItem:_trackSelectorContainer attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterY multiplier:1 constant:0],
  299. [NSLayoutConstraint constraintWithItem:_trackSelectorContainer attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationLessThanOrEqual toItem:nil attribute:NSLayoutAttributeWidth multiplier:1 constant:420.0],
  300. widthConstraint,
  301. [NSLayoutConstraint constraintWithItem:_trackSelectorContainer attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationLessThanOrEqual toItem:self.view attribute:NSLayoutAttributeHeight multiplier:2.0/3.0 constant:0],
  302. ];
  303. [NSLayoutConstraint activateConstraints:constraints];
  304. }
  305. - (void)setupNavigationbar
  306. {
  307. UIButton *doneButton = [[UIButton alloc] initWithFrame:CGRectZero];
  308. [doneButton addTarget:self action:@selector(closePlayback:) forControlEvents:UIControlEventTouchUpInside];
  309. [doneButton setTitle:NSLocalizedString(@"BUTTON_DONE", nil) forState:UIControlStateNormal];
  310. doneButton.translatesAutoresizingMaskIntoConstraints = NO;
  311. self.timeNavigationTitleView = [[[NSBundle mainBundle] loadNibNamed:@"VLCTimeNavigationTitleView" owner:self options:nil] objectAtIndex:0];
  312. self.timeNavigationTitleView.translatesAutoresizingMaskIntoConstraints = NO;
  313. [self.navigationController.navigationBar addSubview:self.timeNavigationTitleView];
  314. [self.navigationController.navigationBar addSubview:doneButton];
  315. NSObject *guide = self.navigationController.navigationBar;
  316. if (@available(iOS 11.0, *)) {
  317. guide = self.navigationController.navigationBar.safeAreaLayoutGuide;
  318. }
  319. [self.navigationController.view addConstraints: @[
  320. [NSLayoutConstraint constraintWithItem:doneButton attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:guide attribute:NSLayoutAttributeLeft multiplier:1 constant:8],
  321. [NSLayoutConstraint constraintWithItem:doneButton attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self.navigationController.navigationBar attribute:NSLayoutAttributeCenterY multiplier:1 constant:0],
  322. [NSLayoutConstraint constraintWithItem:self.timeNavigationTitleView attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:doneButton attribute:NSLayoutAttributeRight multiplier:1 constant:0],
  323. [NSLayoutConstraint constraintWithItem:self.timeNavigationTitleView attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:guide attribute:NSLayoutAttributeRight multiplier:1 constant:0],
  324. [NSLayoutConstraint constraintWithItem:self.timeNavigationTitleView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.navigationController.navigationBar attribute:NSLayoutAttributeTop multiplier:1 constant:0],
  325. [NSLayoutConstraint constraintWithItem:self.timeNavigationTitleView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.navigationController.navigationBar attribute:NSLayoutAttributeBottom multiplier:1 constant:0],
  326. ]];
  327. }
  328. - (void)resetVideoFiltersSliders
  329. {
  330. _brightnessSlider.value = 1.;
  331. _contrastSlider.value = 1.;
  332. _hueSlider.value = 0.;
  333. _saturationSlider.value = 1.;
  334. _gammaSlider.value = 1.;
  335. }
  336. - (void)viewWillAppear:(BOOL)animated
  337. {
  338. [super viewWillAppear:animated];
  339. _vpc.delegate = self;
  340. [_vpc recoverPlaybackState];
  341. self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
  342. self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
  343. [self setupNavigationbar];
  344. /* reset audio meta data views */
  345. self.artworkImageView.image = nil;
  346. self.trackNameLabel.text = nil;
  347. self.artistNameLabel.text = nil;
  348. self.albumNameLabel.text = nil;
  349. [self setControlsHidden:NO animated:animated];
  350. [self updateDefaults];
  351. //Disabling video gestures, media not init in the player yet.
  352. [self enableNormalVideoGestures:NO];
  353. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateDefaults) name:NSUserDefaultsDidChangeNotification object:nil];
  354. }
  355. - (void)viewDidAppear:(BOOL)animated
  356. {
  357. [super viewDidAppear:animated];
  358. _viewAppeared = YES;
  359. _playbackWillClose = NO;
  360. [_vpc recoverDisplayedMetadata];
  361. [self resetVideoFiltersSliders];
  362. _vpc.videoOutputView = self.movieView;
  363. _multiSelectionView.repeatMode = _vpc.repeatMode;
  364. _multiSelectionView.shuffleMode = _vpc.isShuffleMode;
  365. //Media is loaded in the media player, checking the projection type and configuring accordingly.
  366. _fov = 0.f;
  367. _mediaHasProjection = NO;
  368. if ([_vpc currentMediaProjection] == VLCMediaProjectionEquiRectangular) {
  369. _fov = DEFAULT_FOV;
  370. _mediaHasProjection = YES;
  371. }
  372. [self enableNormalVideoGestures:!_mediaHasProjection];
  373. }
  374. - (void)viewDidLayoutSubviews
  375. {
  376. CGRect equalizerRect = _equalizerView.frame;
  377. equalizerRect.origin.x = CGRectGetMidX(self.view.bounds) - CGRectGetWidth(equalizerRect)/2.0;
  378. equalizerRect.origin.y = CGRectGetMidY(self.view.bounds) - CGRectGetHeight(equalizerRect)/2.0;
  379. _equalizerView.frame = equalizerRect;
  380. CGRect multiSelectionFrame;
  381. CGRect controllerPanelFrame = _controllerPanel.frame;;
  382. if (UI_USER_INTERFACE_IDIOM() != UIUserInterfaceIdiomPhone) {
  383. multiSelectionFrame = (CGRect){CGPointMake(0., 0.), [_multiSelectionView proposedDisplaySize]};
  384. multiSelectionFrame.origin.x = controllerPanelFrame.size.width - multiSelectionFrame.size.width;
  385. multiSelectionFrame.origin.y = controllerPanelFrame.origin.y - multiSelectionFrame.size.height;
  386. _multiSelectionView.frame = multiSelectionFrame;
  387. _multiSelectionView.showsEqualizer = YES;
  388. return;
  389. }
  390. if (UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation])) {
  391. _multiSelectionView.showsEqualizer = YES;
  392. multiSelectionFrame = (CGRect){CGPointMake(0., 0.), [_multiSelectionView proposedDisplaySize]};
  393. multiSelectionFrame.origin.x = controllerPanelFrame.size.width - multiSelectionFrame.size.width;
  394. multiSelectionFrame.origin.y = controllerPanelFrame.origin.y - multiSelectionFrame.size.height;
  395. } else {
  396. _multiSelectionView.showsEqualizer = NO;
  397. multiSelectionFrame = (CGRect){CGPointMake(0., 0.), [_multiSelectionView proposedDisplaySize]};
  398. multiSelectionFrame.origin.x = controllerPanelFrame.size.width - multiSelectionFrame.size.width;
  399. multiSelectionFrame.origin.y = controllerPanelFrame.origin.y - multiSelectionFrame.size.height;
  400. }
  401. _multiSelectionView.frame = multiSelectionFrame;
  402. }
  403. - (void)viewWillDisappear:(BOOL)animated
  404. {
  405. if (_vpc.videoOutputView == self.movieView) {
  406. _vpc.videoOutputView = nil;
  407. }
  408. _viewAppeared = NO;
  409. if (_idleTimer) {
  410. [_idleTimer invalidate];
  411. _idleTimer = nil;
  412. }
  413. [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationFade];
  414. [super viewWillDisappear:animated];
  415. // hide filter UI for next run
  416. if (!_videoFiltersHidden)
  417. _videoFiltersHidden = YES;
  418. if (_equalizerView.hidden == NO)
  419. _equalizerView.hidden = YES;
  420. if (!_playbackSpeedViewHidden)
  421. _playbackSpeedViewHidden = YES;
  422. // reset tap to seek values
  423. _isTapSeeking = NO;
  424. _previousJumpState = VLCMovieJumpStateDefault;
  425. _numberOfTapSeek = 0;
  426. [[NSNotificationCenter defaultCenter] removeObserver:self name:NSUserDefaultsDidChangeNotification object:nil];
  427. [[NSUserDefaults standardUserDefaults] setBool:_displayRemainingTime forKey:kVLCShowRemainingTime];
  428. }
  429. - (BOOL)canBecomeFirstResponder
  430. {
  431. return YES;
  432. }
  433. - (void)dismissViewControllerAnimated:(BOOL)flag completion:(void (^)(void))completion
  434. {
  435. [self setControlsHidden:YES animated:flag];
  436. [super dismissViewControllerAnimated:flag completion:completion];
  437. }
  438. - (void)updateDefaults
  439. {
  440. NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
  441. if (!_playbackWillClose) {
  442. _displayRemainingTime = [[defaults objectForKey:kVLCShowRemainingTime] boolValue];
  443. [self updateTimeDisplayButton];
  444. }
  445. _volumeGestureEnabled = [[defaults objectForKey:kVLCSettingVolumeGesture] boolValue];
  446. _playPauseGestureEnabled = [[defaults objectForKey:kVLCSettingPlayPauseGesture] boolValue];
  447. _brightnessGestureEnabled = [[defaults objectForKey:kVLCSettingBrightnessGesture] boolValue];
  448. _seekGestureEnabled = [[defaults objectForKey:kVLCSettingSeekGesture] boolValue];
  449. _closeGestureEnabled = [[defaults objectForKey:kVLCSettingCloseGesture] boolValue];
  450. _variableJumpDurationEnabled = [[defaults objectForKey:kVLCSettingVariableJumpDuration] boolValue];
  451. }
  452. #pragma mark - Initializer helper
  453. - (void)sleepTimerInitializer
  454. {
  455. /* add sleep timer UI */
  456. _sleepTimerContainer = [[VLCFrostedGlasView alloc] initWithFrame:CGRectMake(0., 0., 300., 200.)];
  457. _sleepTimerContainer.center = self.view.center;
  458. _sleepTimerContainer.clipsToBounds = YES;
  459. _sleepTimerContainer.layer.cornerRadius = 5;
  460. _sleepTimerContainer.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleTopMargin;
  461. //Layers used to create a separator for the buttons.
  462. CALayer *horizontalSeparator = [CALayer layer];
  463. horizontalSeparator.frame = CGRectMake(0., 162., 300., 1.);
  464. horizontalSeparator.backgroundColor = [UIColor VLCLightTextColor].CGColor;
  465. CALayer *verticalSeparator = [CALayer layer];
  466. verticalSeparator.frame = CGRectMake(150., 162., 1., 48.);
  467. verticalSeparator.backgroundColor = [UIColor VLCLightTextColor].CGColor;
  468. _sleepTimeDatePicker = [[UIDatePicker alloc] init];
  469. _sleepTimeDatePicker.opaque = NO;
  470. _sleepTimeDatePicker.backgroundColor = [UIColor clearColor];
  471. _sleepTimeDatePicker.tintColor = [UIColor VLCLightTextColor];
  472. _sleepTimeDatePicker.frame = CGRectMake(0., 0., 300., 162.);
  473. _sleepTimeDatePicker.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleTopMargin;
  474. [_sleepTimerContainer addSubview:_sleepTimeDatePicker];
  475. [_sleepTimerContainer.layer addSublayer:horizontalSeparator];
  476. [_sleepTimerContainer.layer addSublayer:verticalSeparator];
  477. UIButton *cancelSleepTimer = [[UIButton alloc] initWithFrame:CGRectMake(0., 162., 150., 48.)];
  478. cancelSleepTimer.backgroundColor = [UIColor clearColor];
  479. [cancelSleepTimer setTitle:NSLocalizedString(@"BUTTON_CANCEL", nil) forState:UIControlStateNormal];
  480. [cancelSleepTimer setTintColor:[UIColor VLCLightTextColor]];
  481. [cancelSleepTimer setTitleColor:[UIColor VLCDarkTextShadowColor] forState:UIControlStateHighlighted];
  482. [cancelSleepTimer addTarget:self action:@selector(sleepTimerCancel:) forControlEvents:UIControlEventTouchDown];
  483. cancelSleepTimer.contentEdgeInsets = UIEdgeInsetsMake(0, 0, 10, 0);
  484. [_sleepTimerContainer addSubview:cancelSleepTimer];
  485. UIButton *confirmSleepTimer = [[UIButton alloc] initWithFrame:CGRectMake(150., 162., 150., 48.)];
  486. confirmSleepTimer.backgroundColor = [UIColor clearColor];
  487. [confirmSleepTimer setTitle:NSLocalizedString(@"BUTTON_DONE", nil) forState:UIControlStateNormal];
  488. [confirmSleepTimer setTintColor:[UIColor VLCLightTextColor]];
  489. [confirmSleepTimer setTitleColor:[UIColor VLCDarkTextShadowColor] forState:UIControlStateHighlighted];
  490. [confirmSleepTimer addTarget:self action:@selector(sleepTimerAction:) forControlEvents:UIControlEventTouchDown];
  491. confirmSleepTimer.contentEdgeInsets = UIEdgeInsetsMake(0, 0, 10, 0);
  492. [_sleepTimerContainer addSubview:confirmSleepTimer];
  493. /* adapt the date picker style to suit our needs */
  494. [_sleepTimeDatePicker setValue:[UIColor whiteColor] forKeyPath:@"textColor"];
  495. SEL selector = NSSelectorFromString(@"setHighlightsToday:");
  496. NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[UIDatePicker instanceMethodSignatureForSelector:selector]];
  497. BOOL no = NO;
  498. [invocation setSelector:selector];
  499. [invocation setArgument:&no atIndex:2];
  500. [invocation invokeWithTarget:_sleepTimeDatePicker];
  501. if (_sleepTimerContainer.subviews.count > 0) {
  502. NSArray *subviewsOfSubview = [_sleepTimeDatePicker.subviews[0] subviews];
  503. NSUInteger subviewCount = subviewsOfSubview.count;
  504. for (NSUInteger x = 0; x < subviewCount; x++) {
  505. if ([subviewsOfSubview[x] isKindOfClass:[UILabel class]])
  506. [subviewsOfSubview[x] setTextColor:[UIColor VLCLightTextColor]];
  507. }
  508. }
  509. _sleepTimeDatePicker.datePickerMode = UIDatePickerModeCountDownTimer;
  510. _sleepTimeDatePicker.minuteInterval = 1;
  511. _sleepTimeDatePicker.minimumDate = [NSDate date];
  512. _sleepTimeDatePicker.countDownDuration = 1200.;
  513. [self.view addSubview:_sleepTimerContainer];
  514. }
  515. #pragma mark - controls visibility
  516. - (void)handlePinchGesture:(UIPinchGestureRecognizer *)recognizer
  517. {
  518. LOCKCHECK;
  519. if (!_closeGestureEnabled || isnan(recognizer.velocity))
  520. return;
  521. CGFloat diff = DEFAULT_FOV * -(ZOOM_SENSITIVITY * recognizer.velocity / _screenSizePixel.width);
  522. if (_mediaHasProjection) {
  523. if ([_vpc updateViewpoint:0 pitch:0 roll:0 fov:diff absolute:NO]) {
  524. //Checking for fov value in case of
  525. _fov = MAX(MIN(_fov + diff, MAX_FOV), MIN_FOV);
  526. }
  527. } else if (recognizer.velocity < 0.) {
  528. [self minimizePlayback:nil];
  529. }
  530. }
  531. - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
  532. {
  533. if (touch.view != self.view)
  534. return NO;
  535. return YES;
  536. }
  537. - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
  538. {
  539. return YES;
  540. }
  541. - (void)setControlsHidden:(BOOL)hidden animated:(BOOL)animated
  542. {
  543. _controlsHidden = hidden;
  544. CGFloat alpha = _controlsHidden? 0.0f: 1.0f;
  545. if (!_controlsHidden) {
  546. self.navigationController.navigationBar.alpha = 0.0;
  547. self.navigationController.navigationBar.hidden = NO;
  548. _controllerPanel.alpha = 0.0f;
  549. _controllerPanel.hidden = !_videoFiltersHidden;
  550. _videoFilterView.alpha = 0.0f;
  551. _videoFilterView.hidden = _videoFiltersHidden;
  552. _playbackSpeedView.alpha = 0.0f;
  553. _playbackSpeedView.hidden = _playbackSpeedViewHidden;
  554. _trackSelectorContainer.alpha = 0.0f;
  555. _trackSelectorContainer.hidden = YES;
  556. _equalizerView.alpha = 0.0f;
  557. _equalizerView.hidden = YES;
  558. if (_sleepTimerContainer) {
  559. _sleepTimerContainer.alpha = 0.0f;
  560. _sleepTimerContainer.hidden = YES;
  561. }
  562. _multiSelectionView.alpha = 0.0f;
  563. _multiSelectionView.hidden = YES;
  564. _artistNameLabel.hidden = NO;
  565. _albumNameLabel.hidden = NO;
  566. _trackNameLabel.hidden = NO;
  567. }
  568. void (^animationBlock)() = ^() {
  569. self.navigationController.navigationBar.alpha = alpha;
  570. _controllerPanel.alpha = alpha;
  571. _videoFilterView.alpha = alpha;
  572. _playbackSpeedView.alpha = alpha;
  573. _trackSelectorContainer.alpha = alpha;
  574. _equalizerView.alpha = alpha;
  575. _multiSelectionView.alpha = alpha;
  576. if (_sleepTimerContainer)
  577. _sleepTimerContainer.alpha = alpha;
  578. CGFloat metaInfoAlpha = _audioOnly ? 1.0f : alpha;
  579. _artistNameLabel.alpha = metaInfoAlpha;
  580. _albumNameLabel.alpha = metaInfoAlpha;
  581. _trackNameLabel.alpha = metaInfoAlpha;
  582. };
  583. void (^completionBlock)(BOOL finished) = ^(BOOL finished) {
  584. _controllerPanel.hidden = _videoFiltersHidden ? _controlsHidden : NO;
  585. _videoFilterView.hidden = _videoFiltersHidden;
  586. _playbackSpeedView.hidden = _playbackSpeedViewHidden;
  587. self.navigationController.navigationBar.hidden = _controlsHidden;
  588. _trackSelectorContainer.hidden = YES;
  589. _equalizerView.hidden = YES;
  590. if (_sleepTimerContainer)
  591. _sleepTimerContainer.hidden = YES;
  592. _multiSelectionView.hidden = YES;
  593. _artistNameLabel.hidden = _audioOnly ? NO : _controlsHidden;
  594. _albumNameLabel.hidden = _audioOnly ? NO : _controlsHidden;
  595. _trackNameLabel.hidden = _audioOnly ? NO : _controlsHidden;
  596. };
  597. UIStatusBarAnimation animationType = animated? UIStatusBarAnimationFade: UIStatusBarAnimationNone;
  598. NSTimeInterval animationDuration = animated? 0.3: 0.0;
  599. [[UIApplication sharedApplication] setStatusBarHidden:_viewAppeared ? _controlsHidden : NO withAnimation:animationType];
  600. [UIView animateWithDuration:animationDuration animations:animationBlock completion:completionBlock];
  601. }
  602. - (void)toggleControlsVisible
  603. {
  604. if (!_trackSelectorContainer.hidden) {
  605. for (UIGestureRecognizer *recognizer in self.view.gestureRecognizers)
  606. [recognizer setEnabled:YES];
  607. }
  608. if (_controlsHidden && !_videoFiltersHidden)
  609. _videoFiltersHidden = YES;
  610. if (_isTapSeeking)
  611. _numberOfTapSeek = 0;
  612. [self setControlsHidden:!_controlsHidden animated:YES];
  613. }
  614. - (void)_resetIdleTimer
  615. {
  616. if (!_idleTimer)
  617. _idleTimer = [NSTimer scheduledTimerWithTimeInterval:4.
  618. target:self
  619. selector:@selector(idleTimerExceeded)
  620. userInfo:nil
  621. repeats:NO];
  622. else {
  623. if (fabs([_idleTimer.fireDate timeIntervalSinceNow]) < 4.)
  624. [_idleTimer setFireDate:[NSDate dateWithTimeIntervalSinceNow:4.]];
  625. }
  626. }
  627. - (NSString *)_stringInTimeFormatFrom:(int)duration
  628. {
  629. if (duration < 60) {
  630. return [NSString stringWithFormat:@"%is", duration];
  631. } else {
  632. return [NSString stringWithFormat:@"%im%is", duration / 60, duration % 60];
  633. }
  634. }
  635. - (void)_seekFromTap
  636. {
  637. NSMutableString *hudString = [NSMutableString string];
  638. int seekDuration = (int)_numberOfTapSeek * SHORT_JUMP_DURATION;
  639. if (seekDuration > 0) {
  640. [_vpc jumpForward:SHORT_JUMP_DURATION];
  641. [hudString appendString:@"⇒ "];
  642. _previousJumpState = VLCMovieJumpStateForward;
  643. } else {
  644. [_vpc jumpBackward:SHORT_JUMP_DURATION];
  645. [hudString appendString:@"⇐ "];
  646. _previousJumpState = VLCMovieJumpStateBackward;
  647. }
  648. [hudString appendString: [self _stringInTimeFormatFrom:abs(seekDuration)]];
  649. [self.statusLabel showStatusMessage:[NSString stringWithString:hudString]];
  650. if (_controlsHidden)
  651. [self setControlsHidden:NO animated:NO];
  652. }
  653. - (void)idleTimerExceeded
  654. {
  655. if (![NSThread isMainThread]) {
  656. [self performSelectorOnMainThread:@selector(idleTimerExceeded) withObject:nil waitUntilDone:NO];
  657. return;
  658. }
  659. _idleTimer = nil;
  660. if (!_controlsHidden)
  661. [self toggleControlsVisible];
  662. if (_isTapSeeking) {
  663. _isTapSeeking = NO;
  664. _numberOfTapSeek = 0;
  665. }
  666. if (!_videoFiltersHidden)
  667. _videoFiltersHidden = YES;
  668. if (_equalizerView.hidden == NO)
  669. _equalizerView.hidden = YES;
  670. if (!_playbackSpeedViewHidden)
  671. _playbackSpeedViewHidden = YES;
  672. if (self.scrubIndicatorView.hidden == NO)
  673. self.scrubIndicatorView.hidden = YES;
  674. }
  675. - (UIResponder *)nextResponder
  676. {
  677. [self _resetIdleTimer];
  678. return [super nextResponder];
  679. }
  680. - (void)enableNormalVideoGestures:(BOOL)enable
  681. {
  682. [_tapRecognizer setEnabled:enable];
  683. [_swipeRecognizerUp setEnabled:enable];
  684. [_swipeRecognizerDown setEnabled:enable];
  685. [_swipeRecognizerLeft setEnabled:enable];
  686. [_swipeRecognizerRight setEnabled:enable];
  687. }
  688. #pragma mark - controls
  689. - (IBAction)closePlayback:(id)sender
  690. {
  691. LOCKCHECK;
  692. _playbackWillClose = YES;
  693. [_vpc stopPlayback];
  694. }
  695. - (IBAction)minimizePlayback:(id)sender
  696. {
  697. LOCKCHECK;
  698. [[UIApplication sharedApplication] sendAction:@selector(closeFullscreenPlayback) to:nil from:self forEvent:nil];
  699. }
  700. - (IBAction)positionSliderAction:(UISlider *)sender
  701. {
  702. LOCKCHECK;
  703. /* we need to limit the number of events sent by the slider, since otherwise, the user
  704. * wouldn't see the I-frames when seeking on current mobile devices. This isn't a problem
  705. * within the Simulator, but especially on older ARMv7 devices, it's clearly noticeable. */
  706. [self performSelector:@selector(_setPositionForReal) withObject:nil afterDelay:0.3];
  707. if (_mediaDuration > 0) {
  708. VLCTime *newPosition = [VLCTime timeWithInt:(int)(sender.value * _mediaDuration)];
  709. [self.timeNavigationTitleView.timeDisplayButton setTitle:newPosition.stringValue forState:UIControlStateNormal];
  710. [self.timeNavigationTitleView setNeedsLayout];
  711. self.timeNavigationTitleView.timeDisplayButton.accessibilityLabel = [NSString stringWithFormat:@"%@: %@", NSLocalizedString(@"PLAYBACK_POSITION", nil), newPosition.stringValue];
  712. _positionSet = NO;
  713. }
  714. [self _resetIdleTimer];
  715. }
  716. - (void)_setPositionForReal
  717. {
  718. if (!_positionSet) {
  719. [_vpc setPlaybackPosition:self.timeNavigationTitleView.positionSlider.value];
  720. [_vpc setNeedsMetadataUpdate];
  721. _positionSet = YES;
  722. }
  723. }
  724. - (IBAction)positionSliderTouchDown:(id)sender
  725. {
  726. LOCKCHECK;
  727. [self _updateScrubLabel];
  728. self.scrubIndicatorView.hidden = NO;
  729. _isScrubbing = YES;
  730. }
  731. - (IBAction)positionSliderTouchUp:(id)sender
  732. {
  733. LOCKCHECK;
  734. self.scrubIndicatorView.hidden = YES;
  735. _isScrubbing = NO;
  736. }
  737. - (void)_updateScrubLabel
  738. {
  739. float speed = self.timeNavigationTitleView.positionSlider.scrubbingSpeed;
  740. if (speed == 1.)
  741. self.currentScrubSpeedLabel.text = NSLocalizedString(@"PLAYBACK_SCRUB_HIGH", nil);
  742. else if (speed == .5)
  743. self.currentScrubSpeedLabel.text = NSLocalizedString(@"PLAYBACK_SCRUB_HALF", nil);
  744. else if (speed == .25)
  745. self.currentScrubSpeedLabel.text = NSLocalizedString(@"PLAYBACK_SCRUB_QUARTER", nil);
  746. else
  747. self.currentScrubSpeedLabel.text = NSLocalizedString(@"PLAYBACK_SCRUB_FINE", nil);
  748. [self _resetIdleTimer];
  749. }
  750. - (IBAction)positionSliderDrag:(id)sender
  751. {
  752. LOCKCHECK;
  753. [self _updateScrubLabel];
  754. }
  755. - (void)volumeSliderAction:(id)sender
  756. {
  757. LOCKCHECK;
  758. [self _resetIdleTimer];
  759. }
  760. - (void)updateTimeDisplayButton
  761. {
  762. UIButton *timeDisplayButton = self.timeNavigationTitleView.timeDisplayButton;
  763. if (_displayRemainingTime)
  764. [timeDisplayButton setTitle:[[_vpc remainingTime] stringValue] forState:UIControlStateNormal];
  765. else
  766. [timeDisplayButton setTitle:[[_vpc playedTime] stringValue] forState:UIControlStateNormal];
  767. [self.timeNavigationTitleView setNeedsLayout];
  768. }
  769. - (void)updateSleepTimerButton
  770. {
  771. NSMutableString *title = [NSMutableString stringWithString:NSLocalizedString(@"BUTTON_SLEEP_TIMER", nil)];
  772. if (_vpc.sleepTimer != nil && _vpc.sleepTimer.valid) {
  773. int remainSeconds = (int)[_vpc.sleepTimer.fireDate timeIntervalSinceNow];
  774. int hour = remainSeconds / 3600;
  775. int minute = (remainSeconds - hour * 3600) / 60;
  776. int second = remainSeconds % 60;
  777. [title appendFormat:@" %02d:%02d:%02d", hour, minute, second];
  778. } else {
  779. [_sleepCountDownTimer invalidate];
  780. }
  781. [_sleepTimerButton setTitle:title forState:UIControlStateNormal];
  782. }
  783. #pragma mark - playback controller delegation
  784. - (void)playbackPositionUpdated:(VLCPlaybackController *)controller
  785. {
  786. if (!_isScrubbing) {
  787. self.timeNavigationTitleView.positionSlider.value = [controller playbackPosition];
  788. }
  789. [self updateTimeDisplayButton];
  790. }
  791. - (void)prepareForMediaPlayback:(VLCPlaybackController *)controller
  792. {
  793. self.trackNameLabel.text = self.artistNameLabel.text = self.albumNameLabel.text = @"";
  794. self.timeNavigationTitleView.positionSlider.value = 0.;
  795. [self.timeNavigationTitleView.timeDisplayButton setTitle:@"" forState:UIControlStateNormal];
  796. self.timeNavigationTitleView.timeDisplayButton.accessibilityLabel = @"";
  797. [_equalizerView reloadData];
  798. double playbackRate = controller.playbackRate;
  799. self.playbackSpeedSlider.value = log2(playbackRate);
  800. self.playbackSpeedIndicator.text = [NSString stringWithFormat:@"%.2fx", playbackRate];
  801. float audioDelay = controller.audioDelay;
  802. self.audioDelaySlider.value = audioDelay;
  803. self.audioDelayIndicator.text = [NSString stringWithFormat:@"%1.2f s", audioDelay];
  804. float subtitleDelay = controller.subtitleDelay;
  805. self.spuDelaySlider.value = subtitleDelay;
  806. self.spuDelayIndicator.text = [NSString stringWithFormat:@"%1.00f s", subtitleDelay];
  807. [self _resetIdleTimer];
  808. }
  809. - (void)playbackDidStop:(NSNotification *)notification
  810. {
  811. [self minimizePlayback:nil];
  812. }
  813. - (void)mediaPlayerStateChanged:(VLCMediaPlayerState)currentState
  814. isPlaying:(BOOL)isPlaying
  815. currentMediaHasTrackToChooseFrom:(BOOL)currentMediaHasTrackToChooseFrom
  816. currentMediaHasChapters:(BOOL)currentMediaHasChapters
  817. forPlaybackController:(VLCPlaybackController *)controller
  818. {
  819. if (currentState == VLCMediaPlayerStateBuffering)
  820. _mediaDuration = controller.mediaDuration;
  821. if (currentState == VLCMediaPlayerStateError)
  822. [self.statusLabel showStatusMessage:NSLocalizedString(@"PLAYBACK_FAILED", nil)];
  823. [_controllerPanel updateButtons];
  824. _multiSelectionView.mediaHasChapters = currentMediaHasChapters;
  825. }
  826. - (void)showStatusMessage:(NSString *)statusMessage forPlaybackController:(VLCPlaybackController *)controller
  827. {
  828. [self.statusLabel showStatusMessage:statusMessage];
  829. }
  830. - (void)hideShowAspectratioButton:(BOOL)hide
  831. {
  832. [UIView animateWithDuration:.3
  833. animations:^{
  834. self.widthConstraint.constant = hide ? 0 : 30;
  835. self.timeNavigationTitleView.aspectRatioButton.hidden = hide;
  836. }];
  837. }
  838. - (void)displayMetadataForPlaybackController:(VLCPlaybackController *)controller metadata:(VLCMetaData *)metadata
  839. {
  840. if (!_viewAppeared)
  841. return;
  842. self.trackNameLabel.text = metadata.title;
  843. self.artworkImageView.image = metadata.artworkImage;
  844. if (!metadata.artworkImage) {
  845. self.artistNameLabel.text = metadata.artist;
  846. self.albumNameLabel.text = metadata.albumName;
  847. } else
  848. self.artistNameLabel.text = self.albumNameLabel.text = nil;
  849. [self hideShowAspectratioButton:metadata.isAudioOnly];
  850. [_controllerPanel updateButtons];
  851. _audioOnly = metadata.isAudioOnly;
  852. }
  853. - (IBAction)playPause
  854. {
  855. LOCKCHECK;
  856. [_vpc playPause];
  857. }
  858. - (IBAction)forward:(id)sender
  859. {
  860. LOCKCHECK;
  861. [_vpc next];
  862. }
  863. - (IBAction)backward:(id)sender
  864. {
  865. LOCKCHECK;
  866. [_vpc previous];
  867. }
  868. - (IBAction)switchTrack:(id)sender
  869. {
  870. LOCKCHECK;
  871. if (_trackSelectorContainer.hidden == YES || _trackSelectorContainer.switchingTracksNotChapters == NO) {
  872. _trackSelectorContainer.switchingTracksNotChapters = YES;
  873. _trackSelectorContainer.hidden = NO;
  874. _trackSelectorContainer.alpha = 1.;
  875. [_trackSelectorContainer updateView];
  876. if (_equalizerView.hidden == NO)
  877. _equalizerView.hidden = YES;
  878. if (!_playbackSpeedViewHidden)
  879. self.playbackSpeedView.hidden = _playbackSpeedViewHidden = YES;
  880. self.videoFilterView.hidden = _videoFiltersHidden = YES;
  881. for (UIGestureRecognizer *recognizer in self.view.gestureRecognizers)
  882. [recognizer setEnabled:NO];
  883. [_tapOnVideoRecognizer setEnabled:YES];
  884. } else {
  885. _trackSelectorContainer.hidden = YES;
  886. _trackSelectorContainer.switchingTracksNotChapters = NO;
  887. }
  888. }
  889. - (IBAction)toggleTimeDisplay:(id)sender
  890. {
  891. LOCKCHECK;
  892. _displayRemainingTime = !_displayRemainingTime;
  893. [self updateTimeDisplayButton];
  894. [self _resetIdleTimer];
  895. }
  896. - (IBAction)sleepTimer:(id)sender
  897. {
  898. if (!_playbackSpeedViewHidden)
  899. self.playbackSpeedView.hidden = _playbackSpeedViewHidden = YES;
  900. if (_equalizerView.hidden == NO)
  901. _equalizerView.hidden = YES;
  902. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
  903. if (!_controlsHidden) {
  904. self.controllerPanel.hidden = _controlsHidden = YES;
  905. }
  906. }
  907. self.videoFilterView.hidden = _videoFiltersHidden = YES;
  908. _sleepTimerContainer.alpha = 1.;
  909. _sleepTimerContainer.hidden = NO;
  910. }
  911. - (IBAction)sleepTimerCancel:(id)sender
  912. {
  913. NSTimer *sleepTimer = [_vpc sleepTimer];
  914. if (sleepTimer) {
  915. [sleepTimer invalidate];
  916. sleepTimer = nil;
  917. }
  918. [self.statusLabel showStatusMessage:NSLocalizedString(@"SLEEP_TIMER_UPDATED", nil)];
  919. [self setControlsHidden:YES animated:YES];
  920. }
  921. - (IBAction)sleepTimerAction:(id)sender
  922. {
  923. [_vpc scheduleSleepTimerWithInterval:_sleepTimeDatePicker.countDownDuration];
  924. if (_sleepCountDownTimer == nil || _sleepCountDownTimer.valid == NO) {
  925. _sleepCountDownTimer = [NSTimer scheduledTimerWithTimeInterval:1
  926. target:self
  927. selector:@selector(updateSleepTimerButton)
  928. userInfo:nil
  929. repeats:YES];
  930. }
  931. [self.statusLabel showStatusMessage:NSLocalizedString(@"SLEEP_TIMER_UPDATED", nil)];
  932. [self setControlsHidden:YES animated:YES];
  933. }
  934. - (void)moreActions:(UIButton *)sender
  935. {
  936. if (_multiSelectionView.hidden == NO) {
  937. [UIView animateWithDuration:.3
  938. animations:^{
  939. _multiSelectionView.hidden = YES;
  940. }
  941. completion:^(BOOL finished){
  942. }];
  943. return;
  944. }
  945. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
  946. if (UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation])) {
  947. _multiSelectionView.showsEqualizer = YES;
  948. } else {
  949. _multiSelectionView.showsEqualizer = NO;
  950. }
  951. }
  952. CGRect workFrame = _multiSelectionView.frame;
  953. workFrame.size = [_multiSelectionView proposedDisplaySize];
  954. workFrame.origin.x = CGRectGetMaxX(sender.frame) - workFrame.size.width;
  955. _multiSelectionView.alpha = 1.0f;
  956. /* animate */
  957. _multiSelectionView.frame = CGRectMake(workFrame.origin.x, workFrame.origin.y + workFrame.size.height, workFrame.size.width, 0.);
  958. [UIView animateWithDuration:.3
  959. animations:^{
  960. _multiSelectionView.frame = workFrame;
  961. _multiSelectionView.hidden = NO;
  962. }
  963. completion:^(BOOL finished){
  964. }];
  965. [self _resetIdleTimer];
  966. }
  967. #pragma mark - multi-select delegation
  968. - (void)toggleUILock
  969. {
  970. _interfaceIsLocked = !_interfaceIsLocked;
  971. _multiSelectionView.displayLock = _interfaceIsLocked;
  972. }
  973. - (void)toggleEqualizer
  974. {
  975. LOCKCHECK;
  976. if (_equalizerView.hidden) {
  977. if (!_playbackSpeedViewHidden)
  978. self.playbackSpeedView.hidden = _playbackSpeedViewHidden = YES;
  979. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
  980. if (!_controlsHidden) {
  981. self.controllerPanel.hidden = _controlsHidden = YES;
  982. self.navigationController.navigationBar.hidden = YES;
  983. }
  984. }
  985. _trackSelectorContainer.hidden = YES;
  986. self.videoFilterView.hidden = _videoFiltersHidden = YES;
  987. _equalizerView.alpha = 1.;
  988. _equalizerView.hidden = NO;
  989. } else
  990. _equalizerView.hidden = YES;
  991. }
  992. - (void)toggleChapterAndTitleSelector
  993. {
  994. LOCKCHECK;
  995. if (_trackSelectorContainer.hidden == YES || _trackSelectorContainer.switchingTracksNotChapters == YES) {
  996. _trackSelectorContainer.switchingTracksNotChapters = NO;
  997. [_trackSelectorContainer updateView];
  998. _trackSelectorContainer.hidden = NO;
  999. _trackSelectorContainer.alpha = 1.;
  1000. if (_equalizerView.hidden == NO)
  1001. _equalizerView.hidden = YES;
  1002. if (!_playbackSpeedViewHidden)
  1003. self.playbackSpeedView.hidden = _playbackSpeedViewHidden = YES;
  1004. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
  1005. if (!_controlsHidden) {
  1006. self.controllerPanel.hidden = _controlsHidden = YES;
  1007. }
  1008. }
  1009. _sleepTimerContainer.hidden = YES;
  1010. self.videoFilterView.hidden = _videoFiltersHidden = YES;
  1011. } else {
  1012. _trackSelectorContainer.hidden = YES;
  1013. }
  1014. }
  1015. - (void)toggleRepeatMode
  1016. {
  1017. LOCKCHECK;
  1018. [[VLCPlaybackController sharedInstance] toggleRepeatMode];
  1019. _multiSelectionView.repeatMode = [VLCPlaybackController sharedInstance].repeatMode;
  1020. }
  1021. - (void)toggleShuffleMode
  1022. {
  1023. LOCKCHECK;
  1024. _vpc.shuffleMode = !_vpc.isShuffleMode;
  1025. _multiSelectionView.shuffleMode = _vpc.isShuffleMode;
  1026. }
  1027. - (void)hideMenu
  1028. {
  1029. [UIView animateWithDuration:.2
  1030. animations:^{
  1031. _multiSelectionView.hidden = YES;
  1032. }
  1033. completion:^(BOOL finished){
  1034. }];
  1035. [self _resetIdleTimer];
  1036. }
  1037. #pragma mark - multi-touch gestures
  1038. - (void)togglePlayPause
  1039. {
  1040. LOCKCHECK;
  1041. if (!_playPauseGestureEnabled)
  1042. return;
  1043. if (_vpc.isPlaying) {
  1044. [_vpc pause];
  1045. [self setControlsHidden:NO animated:_controlsHidden];
  1046. } else {
  1047. [_vpc play];
  1048. }
  1049. }
  1050. - (void)toggleiPhoneXAspectRatio
  1051. {
  1052. if (@available(iOS 11.0, *)) {
  1053. BOOL isFullScreen = CGRectEqualToRect(_movieView.frame , self.view.frame);
  1054. CGRect frameWithoutNotch = self.view.safeAreaLayoutGuide.layoutFrame;
  1055. [UIView animateWithDuration:0.3 animations:^{
  1056. _movieView.frame = isFullScreen ? frameWithoutNotch : self.view.frame;
  1057. }];
  1058. }
  1059. }
  1060. - (BOOL)prefersHomeIndicatorAutoHidden
  1061. {
  1062. return YES;
  1063. }
  1064. - (VLCPanType)detectPanTypeForPan:(UIPanGestureRecognizer*)panRecognizer
  1065. {
  1066. NSString *deviceType = [[UIDevice currentDevice] model];
  1067. UIWindow *window = [[UIApplication sharedApplication] keyWindow];
  1068. CGFloat windowWidth = CGRectGetWidth(window.bounds);
  1069. CGPoint location = [panRecognizer locationInView:window];
  1070. VLCPanType panType = VLCPanTypeVolume; // default or right side of the screen
  1071. if (location.x < windowWidth / 2)
  1072. panType = VLCPanTypeBrightness;
  1073. // only check for seeking gesture if on iPad , will overwrite last statements if true
  1074. if ([deviceType isEqualToString:@"iPad"]) {
  1075. if (location.y < 110)
  1076. panType = VLCPanTypeSeek;
  1077. }
  1078. return panType;
  1079. }
  1080. - (void)panRecognized:(UIPanGestureRecognizer*)panRecognizer
  1081. {
  1082. LOCKCHECK;
  1083. CGFloat panDirectionX = [panRecognizer velocityInView:self.view].x;
  1084. CGFloat panDirectionY = [panRecognizer velocityInView:self.view].y;
  1085. if (panRecognizer.state == UIGestureRecognizerStateBegan) {
  1086. _currentPanType = _mediaHasProjection ? VLCPanTypeProjection : [self detectPanTypeForPan:panRecognizer];
  1087. }
  1088. if (_currentPanType == VLCPanTypeSeek) {
  1089. if (!_seekGestureEnabled)
  1090. return;
  1091. double timeRemainingDouble = (-[_vpc remainingTime].intValue*0.001);
  1092. int timeRemaining = timeRemainingDouble;
  1093. if (panDirectionX > 0) {
  1094. if (timeRemaining > 2 ) // to not go outside duration , video will stop
  1095. [_vpc jumpForward:1];
  1096. } else
  1097. [_vpc jumpBackward:1];
  1098. } else if (_currentPanType == VLCPanTypeVolume) {
  1099. if (!_volumeGestureEnabled)
  1100. return;
  1101. MPMusicPlayerController *musicPlayer = [MPMusicPlayerController applicationMusicPlayer];
  1102. #pragma clang diagnostic push
  1103. #pragma clang diagnostic ignored "-Wdeprecated"
  1104. // there is no replacement for .volume which we want to use since Apple's susggestion is to not use their overlays
  1105. // but switch to the volume slider exclusively. meh.
  1106. if (panDirectionY > 0)
  1107. musicPlayer.volume -= 0.01;
  1108. else
  1109. musicPlayer.volume += 0.01;
  1110. #pragma clang diagnostic pop
  1111. } else if (_currentPanType == VLCPanTypeBrightness) {
  1112. if (!_brightnessGestureEnabled)
  1113. return;
  1114. CGFloat brightness = [UIScreen mainScreen].brightness;
  1115. if (panDirectionY > 0)
  1116. brightness = brightness - 0.01;
  1117. else
  1118. brightness = brightness + 0.01;
  1119. // Sanity check since -[UIScreen brightness] does not go by 0.01 steps
  1120. if (brightness > 1.0)
  1121. brightness = 1.0;
  1122. else if (brightness < 0.0)
  1123. brightness = 0.0;
  1124. NSAssert(brightness >= 0 && brightness <= 1, @"Brightness must be within 0 and 1 (it is %f)", brightness);
  1125. [[UIScreen mainScreen] setBrightness:brightness];
  1126. NSString *brightnessHUD = [NSString stringWithFormat:@"%@: %@ %%", NSLocalizedString(@"VFILTER_BRIGHTNESS", nil), [[[NSString stringWithFormat:@"%f",(brightness*100)] componentsSeparatedByString:@"."] objectAtIndex:0]];
  1127. [self.statusLabel showStatusMessage:brightnessHUD];
  1128. } else if (_currentPanType == VLCPanTypeProjection) {
  1129. CGPoint tmp = [panRecognizer locationInView:self.view];
  1130. CGFloat changeX = 0.f;
  1131. CGFloat changeY = 0.f;
  1132. if (_saveLocation.x != -1.f && _saveLocation.y != -1.f) {
  1133. changeX = tmp.x - _saveLocation.x;
  1134. changeY = tmp.y - _saveLocation.y;
  1135. }
  1136. _saveLocation = [panRecognizer locationInView:self.view];
  1137. //screenSizePixel width is used twice to get a constant speed on the movement.
  1138. CGFloat yaw = _fov * -changeX / _screenSizePixel.width;
  1139. CGFloat pitch = _fov * -changeY / _screenSizePixel.width;
  1140. [_vpc updateViewpoint:yaw pitch:pitch roll:0 fov:0 absolute:NO];
  1141. }
  1142. if (panRecognizer.state == UIGestureRecognizerStateEnded) {
  1143. _currentPanType = VLCPanTypeNone;
  1144. //Invalidate saved location when the gesture is ended
  1145. if (_mediaHasProjection)
  1146. _saveLocation = CGPointMake(-1.f, -1.f);
  1147. }
  1148. }
  1149. - (void)swipeRecognized:(UISwipeGestureRecognizer*)swipeRecognizer
  1150. {
  1151. LOCKCHECK;
  1152. if (!_seekGestureEnabled)
  1153. return;
  1154. NSString * hudString = @" ";
  1155. int swipeForwardDuration = (_variableJumpDurationEnabled) ? ((int)(_mediaDuration*0.001*0.05)) : FORWARD_SWIPE_DURATION;
  1156. int swipeBackwardDuration = (_variableJumpDurationEnabled) ? ((int)(_mediaDuration*0.001*0.05)) : BACKWARD_SWIPE_DURATION;
  1157. if (swipeRecognizer.direction == UISwipeGestureRecognizerDirectionRight) {
  1158. double timeRemainingDouble = (-[_vpc remainingTime].intValue*0.001);
  1159. int timeRemaining = timeRemainingDouble;
  1160. if (swipeForwardDuration < timeRemaining) {
  1161. if (swipeForwardDuration < 1)
  1162. swipeForwardDuration = 1;
  1163. [_vpc jumpForward:swipeForwardDuration];
  1164. hudString = [NSString stringWithFormat:@"⇒ %is", swipeForwardDuration];
  1165. } else {
  1166. [_vpc jumpForward:(timeRemaining - 5)];
  1167. hudString = [NSString stringWithFormat:@"⇒ %is",(timeRemaining - 5)];
  1168. }
  1169. }
  1170. else if (swipeRecognizer.direction == UISwipeGestureRecognizerDirectionLeft) {
  1171. [_vpc jumpBackward:swipeBackwardDuration];
  1172. hudString = [NSString stringWithFormat:@"⇐ %is",swipeBackwardDuration];
  1173. }else if (swipeRecognizer.direction == UISwipeGestureRecognizerDirectionUp) {
  1174. [self backward:self];
  1175. }
  1176. else if (swipeRecognizer.direction == UISwipeGestureRecognizerDirectionDown) {
  1177. [self forward:self];
  1178. }
  1179. if (swipeRecognizer.state == UIGestureRecognizerStateEnded) {
  1180. [self.statusLabel showStatusMessage:hudString];
  1181. }
  1182. }
  1183. - (void)tapToSeekRecognized:(UITapGestureRecognizer *)tapRecognizer
  1184. {
  1185. LOCKCHECK;
  1186. if (!_seekGestureEnabled)
  1187. return;
  1188. CGFloat screenHalf;
  1189. CGFloat tmpPosition;
  1190. CGSize size = self.view.frame.size;
  1191. CGPoint tapPosition = [tapRecognizer locationInView:self.view];
  1192. screenHalf = size.width / 2;
  1193. tmpPosition = tapPosition.x;
  1194. //Handling seek reset if tap orientation changes.
  1195. if (tmpPosition < screenHalf) {
  1196. _numberOfTapSeek = _previousJumpState == VLCMovieJumpStateForward ? -1 : _numberOfTapSeek - 1;
  1197. } else {
  1198. _numberOfTapSeek = _previousJumpState == VLCMovieJumpStateBackward ? 1 : _numberOfTapSeek + 1;
  1199. }
  1200. _isTapSeeking = YES;
  1201. [self _seekFromTap];
  1202. }
  1203. - (void)equalizerViewReceivedUserInput
  1204. {
  1205. [self _resetIdleTimer];
  1206. }
  1207. #pragma mark - Video Filter UI
  1208. - (IBAction)videoFilterToggle:(id)sender
  1209. {
  1210. LOCKCHECK;
  1211. if (!_playbackSpeedViewHidden)
  1212. self.playbackSpeedView.hidden = _playbackSpeedViewHidden = YES;
  1213. if (_equalizerView.hidden == NO)
  1214. _equalizerView.hidden = YES;
  1215. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
  1216. if (!_controlsHidden) {
  1217. self.controllerPanel.hidden = _controlsHidden = YES;
  1218. }
  1219. }
  1220. self.videoFilterView.hidden = !_videoFiltersHidden;
  1221. _videoFiltersHidden = self.videoFilterView.hidden;
  1222. }
  1223. - (IBAction)videoFilterSliderAction:(id)sender
  1224. {
  1225. if (sender == self.hueSlider)
  1226. _vpc.hue = self.hueSlider.value;
  1227. else if (sender == self.contrastSlider)
  1228. _vpc.contrast = self.contrastSlider.value;
  1229. else if (sender == self.brightnessSlider)
  1230. _vpc.brightness = self.brightnessSlider.value;
  1231. else if (sender == self.saturationSlider)
  1232. _vpc.saturation = self.saturationSlider.value;
  1233. else if (sender == self.gammaSlider)
  1234. _vpc.gamma = self.gammaSlider.value;
  1235. else if (sender == self.resetVideoFilterButton) {
  1236. [self resetVideoFiltersSliders];
  1237. [_vpc resetFilters];
  1238. } else
  1239. APLog(@"unknown sender for videoFilterSliderAction");
  1240. [self _resetIdleTimer];
  1241. }
  1242. - (void)appBecameActive:(NSNotification *)aNotification
  1243. {
  1244. VLCPlayerDisplayController *pdc = [VLCPlayerDisplayController sharedInstance];
  1245. if (pdc.displayMode == VLCPlayerDisplayControllerDisplayModeFullscreen) {
  1246. [_vpc recoverDisplayedMetadata];
  1247. if (_vpc.videoOutputView != self.movieView) {
  1248. _vpc.videoOutputView = self.movieView;
  1249. }
  1250. }
  1251. }
  1252. #pragma mark - playback view
  1253. - (IBAction)playbackSliderAction:(UISlider *)sender
  1254. {
  1255. LOCKCHECK;
  1256. if (sender == _playbackSpeedSlider) {
  1257. double speed = exp2(sender.value);
  1258. _vpc.playbackRate = speed;
  1259. self.playbackSpeedIndicator.text = [NSString stringWithFormat:@"%.2fx", speed];
  1260. } else if (sender == _audioDelaySlider) {
  1261. double delay = sender.value;
  1262. _vpc.audioDelay = delay;
  1263. _audioDelayIndicator.text = [NSString stringWithFormat:@"%1.2f s", delay];
  1264. } else if (sender == _spuDelaySlider) {
  1265. double delay = sender.value;
  1266. _vpc.subtitleDelay = delay;
  1267. _spuDelayIndicator.text = [NSString stringWithFormat:@"%1.00f s", delay];
  1268. }
  1269. [self _resetIdleTimer];
  1270. }
  1271. - (IBAction)videoDimensionAction:(id)sender
  1272. {
  1273. if (sender == self.timeNavigationTitleView.aspectRatioButton) {
  1274. [[VLCPlaybackController sharedInstance] switchAspectRatio];
  1275. }
  1276. }
  1277. - (IBAction)showPlaybackSpeedView {
  1278. LOCKCHECK;
  1279. if (!_videoFiltersHidden)
  1280. self.videoFilterView.hidden = _videoFiltersHidden = YES;
  1281. if (_equalizerView.hidden == NO)
  1282. _equalizerView.hidden = YES;
  1283. self.playbackSpeedView.hidden = !_playbackSpeedViewHidden;
  1284. _playbackSpeedViewHidden = self.playbackSpeedView.hidden;
  1285. [self _resetIdleTimer];
  1286. }
  1287. #pragma mark - autorotation
  1288. - (BOOL)rotationIsDisabled
  1289. {
  1290. return _interfaceIsLocked;
  1291. }
  1292. - (BOOL)shouldAutorotate
  1293. {
  1294. UIInterfaceOrientation toInterfaceOrientation = [[UIApplication sharedApplication] statusBarOrientation];
  1295. return UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad
  1296. || toInterfaceOrientation != UIInterfaceOrientationPortraitUpsideDown;
  1297. }
  1298. // < iOS 8
  1299. - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
  1300. {
  1301. [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
  1302. if (self.artworkImageView.image)
  1303. self.trackNameLabel.hidden = UIInterfaceOrientationIsLandscape(toInterfaceOrientation);
  1304. if (!_equalizerView.hidden)
  1305. _equalizerView.hidden = YES;
  1306. }
  1307. - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
  1308. {
  1309. if (_vpc.isPlaying && _controlsHidden)
  1310. [self setControlsHidden:NO animated:YES];
  1311. }
  1312. // >= iOS 8
  1313. - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
  1314. {
  1315. [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
  1316. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
  1317. [coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
  1318. if (self.artworkImageView.image)
  1319. self.trackNameLabel.hidden = YES;
  1320. if (!_equalizerView.hidden)
  1321. _equalizerView.hidden = YES;
  1322. } completion:nil];
  1323. }
  1324. }
  1325. - (void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection
  1326. {
  1327. if (_vpc.isPlaying && _controlsHidden)
  1328. [self setControlsHidden:NO animated:YES];
  1329. }
  1330. #pragma mark - External Display
  1331. - (void)showOnExternalDisplay
  1332. {
  1333. UIScreen *screen = [UIScreen screens][1];
  1334. screen.overscanCompensation = UIScreenOverscanCompensationInsetApplicationFrame;
  1335. self.externalWindow = [[UIWindow alloc] initWithFrame:screen.bounds];
  1336. UIViewController *controller = [[VLCExternalDisplayController alloc] init];
  1337. self.externalWindow.rootViewController = controller;
  1338. [controller.view addSubview:_movieView];
  1339. controller.view.frame = screen.bounds;
  1340. _movieView.frame = screen.bounds;
  1341. self.playingExternallyView.hidden = NO;
  1342. self.externalWindow.screen = screen;
  1343. self.externalWindow.hidden = NO;
  1344. }
  1345. - (void)hideFromExternalDisplay
  1346. {
  1347. [self.view addSubview:_movieView];
  1348. [self.view sendSubviewToBack:_movieView];
  1349. _movieView.frame = self.view.frame;
  1350. self.playingExternallyView.hidden = YES;
  1351. self.externalWindow.hidden = YES;
  1352. self.externalWindow = nil;
  1353. }
  1354. - (void)handleExternalScreenDidConnect:(NSNotification *)notification
  1355. {
  1356. [self showOnExternalDisplay];
  1357. }
  1358. - (void)handleExternalScreenDidDisconnect:(NSNotification *)notification
  1359. {
  1360. [self hideFromExternalDisplay];
  1361. }
  1362. @end