VLCMovieViewController.m 62 KB

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