VLCMovieViewController.m 62 KB

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