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