VLCMovieViewController.m 64 KB

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