VLCMovieViewController.m 61 KB

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