VLCMovieViewController.m 62 KB

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