VLCMovieViewController.m 70 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896
  1. /*****************************************************************************
  2. * VLCMovieViewController.m
  3. * VLC for iOS
  4. *****************************************************************************
  5. * Copyright (c) 2013-2018 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. * Andrew Breckenridge <asbreckenridge # me dot com>
  20. *
  21. * Refer to the COPYING file of the official project for license.
  22. *****************************************************************************/
  23. #import "VLCMovieViewController.h"
  24. #import "VLCEqualizerView.h"
  25. #import "VLCMultiSelectionMenuView.h"
  26. #import "VLCPlaybackController.h"
  27. #import "VLCTimeNavigationTitleView.h"
  28. #import "VLCAppDelegate.h"
  29. #import "VLCStatusLabel.h"
  30. #import "VLCMovieViewControlPanelView.h"
  31. #import "VLCSlider.h"
  32. #import "VLCTrackSelectorView.h"
  33. #import "VLCMetadata.h"
  34. #import "UIDevice+VLC.h"
  35. #import "VLC-Swift.h"
  36. #define FORWARD_SWIPE_DURATION 30
  37. #define BACKWARD_SWIPE_DURATION 10
  38. #define SHORT_JUMP_DURATION 10
  39. #define ZOOM_SENSITIVITY 5.f
  40. #define DEFAULT_FOV 80.f
  41. #define MAX_FOV 150.f
  42. #define MIN_FOV 20.f
  43. #define NEW_UI 0
  44. typedef NS_ENUM(NSInteger, VLCPanType) {
  45. VLCPanTypeNone,
  46. VLCPanTypeBrightness,
  47. VLCPanTypeSeek,
  48. VLCPanTypeVolume,
  49. VLCPanTypeProjection
  50. };
  51. @interface VLCMovieViewController () <UIGestureRecognizerDelegate, VLCMultiSelectionViewDelegate, VLCEqualizerViewUIDelegate, VLCPlaybackControllerDelegate, VLCDeviceMotionDelegate, VLCRendererDiscovererManagerDelegate, PlaybackSpeedViewDelegate, VLCVideoOptionsControlBarDelegate>
  52. {
  53. BOOL _controlsHidden;
  54. BOOL _videoFiltersHidden;
  55. BOOL _playbackSpeedViewHidden;
  56. NSTimer *_idleTimer;
  57. BOOL _viewAppeared;
  58. BOOL _displayRemainingTime;
  59. BOOL _positionSet;
  60. BOOL _isScrubbing;
  61. BOOL _interfaceIsLocked;
  62. BOOL _audioOnly;
  63. BOOL _volumeGestureEnabled;
  64. BOOL _playPauseGestureEnabled;
  65. BOOL _brightnessGestureEnabled;
  66. BOOL _seekGestureEnabled;
  67. BOOL _closeGestureEnabled;
  68. BOOL _variableJumpDurationEnabled;
  69. BOOL _playbackWillClose;
  70. BOOL _isTapSeeking;
  71. VLCMovieJumpState _previousJumpState;
  72. VLCMediaPlayerState _previousPlayerStateWasPaused;
  73. UIPinchGestureRecognizer *_pinchRecognizer;
  74. VLCPanType _currentPanType;
  75. UIPanGestureRecognizer *_panRecognizer;
  76. UISwipeGestureRecognizer *_swipeRecognizerLeft;
  77. UISwipeGestureRecognizer *_swipeRecognizerRight;
  78. UISwipeGestureRecognizer *_swipeRecognizerUp;
  79. UISwipeGestureRecognizer *_swipeRecognizerDown;
  80. UITapGestureRecognizer *_tapRecognizer;
  81. UITapGestureRecognizer *_tapOnVideoRecognizer;
  82. UITapGestureRecognizer *_doubleTapRecognizer;
  83. UIButton *_doneButton;
  84. VLCTrackSelectorView *_trackSelectorContainer;
  85. VLCEqualizerView *_equalizerView;
  86. VLCMultiSelectionMenuView *_multiSelectionView;
  87. VLCVideoOptionsControlBar *_videoOptionsControlBar;
  88. VLCPlaybackController *_vpc;
  89. UIView *_sleepTimerContainer;
  90. UIDatePicker *_sleepTimeDatePicker;
  91. NSInteger _mediaDuration;
  92. NSInteger _numberOfTapSeek;
  93. VLCDeviceMotion *_deviceMotion;
  94. CGFloat _fov;
  95. CGPoint _saveLocation;
  96. CGSize _screenPixelSize;
  97. UIInterfaceOrientation _lockedOrientation;
  98. UIStackView *_navigationBarStackView;
  99. UIButton *_rendererButton;
  100. }
  101. @property (nonatomic, strong) VLCMovieViewControlPanelView *controllerPanel;
  102. @property (nonatomic, strong) VLCService *services;
  103. @property (nonatomic, strong) VLCTimeNavigationTitleView *timeNavigationTitleView;
  104. @property (nonatomic, strong) IBOutlet PlayingExternallyView *playingExternalView;
  105. @property (nonatomic, strong) IBOutlet PlaybackSpeedView *playbackSpeedView;
  106. @property (nonatomic, strong) IBOutlet NSLayoutConstraint *scrubViewTopConstraint;
  107. @end
  108. @implementation VLCMovieViewController
  109. + (void)initialize
  110. {
  111. NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
  112. NSDictionary *appDefaults = @{kVLCShowRemainingTime : @(YES)};
  113. [defaults registerDefaults:appDefaults];
  114. }
  115. - (instancetype)initWithServices:(VLCService *)services
  116. {
  117. self = [super initWithNibName:nil bundle:nil];
  118. if (self) {
  119. NSAssert([services isKindOfClass:[VLCService class]], @"VLCPlayerDisplayController: Injected services class issue");
  120. _services = services;
  121. }
  122. return self;
  123. }
  124. - (void)viewDidLoad
  125. {
  126. [super viewDidLoad];
  127. _vpc = [VLCPlaybackController sharedInstance];
  128. self.extendedLayoutIncludesOpaqueBars = YES;
  129. self.edgesForExtendedLayout = UIRectEdgeAll;
  130. self.videoFilterView.hidden = YES;
  131. _videoFiltersHidden = YES;
  132. _hueLabel.text = NSLocalizedString(@"VFILTER_HUE", nil);
  133. _hueSlider.accessibilityLabel = _hueLabel.text;
  134. _contrastLabel.text = NSLocalizedString(@"VFILTER_CONTRAST", nil);
  135. _contrastSlider.accessibilityLabel = _contrastLabel.text;
  136. _brightnessLabel.text = NSLocalizedString(@"VFILTER_BRIGHTNESS", nil);
  137. _brightnessSlider.accessibilityLabel = _brightnessLabel.text;
  138. _saturationLabel.text = NSLocalizedString(@"VFILTER_SATURATION", nil);
  139. _saturationSlider.accessibilityLabel = _saturationLabel.text;
  140. _gammaLabel.text = NSLocalizedString(@"VFILTER_GAMMA", nil);
  141. _gammaSlider.accessibilityLabel = _gammaLabel.text;
  142. _resetVideoFilterButton.accessibilityLabel = NSLocalizedString(@"VIDEO_FILTER_RESET_BUTTON", nil);
  143. #if !NEW_UI
  144. [self setupMultiSelectionView];
  145. #else
  146. [self setupVideoOptionsControlBar];
  147. #endif
  148. _scrubHelpLabel.text = NSLocalizedString(@"PLAYBACK_SCRUB_HELP", nil);
  149. self.playbackSpeedView.hidden = YES;
  150. _playbackSpeedViewHidden = YES;
  151. _playbackSpeedView.delegate = self;
  152. NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
  153. [center addObserver:self selector:@selector(handleExternalScreenDidConnect:)
  154. name:UIScreenDidConnectNotification object:nil];
  155. [center addObserver:self selector:@selector(handleExternalScreenDidDisconnect:)
  156. name:UIScreenDidDisconnectNotification object:nil];
  157. [center addObserver:self
  158. selector:@selector(appBecameActive:)
  159. name:UIApplicationDidBecomeActiveNotification
  160. object:nil];
  161. [center addObserver:self
  162. selector:@selector(playbackDidStop:)
  163. name:VLCPlaybackControllerPlaybackDidStop
  164. object:nil];
  165. self.trackNameLabel.text = self.artistNameLabel.text = self.albumNameLabel.text = @"";
  166. _movieView.userInteractionEnabled = NO;
  167. [self setupGestureRecognizers];
  168. _isTapSeeking = NO;
  169. _previousJumpState = VLCMovieJumpStateDefault;
  170. _numberOfTapSeek = 0;
  171. CGRect rect = self.resetVideoFilterButton.frame;
  172. rect.origin.y = rect.origin.y + 5.;
  173. self.resetVideoFilterButton.frame = rect;
  174. if (@available(iOS 11.0, *)) {
  175. [self.movieView setAccessibilityIgnoresInvertColors:YES];
  176. }
  177. [self.movieView setAccessibilityIdentifier:@"Video Player Title"];
  178. [self.movieView setAccessibilityLabel:NSLocalizedString(@"VO_VIDEOPLAYER_TITLE", nil)];
  179. [self.movieView setAccessibilityHint:NSLocalizedString(@"VO_VIDEOPLAYER_DOUBLETAP", nil)];
  180. _trackSelectorContainer = [[VLCTrackSelectorView alloc] initWithFrame:CGRectZero];
  181. _trackSelectorContainer.hidden = YES;
  182. void (^completionBlock)(BOOL finished) = ^(BOOL finished) {
  183. for (UIGestureRecognizer *recognizer in self.view.gestureRecognizers)
  184. [recognizer setEnabled:YES];
  185. self->_trackSelectorContainer.hidden = YES;
  186. };
  187. _trackSelectorContainer.completionHandler = completionBlock;
  188. _trackSelectorContainer.translatesAutoresizingMaskIntoConstraints = NO;
  189. [self.view addSubview:_trackSelectorContainer];
  190. _equalizerView = [[VLCEqualizerView alloc] initWithFrame:CGRectMake(0, 0, 450., 240.)];
  191. _equalizerView.delegate = [VLCPlaybackController sharedInstance];
  192. _equalizerView.UIdelegate = self;
  193. _equalizerView.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleTopMargin;
  194. _equalizerView.hidden = YES;
  195. [self.view addSubview:_equalizerView];
  196. //Sleep Timer initialization
  197. [self sleepTimerInitializer];
  198. [self setupControlPanel];
  199. CGRect screenBounds = [[UIScreen mainScreen] bounds];
  200. _screenPixelSize = CGSizeMake(screenBounds.size.width, screenBounds.size.height);
  201. [self setupConstraints];
  202. [self setupRendererDiscovererManager];
  203. }
  204. - (void) setupMultiSelectionView
  205. {
  206. _multiSelectionView = [[VLCMultiSelectionMenuView alloc] init];
  207. _multiSelectionView.delegate = self;
  208. _multiSelectionView.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin;
  209. _multiSelectionView.hidden = YES;
  210. _multiSelectionView.repeatMode = _vpc.repeatMode;
  211. [self.view addSubview:_multiSelectionView];
  212. }
  213. - (void)setupVideoOptionsControlBar
  214. {
  215. _videoOptionsControlBar = [[VLCVideoOptionsControlBar alloc] init];
  216. _videoOptionsControlBar.delegate = self;
  217. _videoOptionsControlBar.hidden = YES;
  218. _videoOptionsControlBar.repeatMode = _vpc.repeatMode;
  219. [self.view addSubview:_videoOptionsControlBar];
  220. }
  221. - (void)setupGestureRecognizers
  222. {
  223. _tapOnVideoRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(toggleControlsVisible)];
  224. _tapOnVideoRecognizer.delegate = self;
  225. [self.view addGestureRecognizer:_tapOnVideoRecognizer];
  226. _pinchRecognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(handlePinchGesture:)];
  227. _pinchRecognizer.delegate = self;
  228. _doubleTapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doubleTapRecognized:)];
  229. [_doubleTapRecognizer setNumberOfTapsRequired:2];
  230. [self.view addGestureRecognizer:_doubleTapRecognizer];
  231. [_tapOnVideoRecognizer requireGestureRecognizerToFail:_doubleTapRecognizer];
  232. _tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(togglePlayPause)];
  233. [_tapRecognizer setNumberOfTouchesRequired:2];
  234. _currentPanType = VLCPanTypeNone;
  235. _panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panRecognized:)];
  236. [_panRecognizer setMinimumNumberOfTouches:1];
  237. [_panRecognizer setMaximumNumberOfTouches:1];
  238. _swipeRecognizerLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeRecognized:)];
  239. _swipeRecognizerLeft.direction = UISwipeGestureRecognizerDirectionLeft;
  240. _swipeRecognizerRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeRecognized:)];
  241. _swipeRecognizerRight.direction = UISwipeGestureRecognizerDirectionRight;
  242. _swipeRecognizerUp = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeRecognized:)];
  243. _swipeRecognizerUp.direction = UISwipeGestureRecognizerDirectionUp;
  244. _swipeRecognizerUp.numberOfTouchesRequired = 2;
  245. _swipeRecognizerDown = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeRecognized:)];
  246. _swipeRecognizerDown.direction = UISwipeGestureRecognizerDirectionDown;
  247. _swipeRecognizerDown.numberOfTouchesRequired = 2;
  248. [self.view addGestureRecognizer:_pinchRecognizer];
  249. [self.view addGestureRecognizer:_swipeRecognizerLeft];
  250. [self.view addGestureRecognizer:_swipeRecognizerRight];
  251. [self.view addGestureRecognizer:_swipeRecognizerUp];
  252. [self.view addGestureRecognizer:_swipeRecognizerDown];
  253. [self.view addGestureRecognizer:_panRecognizer];
  254. [self.view addGestureRecognizer:_tapRecognizer];
  255. [_panRecognizer requireGestureRecognizerToFail:_swipeRecognizerLeft];
  256. [_panRecognizer requireGestureRecognizerToFail:_swipeRecognizerRight];
  257. [_panRecognizer requireGestureRecognizerToFail:_swipeRecognizerUp];
  258. [_panRecognizer requireGestureRecognizerToFail:_swipeRecognizerDown];
  259. _panRecognizer.delegate = self;
  260. _swipeRecognizerRight.delegate = self;
  261. _swipeRecognizerLeft.delegate = self;
  262. _swipeRecognizerUp.delegate = self;
  263. _swipeRecognizerDown.delegate = self;
  264. _tapRecognizer.delegate = self;
  265. _doubleTapRecognizer.delegate = self;
  266. }
  267. - (void)setupControlPanel
  268. {
  269. _controllerPanel = [[VLCMovieViewControlPanelView alloc] initWithFrame:CGRectZero];
  270. [_controllerPanel.bwdButton addTarget:self action:@selector(backward:) forControlEvents:UIControlEventTouchUpInside];
  271. [_controllerPanel.fwdButton addTarget:self action:@selector(forward:) forControlEvents:UIControlEventTouchUpInside];
  272. [_controllerPanel.playPauseButton addTarget:self action:@selector(playPause) forControlEvents:UIControlEventTouchUpInside];
  273. [_controllerPanel.moreActionsButton addTarget:self action:@selector(moreActions:) forControlEvents:UIControlEventTouchUpInside];
  274. [_controllerPanel.playbackSpeedButton addTarget:self action:@selector(showPlaybackSpeedView) forControlEvents:UIControlEventTouchUpInside];
  275. [_controllerPanel.trackSwitcherButton addTarget:self action:@selector(switchTrack:) forControlEvents:UIControlEventTouchUpInside];
  276. [_controllerPanel.videoFilterButton addTarget:self action:@selector(videoFilterToggle:) forControlEvents:UIControlEventTouchUpInside];
  277. // HACK: get the slider from volume view
  278. UISlider *volumeSlider = nil;
  279. for (id aView in _controllerPanel.volumeView.subviews){
  280. if ([aView isKindOfClass:[UISlider class]]){
  281. volumeSlider = (UISlider *)aView;
  282. break;
  283. }
  284. }
  285. [volumeSlider addTarget:self action:@selector(volumeSliderAction:) forControlEvents:UIControlEventValueChanged];
  286. _controllerPanel.translatesAutoresizingMaskIntoConstraints = NO;
  287. [self.view addSubview:_controllerPanel];
  288. }
  289. - (void)setupConstraints
  290. {
  291. NSArray *hConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|[panel]|"
  292. options:0
  293. metrics:nil
  294. views:@{@"panel":_controllerPanel}];
  295. NSArray *vConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"V:[panel]|"
  296. options:0
  297. metrics:nil
  298. views:@{@"panel":_controllerPanel}];
  299. [self.view addConstraints:hConstraints];
  300. [self.view addConstraints:vConstraints];
  301. //constraint within _trackSelectorContainer is setting it's height to the tableviews contentview
  302. NSLayoutConstraint *widthConstraint = [NSLayoutConstraint constraintWithItem:_trackSelectorContainer attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeWidth multiplier:2.0/3.0 constant:0];
  303. widthConstraint.priority = UILayoutPriorityRequired - 1;
  304. NSArray *constraints = @[
  305. [NSLayoutConstraint constraintWithItem:_trackSelectorContainer attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterX multiplier:1 constant:0],
  306. [NSLayoutConstraint constraintWithItem:_trackSelectorContainer attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterY multiplier:1 constant:0],
  307. [NSLayoutConstraint constraintWithItem:_trackSelectorContainer attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationLessThanOrEqual toItem:nil attribute:NSLayoutAttributeWidth multiplier:1 constant:420.0],
  308. widthConstraint,
  309. [NSLayoutConstraint constraintWithItem:_trackSelectorContainer attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationLessThanOrEqual toItem:self.view attribute:NSLayoutAttributeHeight multiplier:2.0/3.0 constant:0],
  310. [_videoFilterView.bottomAnchor constraintEqualToAnchor:_controllerPanel.topAnchor]
  311. ];
  312. #if NEW_UI
  313. constraints = [constraints arrayByAddingObjectsFromArray:[self getVideoOptionsConstraints]];
  314. #endif
  315. [NSLayoutConstraint activateConstraints: constraints];
  316. }
  317. - (UIButton *)doneButton
  318. {
  319. if (!_doneButton) {
  320. _doneButton = [[UIButton alloc] initWithFrame:CGRectZero];
  321. [_doneButton setAccessibilityIdentifier:@"Done"];
  322. [_doneButton addTarget:self action:@selector(closePlayback:) forControlEvents:UIControlEventTouchUpInside];
  323. [_doneButton setTitle:NSLocalizedString(@"BUTTON_DONE", nil) forState:UIControlStateNormal];
  324. [_doneButton setTitleColor:[UIColor grayColor] forState:UIControlStateDisabled];
  325. _doneButton.translatesAutoresizingMaskIntoConstraints = NO;
  326. }
  327. return _doneButton;
  328. }
  329. - (UIStackView *)navigationBarStackView
  330. {
  331. if (!_navigationBarStackView) {
  332. _navigationBarStackView = [[UIStackView alloc] init];
  333. _navigationBarStackView.translatesAutoresizingMaskIntoConstraints = NO;
  334. _navigationBarStackView.spacing = 8;
  335. _navigationBarStackView.axis = UILayoutConstraintAxisHorizontal;
  336. _navigationBarStackView.alignment = UIStackViewAlignmentCenter;
  337. [_navigationBarStackView addArrangedSubview:self.doneButton];
  338. [_navigationBarStackView addArrangedSubview:_timeNavigationTitleView];
  339. [_navigationBarStackView addArrangedSubview:_rendererButton];
  340. }
  341. return _navigationBarStackView;
  342. }
  343. - (void)setupNavigationbar
  344. {
  345. if (!self.timeNavigationTitleView) {
  346. self.timeNavigationTitleView = [[[NSBundle mainBundle] loadNibNamed:@"VLCTimeNavigationTitleView" owner:self options:nil] objectAtIndex:0];
  347. self.timeNavigationTitleView.translatesAutoresizingMaskIntoConstraints = NO;
  348. }
  349. if (_vpc.renderer != nil) {
  350. [_rendererButton setSelected:YES];
  351. }
  352. if (self.navigationBarStackView.superview == nil) {
  353. [self.navigationController.navigationBar addSubview:self.navigationBarStackView];
  354. NSObject *guide = self.navigationController.navigationBar;
  355. if (@available(iOS 11.0, *)) {
  356. guide = self.navigationController.navigationBar.layoutMarginsGuide;
  357. }
  358. [NSLayoutConstraint activateConstraints:@[
  359. [NSLayoutConstraint constraintWithItem:self.navigationBarStackView attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self.navigationController.navigationBar attribute:NSLayoutAttributeCenterY multiplier:1 constant:0],
  360. [NSLayoutConstraint constraintWithItem:self.navigationBarStackView attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:guide attribute:NSLayoutAttributeLeft multiplier:1 constant:8],
  361. [NSLayoutConstraint constraintWithItem:self.navigationBarStackView attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:guide attribute:NSLayoutAttributeRight multiplier:1 constant:-8],
  362. [NSLayoutConstraint constraintWithItem:self.navigationBarStackView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.navigationController.navigationBar attribute:NSLayoutAttributeTop multiplier:1 constant:0],
  363. [NSLayoutConstraint constraintWithItem:self.navigationBarStackView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.navigationController.navigationBar attribute:NSLayoutAttributeBottom multiplier:1 constant:0],
  364. [NSLayoutConstraint constraintWithItem:self.timeNavigationTitleView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:self.navigationBarStackView attribute:NSLayoutAttributeHeight multiplier:1 constant:0],
  365. ]];
  366. self.scrubViewTopConstraint.constant = CGRectGetMaxY(self.navigationController.navigationBar.frame);
  367. }
  368. }
  369. - (void)resetVideoFiltersSliders
  370. {
  371. _brightnessSlider.value = 1.;
  372. _contrastSlider.value = 1.;
  373. _hueSlider.value = 0.;
  374. _saturationSlider.value = 1.;
  375. _gammaSlider.value = 1.;
  376. }
  377. - (void)viewWillAppear:(BOOL)animated
  378. {
  379. [super viewWillAppear:animated];
  380. _vpc.delegate = self;
  381. _lockedOrientation = UIInterfaceOrientationPortrait;
  382. [_vpc recoverPlaybackState];
  383. self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
  384. self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
  385. [self setupNavigationbar];
  386. /* reset audio meta data views */
  387. self.artworkImageView.image = nil;
  388. self.trackNameLabel.text = nil;
  389. self.artistNameLabel.text = nil;
  390. self.albumNameLabel.text = nil;
  391. [self setControlsHidden:NO animated:animated];
  392. [self updateDefaults];
  393. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateDefaults) name:NSUserDefaultsDidChangeNotification object:nil];
  394. VLCRendererDiscovererManager *manager = _services.rendererDiscovererManager;
  395. manager.presentingViewController = self;
  396. manager.delegate = self;
  397. if ([_vpc isPlayingOnExternalScreen]) {
  398. [self showOnDisplay:_playingExternalView.displayView];
  399. }
  400. }
  401. - (void)layoutFrameForMultiSelectionView
  402. {
  403. CGRect controllerPanelFrame = _controllerPanel.frame;
  404. CGRect multiSelectionFrame;
  405. BOOL isIphone = (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone);
  406. if (!isIphone) {
  407. _multiSelectionView.showsEqualizer = YES;
  408. return;
  409. }
  410. BOOL isLandscape = UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation]);
  411. _multiSelectionView.showsEqualizer = isLandscape;
  412. multiSelectionFrame = (CGRect){CGPointMake(0., 0.), [_multiSelectionView proposedDisplaySize]};
  413. multiSelectionFrame.origin.x = controllerPanelFrame.size.width - multiSelectionFrame.size.width;
  414. multiSelectionFrame.origin.y = controllerPanelFrame.origin.y - multiSelectionFrame.size.height;
  415. _multiSelectionView.frame = multiSelectionFrame;
  416. }
  417. - (void)viewDidAppear:(BOOL)animated
  418. {
  419. [super viewDidAppear:animated];
  420. _viewAppeared = YES;
  421. _playbackWillClose = NO;
  422. [_vpc recoverDisplayedMetadata];
  423. [self resetVideoFiltersSliders];
  424. _vpc.videoOutputView = self.movieView;
  425. #if !NEW_UI
  426. _multiSelectionView.repeatMode = _vpc.repeatMode;
  427. _multiSelectionView.shuffleMode = _vpc.isShuffleMode;
  428. #else
  429. _videoOptionsControlBar.repeatMode = _vpc.repeatMode;
  430. #endif
  431. //Media is loaded in the media player, checking the projection type and configuring accordingly.
  432. [self setupForMediaProjection];
  433. }
  434. - (void)viewDidLayoutSubviews
  435. {
  436. CGRect equalizerRect = _equalizerView.frame;
  437. equalizerRect.origin.x = CGRectGetMidX(self.view.bounds) - CGRectGetWidth(equalizerRect)/2.0;
  438. equalizerRect.origin.y = CGRectGetMidY(self.view.bounds) - CGRectGetHeight(equalizerRect)/2.0;
  439. _equalizerView.frame = equalizerRect;
  440. #if !NEW_UI
  441. [self layoutFrameForMultiSelectionView];
  442. #endif
  443. self.scrubViewTopConstraint.constant = CGRectGetMaxY(self.navigationController.navigationBar.frame);
  444. }
  445. - (void)viewWillDisappear:(BOOL)animated
  446. {
  447. if (_vpc.videoOutputView == self.movieView) {
  448. _vpc.videoOutputView = nil;
  449. }
  450. _viewAppeared = NO;
  451. if (_idleTimer) {
  452. [_idleTimer invalidate];
  453. _idleTimer = nil;
  454. }
  455. [super viewWillDisappear:animated];
  456. // hide filter UI for next run
  457. if (!_videoFiltersHidden)
  458. _videoFiltersHidden = YES;
  459. if (_equalizerView.hidden == NO)
  460. _equalizerView.hidden = YES;
  461. if (!_playbackSpeedViewHidden)
  462. _playbackSpeedViewHidden = YES;
  463. if (_interfaceIsLocked)
  464. [self toggleUILock];
  465. // reset tap to seek values
  466. _isTapSeeking = NO;
  467. _previousJumpState = VLCMovieJumpStateDefault;
  468. _numberOfTapSeek = 0;
  469. [[NSNotificationCenter defaultCenter] removeObserver:self name:NSUserDefaultsDidChangeNotification object:nil];
  470. [[NSUserDefaults standardUserDefaults] setBool:_displayRemainingTime forKey:kVLCShowRemainingTime];
  471. }
  472. - (void)viewDidDisappear:(BOOL)animated
  473. {
  474. [super viewDidDisappear:animated];
  475. [self.deviceMotion stopDeviceMotion];
  476. }
  477. - (BOOL)canBecomeFirstResponder
  478. {
  479. return YES;
  480. }
  481. - (void)dismissViewControllerAnimated:(BOOL)flag completion:(void (^)(void))completion
  482. {
  483. [self setControlsHidden:YES animated:flag];
  484. [super dismissViewControllerAnimated:flag completion:completion];
  485. }
  486. - (void)updateDefaults
  487. {
  488. NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
  489. if (!_playbackWillClose) {
  490. _displayRemainingTime = [[defaults objectForKey:kVLCShowRemainingTime] boolValue];
  491. [self updateTimeDisplayButton];
  492. }
  493. _volumeGestureEnabled = [[defaults objectForKey:kVLCSettingVolumeGesture] boolValue];
  494. _playPauseGestureEnabled = [[defaults objectForKey:kVLCSettingPlayPauseGesture] boolValue];
  495. _brightnessGestureEnabled = [[defaults objectForKey:kVLCSettingBrightnessGesture] boolValue];
  496. _seekGestureEnabled = [[defaults objectForKey:kVLCSettingSeekGesture] boolValue];
  497. _closeGestureEnabled = [[defaults objectForKey:kVLCSettingCloseGesture] boolValue];
  498. _variableJumpDurationEnabled = [[defaults objectForKey:kVLCSettingVariableJumpDuration] boolValue];
  499. }
  500. #pragma mark - Initializer helper
  501. - (void)sleepTimerInitializer
  502. {
  503. /* add sleep timer UI */
  504. _sleepTimerContainer = [[VLCFrostedGlasView alloc] initWithFrame:CGRectMake(0., 0., 300., 200.)];
  505. _sleepTimerContainer.center = self.view.center;
  506. _sleepTimerContainer.clipsToBounds = YES;
  507. _sleepTimerContainer.layer.cornerRadius = 5;
  508. _sleepTimerContainer.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleTopMargin;
  509. //Layers used to create a separator for the buttons.
  510. CALayer *horizontalSeparator = [CALayer layer];
  511. horizontalSeparator.frame = CGRectMake(0., 162., 300., 1.);
  512. horizontalSeparator.backgroundColor = [UIColor VLCLightTextColor].CGColor;
  513. CALayer *verticalSeparator = [CALayer layer];
  514. verticalSeparator.frame = CGRectMake(150., 162., 1., 48.);
  515. verticalSeparator.backgroundColor = [UIColor VLCLightTextColor].CGColor;
  516. _sleepTimeDatePicker = [[UIDatePicker alloc] init];
  517. _sleepTimeDatePicker.opaque = NO;
  518. _sleepTimeDatePicker.backgroundColor = [UIColor clearColor];
  519. _sleepTimeDatePicker.tintColor = [UIColor VLCLightTextColor];
  520. _sleepTimeDatePicker.frame = CGRectMake(0., 0., 300., 162.);
  521. _sleepTimeDatePicker.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleTopMargin;
  522. [_sleepTimerContainer addSubview:_sleepTimeDatePicker];
  523. [_sleepTimerContainer.layer addSublayer:horizontalSeparator];
  524. [_sleepTimerContainer.layer addSublayer:verticalSeparator];
  525. UIButton *cancelSleepTimer = [[UIButton alloc] initWithFrame:CGRectMake(0., 162., 150., 48.)];
  526. cancelSleepTimer.backgroundColor = [UIColor clearColor];
  527. [cancelSleepTimer setTitle:NSLocalizedString(@"BUTTON_RESET", nil) forState:UIControlStateNormal];
  528. [cancelSleepTimer setTintColor:[UIColor VLCLightTextColor]];
  529. [cancelSleepTimer setTitleColor:[UIColor VLCDarkTextShadowColor] forState:UIControlStateHighlighted];
  530. [cancelSleepTimer addTarget:self action:@selector(sleepTimerCancel:) forControlEvents:UIControlEventTouchDown];
  531. cancelSleepTimer.contentEdgeInsets = UIEdgeInsetsMake(0, 0, 10, 0);
  532. [_sleepTimerContainer addSubview:cancelSleepTimer];
  533. UIButton *confirmSleepTimer = [[UIButton alloc] initWithFrame:CGRectMake(150., 162., 150., 48.)];
  534. confirmSleepTimer.backgroundColor = [UIColor clearColor];
  535. [confirmSleepTimer setTitle:NSLocalizedString(@"BUTTON_SET", nil) forState:UIControlStateNormal];
  536. [confirmSleepTimer setTintColor:[UIColor VLCLightTextColor]];
  537. [confirmSleepTimer setTitleColor:[UIColor VLCDarkTextShadowColor] forState:UIControlStateHighlighted];
  538. [confirmSleepTimer addTarget:self action:@selector(sleepTimerAction:) forControlEvents:UIControlEventTouchDown];
  539. confirmSleepTimer.contentEdgeInsets = UIEdgeInsetsMake(0, 0, 10, 0);
  540. [_sleepTimerContainer addSubview:confirmSleepTimer];
  541. /* adapt the date picker style to suit our needs */
  542. [_sleepTimeDatePicker setValue:[UIColor whiteColor] forKeyPath:@"textColor"];
  543. SEL selector = NSSelectorFromString(@"setHighlightsToday:");
  544. NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[UIDatePicker instanceMethodSignatureForSelector:selector]];
  545. BOOL no = NO;
  546. [invocation setSelector:selector];
  547. [invocation setArgument:&no atIndex:2];
  548. [invocation invokeWithTarget:_sleepTimeDatePicker];
  549. if (_sleepTimerContainer.subviews.count > 0) {
  550. NSArray *subviewsOfSubview = [_sleepTimeDatePicker.subviews[0] subviews];
  551. NSUInteger subviewCount = subviewsOfSubview.count;
  552. for (NSUInteger x = 0; x < subviewCount; x++) {
  553. if ([subviewsOfSubview[x] isKindOfClass:[UILabel class]])
  554. [subviewsOfSubview[x] setTextColor:[UIColor VLCLightTextColor]];
  555. }
  556. }
  557. _sleepTimeDatePicker.datePickerMode = UIDatePickerModeCountDownTimer;
  558. _sleepTimeDatePicker.minuteInterval = 1;
  559. _sleepTimeDatePicker.minimumDate = [NSDate date];
  560. _sleepTimeDatePicker.countDownDuration = 1200.;
  561. [self.view addSubview:_sleepTimerContainer];
  562. }
  563. #pragma mark - controls visibility
  564. - (NSArray *)itemsForInterfaceLock
  565. {
  566. NSArray *arr = [NSArray arrayWithObjects:
  567. _pinchRecognizer,
  568. _panRecognizer,
  569. _tapRecognizer,
  570. _doneButton,
  571. _doubleTapRecognizer,
  572. _timeNavigationTitleView.minimizePlaybackButton,
  573. _timeNavigationTitleView.positionSlider,
  574. _timeNavigationTitleView.aspectRatioButton,
  575. _controllerPanel.playbackSpeedButton,
  576. _controllerPanel.trackSwitcherButton,
  577. _controllerPanel.bwdButton,
  578. _controllerPanel.playPauseButton,
  579. _controllerPanel.fwdButton,
  580. _controllerPanel.videoFilterButton,
  581. _controllerPanel.volumeView,
  582. _rendererButton,
  583. nil];
  584. #if !NEW_UI
  585. return [arr arrayByAddingObjectsFromArray:
  586. @[_multiSelectionView.equalizerButton,
  587. _multiSelectionView.chapterSelectorButton,
  588. _multiSelectionView.repeatButton,
  589. _multiSelectionView.shuffleButton,
  590. _controllerPanel.volumeView,
  591. _rendererButton]];
  592. #else
  593. return [arr arrayByAddingObjectsFromArray:
  594. @[_videoOptionsControlBar.toggleFullScreenButton,
  595. _videoOptionsControlBar.selectSubtitleButton,
  596. _videoOptionsControlBar.moreOptionsButton,
  597. _videoOptionsControlBar.repeatButton]];
  598. #endif
  599. }
  600. - (void)handlePinchGesture:(UIPinchGestureRecognizer *)recognizer
  601. {
  602. CGFloat diff = DEFAULT_FOV * -(ZOOM_SENSITIVITY * recognizer.velocity / _screenPixelSize.width);
  603. if ([_vpc currentMediaIs360Video]) {
  604. [self zoom360Video:diff];
  605. } else if (recognizer.velocity < 0. && _closeGestureEnabled) {
  606. [self minimizePlayback:nil];
  607. }
  608. }
  609. - (void)zoom360Video:(CGFloat)zoom
  610. {
  611. if ([_vpc updateViewpoint:0 pitch:0 roll:0 fov:zoom absolute:NO]) {
  612. //clamp Fov between min and max fov
  613. _fov = MAX(MIN(_fov + zoom, MAX_FOV), MIN_FOV);
  614. }
  615. }
  616. - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
  617. {
  618. if (touch.view != self.view)
  619. return NO;
  620. return YES;
  621. }
  622. - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
  623. {
  624. return YES;
  625. }
  626. - (void)setControlsHidden:(BOOL)hidden animated:(BOOL)animated
  627. {
  628. _controlsHidden = hidden;
  629. CGFloat alpha = _controlsHidden? 0.0f: 1.0f;
  630. if (!_controlsHidden) {
  631. self.navigationController.navigationBar.alpha = 0.0;
  632. self.navigationController.navigationBar.hidden = NO;
  633. _controllerPanel.alpha = 0.0f;
  634. _controllerPanel.hidden = !_videoFiltersHidden;
  635. _videoFilterView.alpha = 0.0f;
  636. _videoFilterView.hidden = _videoFiltersHidden;
  637. _playbackSpeedView.alpha = 0.0f;
  638. _playbackSpeedView.hidden = _playbackSpeedViewHidden;
  639. _trackSelectorContainer.alpha = 0.0f;
  640. _trackSelectorContainer.hidden = YES;
  641. _equalizerView.alpha = 0.0f;
  642. _equalizerView.hidden = YES;
  643. if (_sleepTimerContainer) {
  644. _sleepTimerContainer.alpha = 0.0f;
  645. _sleepTimerContainer.hidden = YES;
  646. }
  647. #if !NEW_UI
  648. _multiSelectionView.alpha = 0.0f;
  649. _multiSelectionView.hidden = YES;
  650. #else
  651. _videoOptionsControlBar.alpha = 0.0f;
  652. _videoOptionsControlBar.hidden = YES;
  653. #endif
  654. _artistNameLabel.hidden = NO;
  655. _albumNameLabel.hidden = NO;
  656. _trackNameLabel.hidden = NO;
  657. }
  658. void (^animationBlock)(void) = ^() {
  659. self.navigationController.navigationBar.alpha = alpha;
  660. self->_controllerPanel.alpha = alpha;
  661. self->_videoFilterView.alpha = alpha;
  662. self->_playbackSpeedView.alpha = alpha;
  663. self->_trackSelectorContainer.alpha = alpha;
  664. #if !NEW_UI
  665. self->_multiSelectionView.alpha = alpha;
  666. #else
  667. self->_videoOptionsControlBar.alpha = alpha;
  668. #endif
  669. self->_equalizerView.alpha = alpha;
  670. if (self->_sleepTimerContainer)
  671. self->_sleepTimerContainer.alpha = alpha;
  672. CGFloat metaInfoAlpha = self->_audioOnly ? 1.0f : alpha;
  673. self->_artistNameLabel.alpha = metaInfoAlpha;
  674. self->_albumNameLabel.alpha = metaInfoAlpha;
  675. self->_trackNameLabel.alpha = [self->_vpc isPlayingOnExternalScreen] ? 0.f : metaInfoAlpha;
  676. };
  677. void (^completionBlock)(BOOL finished) = ^(BOOL finished) {
  678. self->_controllerPanel.hidden = self->_videoFiltersHidden ? self->_controlsHidden : NO;
  679. self->_videoFilterView.hidden = self->_videoFiltersHidden;
  680. self->_playbackSpeedView.hidden = self->_playbackSpeedViewHidden;
  681. self.navigationController.navigationBar.hidden = self->_controlsHidden;
  682. self->_trackSelectorContainer.hidden = YES;
  683. self->_equalizerView.hidden = YES;
  684. if (self->_sleepTimerContainer)
  685. self->_sleepTimerContainer.hidden = YES;
  686. #if !NEW_UI
  687. self->_multiSelectionView.hidden = YES;
  688. #else
  689. self->_videoOptionsControlBar.hidden = YES;
  690. #endif
  691. self->_artistNameLabel.hidden = self->_audioOnly ? NO : self->_controlsHidden;
  692. self->_albumNameLabel.hidden = self->_audioOnly ? NO : self->_controlsHidden;
  693. self->_trackNameLabel.hidden = self->_audioOnly ? NO : self->_controlsHidden;
  694. };
  695. NSTimeInterval animationDuration = animated? 0.3 : 0.0;
  696. [UIView animateWithDuration:animationDuration animations:^{
  697. [self setNeedsStatusBarAppearanceUpdate];
  698. }];
  699. [UIView animateWithDuration:animationDuration animations:animationBlock completion:completionBlock];
  700. }
  701. - (BOOL)prefersStatusBarHidden
  702. {
  703. return _viewAppeared ? _controlsHidden : NO;
  704. }
  705. - (UIStatusBarStyle)preferredStatusBarStyle
  706. {
  707. return UIStatusBarStyleLightContent;
  708. }
  709. - (UIStatusBarAnimation)preferredStatusBarUpdateAnimation
  710. {
  711. return UIStatusBarAnimationFade;
  712. }
  713. - (void)toggleControlsVisible
  714. {
  715. if (!_trackSelectorContainer.hidden) {
  716. for (UIGestureRecognizer *recognizer in self.view.gestureRecognizers)
  717. [recognizer setEnabled:YES];
  718. }
  719. if (_controlsHidden && !_videoFiltersHidden)
  720. _videoFiltersHidden = YES;
  721. if (_controlsHidden && !_playbackSpeedViewHidden)
  722. _playbackSpeedViewHidden = YES;
  723. if (_isTapSeeking)
  724. _numberOfTapSeek = 0;
  725. [self setControlsHidden:!_controlsHidden animated:YES];
  726. }
  727. - (void)updateActivityIndicatorForState:(VLCMediaPlayerState)state
  728. {
  729. if (state == VLCMediaPlayerStatePlaying || state == VLCMediaPlayerStatePaused) {
  730. _previousPlayerStateWasPaused = state == VLCMediaPlayerStatePaused;
  731. }
  732. BOOL shouldAnimate = state == VLCMediaPlayerStateBuffering && !_previousPlayerStateWasPaused;
  733. if (self.activityIndicator.isAnimating != shouldAnimate) {
  734. self.activityIndicator.alpha = shouldAnimate ? 1.0 : 0.0;
  735. shouldAnimate ? [self.activityIndicator startAnimating] : [self.activityIndicator stopAnimating];
  736. }
  737. }
  738. - (void)_resetIdleTimer
  739. {
  740. if (!_idleTimer)
  741. _idleTimer = [NSTimer scheduledTimerWithTimeInterval:4.
  742. target:self
  743. selector:@selector(idleTimerExceeded)
  744. userInfo:nil
  745. repeats:NO];
  746. else {
  747. if (fabs([_idleTimer.fireDate timeIntervalSinceNow]) < 4.)
  748. [_idleTimer setFireDate:[NSDate dateWithTimeIntervalSinceNow:4.]];
  749. }
  750. }
  751. - (NSString *)_stringInTimeFormatFrom:(int)duration
  752. {
  753. if (duration < 60) {
  754. return [NSString stringWithFormat:@"%is", duration];
  755. } else {
  756. return [NSString stringWithFormat:@"%im%is", duration / 60, duration % 60];
  757. }
  758. }
  759. - (void)_seekFromTap
  760. {
  761. NSMutableString *hudString = [NSMutableString string];
  762. int seekDuration = (int)_numberOfTapSeek * SHORT_JUMP_DURATION;
  763. if (seekDuration > 0) {
  764. [_vpc jumpForward:SHORT_JUMP_DURATION];
  765. [hudString appendString:@"⇒ "];
  766. _previousJumpState = VLCMovieJumpStateForward;
  767. } else {
  768. [_vpc jumpBackward:SHORT_JUMP_DURATION];
  769. [hudString appendString:@"⇐ "];
  770. _previousJumpState = VLCMovieJumpStateBackward;
  771. }
  772. [hudString appendString: [self _stringInTimeFormatFrom:abs(seekDuration)]];
  773. [self.statusLabel showStatusMessage:[NSString stringWithString:hudString]];
  774. if (_controlsHidden)
  775. [self setControlsHidden:NO animated:NO];
  776. }
  777. - (void)idleTimerExceeded
  778. {
  779. if (![NSThread isMainThread]) {
  780. [self performSelectorOnMainThread:@selector(idleTimerExceeded) withObject:nil waitUntilDone:NO];
  781. return;
  782. }
  783. _idleTimer = nil;
  784. if (!_controlsHidden)
  785. [self toggleControlsVisible];
  786. if (_isTapSeeking) {
  787. _isTapSeeking = NO;
  788. _numberOfTapSeek = 0;
  789. }
  790. if (!_videoFiltersHidden)
  791. _videoFiltersHidden = YES;
  792. if (_equalizerView.hidden == NO)
  793. _equalizerView.hidden = YES;
  794. if (!_playbackSpeedViewHidden)
  795. _playbackSpeedViewHidden = YES;
  796. if (self.scrubIndicatorView.hidden == NO)
  797. self.scrubIndicatorView.hidden = YES;
  798. }
  799. - (UIResponder *)nextResponder
  800. {
  801. [self _resetIdleTimer];
  802. return [super nextResponder];
  803. }
  804. - (VLCDeviceMotion *)deviceMotion
  805. {
  806. if (!_deviceMotion) {
  807. _deviceMotion = [VLCDeviceMotion new];
  808. _deviceMotion.delegate = self;
  809. }
  810. return _deviceMotion;
  811. }
  812. - (void)setupForMediaProjection
  813. {
  814. BOOL mediaHasProjection = [_vpc currentMediaIs360Video];
  815. _fov = mediaHasProjection ? DEFAULT_FOV : 0.f;
  816. [_swipeRecognizerUp setEnabled:!mediaHasProjection];
  817. [_swipeRecognizerDown setEnabled:!mediaHasProjection];
  818. [_swipeRecognizerLeft setEnabled:!mediaHasProjection];
  819. [_swipeRecognizerRight setEnabled:!mediaHasProjection];
  820. if (mediaHasProjection) {
  821. [self.deviceMotion startDeviceMotion];
  822. }
  823. }
  824. - (void)applyYaw:(CGFloat)diffYaw pitch:(CGFloat)diffPitch;
  825. {
  826. //Add and limit new pitch and yaw
  827. self.deviceMotion.yaw += diffYaw;
  828. self.deviceMotion.pitch += diffPitch;
  829. [_vpc updateViewpoint:self.deviceMotion.yaw pitch:self.deviceMotion.pitch roll:0 fov:_fov absolute:YES];
  830. }
  831. - (void)deviceMotionHasAttitudeWithDeviceMotion:(VLCDeviceMotion *)deviceMotion pitch:(double)pitch yaw:(double)yaw
  832. {
  833. if (_panRecognizer.state != UIGestureRecognizerStateChanged || UIGestureRecognizerStateBegan) {
  834. [self applyYaw:yaw pitch:pitch];
  835. }
  836. }
  837. #pragma mark - keyboard controls
  838. - (NSArray<UIKeyCommand *> *)keyCommands
  839. {
  840. NSMutableArray<UIKeyCommand *> *commands = [NSMutableArray arrayWithObjects:
  841. [UIKeyCommand keyCommandWithInput:@" " modifierFlags:0 action:@selector(playPause) discoverabilityTitle:@"Play/Pause"],
  842. [UIKeyCommand keyCommandWithInput:@"\r" modifierFlags:0 action:@selector(playPause) discoverabilityTitle:@"Play/Pause"],
  843. [UIKeyCommand keyCommandWithInput:UIKeyInputLeftArrow modifierFlags:0 action:@selector(keyBackward) discoverabilityTitle:@"Skip Back"],
  844. [UIKeyCommand keyCommandWithInput:UIKeyInputRightArrow modifierFlags:0 action:@selector(keyForward) discoverabilityTitle:@"Skip Forward"],
  845. [UIKeyCommand keyCommandWithInput:@"[" modifierFlags:0 action:@selector(keyLeftBracket) discoverabilityTitle:@"Decrease playback speed"],
  846. [UIKeyCommand keyCommandWithInput:@"]" modifierFlags:0 action:@selector(keyRightBracket) discoverabilityTitle:@"Increase playback speed"],
  847. nil];
  848. bool playbackRateIsOne = ((fabsf(_vpc.playbackRate) - 1) < FLT_EPSILON);
  849. if (playbackRateIsOne) {
  850. UIKeyCommand *resetPlaybackCommand = [UIKeyCommand keyCommandWithInput:@"=" modifierFlags:0 action:@selector(keyEqual) discoverabilityTitle:@"Reset playback speed"];
  851. [commands addObject:resetPlaybackCommand];
  852. }
  853. return commands;
  854. }
  855. - (void)keyForward
  856. {
  857. [_vpc jumpForward:FORWARD_SWIPE_DURATION];
  858. }
  859. - (void)keyBackward
  860. {
  861. [_vpc jumpBackward:BACKWARD_SWIPE_DURATION];
  862. }
  863. - (void)keyEqual
  864. {
  865. [_vpc setPlaybackRate:1];
  866. }
  867. - (void)keyLeftBracket
  868. {
  869. [_vpc setPlaybackRate:_vpc.playbackRate * 0.75];
  870. }
  871. - (void)keyRightBracket
  872. {
  873. [_vpc setPlaybackRate:_vpc.playbackRate * 1.5];
  874. }
  875. #pragma mark - controls
  876. - (void)closePlayback:(id)sender
  877. {
  878. _playbackWillClose = YES;
  879. [_vpc stopPlayback];
  880. }
  881. - (IBAction)minimizePlayback:(id)sender
  882. {
  883. [_delegate movieViewControllerDidSelectMinimize:self];
  884. }
  885. - (IBAction)positionSliderAction:(UISlider *)sender
  886. {
  887. /* we need to limit the number of events sent by the slider, since otherwise, the user
  888. * wouldn't see the I-frames when seeking on current mobile devices. This isn't a problem
  889. * within the Simulator, but especially on older ARMv7 devices, it's clearly noticeable. */
  890. [self performSelector:@selector(_setPositionForReal) withObject:nil afterDelay:0.3];
  891. if (_mediaDuration > 0) {
  892. VLCTime *newPosition = [VLCTime timeWithInt:(int)(sender.value * _mediaDuration)];
  893. [self.timeNavigationTitleView.timeDisplayButton setTitle:newPosition.stringValue forState:UIControlStateNormal];
  894. [self.timeNavigationTitleView setNeedsLayout];
  895. self.timeNavigationTitleView.timeDisplayButton.accessibilityLabel = [NSString stringWithFormat:@"%@: %@", NSLocalizedString(@"PLAYBACK_POSITION", nil), newPosition.stringValue];
  896. _positionSet = NO;
  897. }
  898. [self _resetIdleTimer];
  899. }
  900. - (void)_setPositionForReal
  901. {
  902. if (!_positionSet) {
  903. [_vpc setPlaybackPosition:self.timeNavigationTitleView.positionSlider.value];
  904. [_vpc setNeedsMetadataUpdate];
  905. _positionSet = YES;
  906. }
  907. }
  908. - (IBAction)positionSliderTouchDown:(id)sender
  909. {
  910. [self _updateScrubLabel];
  911. self.scrubIndicatorView.hidden = NO;
  912. _isScrubbing = YES;
  913. }
  914. - (IBAction)positionSliderTouchUp:(id)sender
  915. {
  916. self.scrubIndicatorView.hidden = YES;
  917. _isScrubbing = NO;
  918. }
  919. - (void)_updateScrubLabel
  920. {
  921. float speed = self.timeNavigationTitleView.positionSlider.scrubbingSpeed;
  922. if (speed == 1.)
  923. self.currentScrubSpeedLabel.text = NSLocalizedString(@"PLAYBACK_SCRUB_HIGH", nil);
  924. else if (speed == .5)
  925. self.currentScrubSpeedLabel.text = NSLocalizedString(@"PLAYBACK_SCRUB_HALF", nil);
  926. else if (speed == .25)
  927. self.currentScrubSpeedLabel.text = NSLocalizedString(@"PLAYBACK_SCRUB_QUARTER", nil);
  928. else
  929. self.currentScrubSpeedLabel.text = NSLocalizedString(@"PLAYBACK_SCRUB_FINE", nil);
  930. [self _resetIdleTimer];
  931. }
  932. - (IBAction)positionSliderDrag:(id)sender
  933. {
  934. [self _updateScrubLabel];
  935. }
  936. - (void)volumeSliderAction:(id)sender
  937. {
  938. [self _resetIdleTimer];
  939. }
  940. - (void)updateTimeDisplayButton
  941. {
  942. UIButton *timeDisplayButton = self.timeNavigationTitleView.timeDisplayButton;
  943. if (_displayRemainingTime)
  944. [timeDisplayButton setTitle:[[_vpc remainingTime] stringValue] forState:UIControlStateNormal];
  945. else
  946. [timeDisplayButton setTitle:[[_vpc playedTime] stringValue] forState:UIControlStateNormal];
  947. [self.timeNavigationTitleView setNeedsLayout];
  948. }
  949. #pragma mark - playback controller delegation
  950. - (void)playbackPositionUpdated:(VLCPlaybackController *)controller
  951. {
  952. // FIXME: hard coded state since the state in mediaPlayer is incorrectly still buffering
  953. [self updateActivityIndicatorForState:VLCMediaPlayerStatePlaying];
  954. if (!_isScrubbing) {
  955. self.timeNavigationTitleView.positionSlider.value = [controller playbackPosition];
  956. }
  957. [self updateTimeDisplayButton];
  958. }
  959. - (void)prepareForMediaPlayback:(VLCPlaybackController *)controller
  960. {
  961. self.trackNameLabel.text = self.artistNameLabel.text = self.albumNameLabel.text = @"";
  962. self.timeNavigationTitleView.positionSlider.value = 0.;
  963. [self.timeNavigationTitleView.timeDisplayButton setTitle:@"" forState:UIControlStateNormal];
  964. self.timeNavigationTitleView.timeDisplayButton.accessibilityLabel = @"";
  965. [_equalizerView reloadData];
  966. [_playbackSpeedView prepareForMediaPlaybackWithController:controller];
  967. [self _resetIdleTimer];
  968. }
  969. - (void)playbackDidStop:(NSNotification *)notification
  970. {
  971. [self minimizePlayback:nil];
  972. }
  973. - (void)mediaPlayerStateChanged:(VLCMediaPlayerState)currentState
  974. isPlaying:(BOOL)isPlaying
  975. currentMediaHasTrackToChooseFrom:(BOOL)currentMediaHasTrackToChooseFrom
  976. currentMediaHasChapters:(BOOL)currentMediaHasChapters
  977. forPlaybackController:(VLCPlaybackController *)controller
  978. {
  979. [self updateActivityIndicatorForState:currentState];
  980. if (currentState == VLCMediaPlayerStateBuffering)
  981. _mediaDuration = controller.mediaDuration;
  982. if (currentState == VLCMediaPlayerStateError)
  983. [self.statusLabel showStatusMessage:NSLocalizedString(@"PLAYBACK_FAILED", nil)];
  984. [_controllerPanel updateButtons];
  985. #if !NEW_UI
  986. _multiSelectionView.mediaHasChapters = currentMediaHasChapters;
  987. #endif
  988. }
  989. - (void)savePlaybackState:(VLCPlaybackController *)controller
  990. {
  991. [_services.medialibraryService savePlaybackStateFrom:controller];
  992. }
  993. - (VLCMLMedia *)mediaForPlayingMedia:(VLCMedia *)media
  994. {
  995. return [_services.medialibraryService fetchMediaWith:media.url];
  996. }
  997. - (void)showStatusMessage:(NSString *)statusMessage
  998. {
  999. [self.statusLabel showStatusMessage:statusMessage];
  1000. }
  1001. - (void)hideShowAspectratioButton:(BOOL)hide
  1002. {
  1003. [UIView animateWithDuration:.3
  1004. animations:^{
  1005. self.widthConstraint.constant = hide ? 0 : 30;
  1006. self.timeNavigationTitleView.aspectRatioButton.hidden = hide;
  1007. }];
  1008. }
  1009. - (void)displayMetadataForPlaybackController:(VLCPlaybackController *)controller metadata:(VLCMetaData *)metadata
  1010. {
  1011. if (!_viewAppeared)
  1012. return;
  1013. self.trackNameLabel.text = metadata.title;
  1014. self.artworkImageView.image = metadata.artworkImage;
  1015. if (!metadata.artworkImage) {
  1016. self.artistNameLabel.text = metadata.artist;
  1017. self.albumNameLabel.text = metadata.albumName;
  1018. } else
  1019. self.artistNameLabel.text = self.albumNameLabel.text = nil;
  1020. [self hideShowAspectratioButton:metadata.isAudioOnly];
  1021. [_controllerPanel updateButtons];
  1022. [_playingExternalView updateUIWithRendererItem:_vpc.renderer title:metadata.title];
  1023. _audioOnly = metadata.isAudioOnly;
  1024. }
  1025. - (IBAction)playPause
  1026. {
  1027. [_vpc playPause];
  1028. }
  1029. - (IBAction)forward:(id)sender
  1030. {
  1031. [_vpc next];
  1032. }
  1033. - (IBAction)backward:(id)sender
  1034. {
  1035. [_vpc previous];
  1036. }
  1037. - (IBAction)switchTrack:(id)sender
  1038. {
  1039. if (_trackSelectorContainer.hidden == YES || _trackSelectorContainer.switchingTracksNotChapters == NO) {
  1040. _trackSelectorContainer.switchingTracksNotChapters = YES;
  1041. _trackSelectorContainer.hidden = NO;
  1042. _trackSelectorContainer.alpha = 1.;
  1043. [_trackSelectorContainer updateView];
  1044. if (_equalizerView.hidden == NO)
  1045. _equalizerView.hidden = YES;
  1046. if (!_playbackSpeedViewHidden)
  1047. self.playbackSpeedView.hidden = _playbackSpeedViewHidden = YES;
  1048. self.videoFilterView.hidden = _videoFiltersHidden = YES;
  1049. for (UIGestureRecognizer *recognizer in self.view.gestureRecognizers)
  1050. [recognizer setEnabled:NO];
  1051. [_tapOnVideoRecognizer setEnabled:YES];
  1052. } else {
  1053. _trackSelectorContainer.hidden = YES;
  1054. _trackSelectorContainer.switchingTracksNotChapters = NO;
  1055. }
  1056. }
  1057. - (IBAction)toggleTimeDisplay:(id)sender
  1058. {
  1059. _displayRemainingTime = !_displayRemainingTime;
  1060. [self updateTimeDisplayButton];
  1061. [self _resetIdleTimer];
  1062. }
  1063. - (void)showSleepTimer
  1064. {
  1065. if (!_playbackSpeedViewHidden)
  1066. self.playbackSpeedView.hidden = _playbackSpeedViewHidden = YES;
  1067. if (_equalizerView.hidden == NO)
  1068. _equalizerView.hidden = YES;
  1069. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
  1070. if (!_controlsHidden) {
  1071. self.controllerPanel.hidden = _controlsHidden = YES;
  1072. }
  1073. }
  1074. self.videoFilterView.hidden = _videoFiltersHidden = YES;
  1075. _sleepTimerContainer.alpha = 1.;
  1076. _sleepTimerContainer.hidden = NO;
  1077. }
  1078. - (IBAction)sleepTimerCancel:(id)sender
  1079. {
  1080. NSTimer *sleepTimer = [_vpc sleepTimer];
  1081. if (sleepTimer) {
  1082. [sleepTimer invalidate];
  1083. sleepTimer = nil;
  1084. }
  1085. [self.statusLabel showStatusMessage:NSLocalizedString(@"SLEEP_TIMER_UPDATED", nil)];
  1086. [self setControlsHidden:YES animated:YES];
  1087. }
  1088. - (IBAction)sleepTimerAction:(id)sender
  1089. {
  1090. [_vpc scheduleSleepTimerWithInterval:_sleepTimeDatePicker.countDownDuration];
  1091. [_playbackSpeedView setupSleepTimerIfNecessary];
  1092. [self.statusLabel showStatusMessage:NSLocalizedString(@"SLEEP_TIMER_UPDATED", nil)];
  1093. [self setControlsHidden:YES animated:YES];
  1094. }
  1095. - (void)toggleMultiSelectionView:(UIButton *)sender {
  1096. if (_multiSelectionView.hidden == NO) {
  1097. [UIView animateWithDuration:.3
  1098. animations:^{
  1099. self->_multiSelectionView.hidden = YES;
  1100. }
  1101. completion:nil];
  1102. return;
  1103. }
  1104. BOOL isLandscape = UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation]);
  1105. BOOL isIphone = (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone);
  1106. _multiSelectionView.showsEqualizer = (isLandscape && isIphone) || !isIphone;
  1107. CGRect workFrame = _multiSelectionView.frame;
  1108. workFrame.size = [_multiSelectionView proposedDisplaySize];
  1109. workFrame.origin.x = CGRectGetMaxX(sender.frame) - workFrame.size.width;
  1110. _multiSelectionView.alpha = 1.0f;
  1111. /* animate */
  1112. _multiSelectionView.frame = CGRectMake(workFrame.origin.x, workFrame.origin.y + workFrame.size.height, workFrame.size.width, 0.);
  1113. [UIView animateWithDuration:.3
  1114. animations:^{
  1115. self->_multiSelectionView.frame = workFrame;
  1116. self->_multiSelectionView.hidden = NO;
  1117. }
  1118. completion:nil];
  1119. }
  1120. - (void) toggleVideoOptionsBar
  1121. {
  1122. CGFloat alpha = _videoOptionsControlBar.hidden ? 1.0f : 0.0f;
  1123. BOOL hidden = !_videoOptionsControlBar.hidden;
  1124. [UIView animateWithDuration:.3
  1125. animations:^{
  1126. self->_videoOptionsControlBar.alpha = alpha;
  1127. self->_videoOptionsControlBar.hidden = hidden;
  1128. }
  1129. completion:nil];
  1130. }
  1131. - (void)moreActions:(UIButton *)sender
  1132. {
  1133. #if !NEW_UI
  1134. [self toggleMultiSelectionView:sender];
  1135. #else
  1136. [self toggleVideoOptionsBar];
  1137. #endif
  1138. [self _resetIdleTimer];
  1139. }
  1140. #pragma mark - multi-select delegation
  1141. - (void)toggleUILock
  1142. {
  1143. _interfaceIsLocked = !_interfaceIsLocked;
  1144. if (_interfaceIsLocked) {
  1145. _lockedOrientation = [[UIApplication sharedApplication] statusBarOrientation];
  1146. }
  1147. NSArray *items = [self itemsForInterfaceLock];
  1148. for (NSObject *item in items) {
  1149. if ([item isKindOfClass:[UIControl class]]) {
  1150. UIControl *control = (UIControl *)item;
  1151. control.enabled = !_interfaceIsLocked;
  1152. } else if ([item isKindOfClass:[UIGestureRecognizer class]]){
  1153. UIGestureRecognizer *gestureRecognizer = (UIGestureRecognizer *)item;
  1154. gestureRecognizer.enabled = !_interfaceIsLocked;
  1155. } else if ([item isKindOfClass:[VLCVolumeView class]]) {
  1156. //The MPVolumeview doesn't adjust it's UI when disabled so we need to set the alpha by hand
  1157. VLCVolumeView *view = (VLCVolumeView *)item;
  1158. view.userInteractionEnabled = !_interfaceIsLocked;
  1159. view.alpha = _interfaceIsLocked ? 0.5 : 1;
  1160. } else {
  1161. NSAssert(NO, @"class not handled");
  1162. }
  1163. }
  1164. #if !NEW_UI
  1165. _multiSelectionView.displayLock = _interfaceIsLocked;
  1166. #else
  1167. _videoOptionsControlBar.interfaceDisabled = _interfaceIsLocked;
  1168. #endif
  1169. }
  1170. - (void)toggleEqualizer
  1171. {
  1172. if (_equalizerView.hidden) {
  1173. if (!_playbackSpeedViewHidden)
  1174. self.playbackSpeedView.hidden = _playbackSpeedViewHidden = YES;
  1175. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
  1176. if (!_controlsHidden) {
  1177. self.controllerPanel.hidden = _controlsHidden = YES;
  1178. self.navigationController.navigationBar.hidden = YES;
  1179. }
  1180. }
  1181. _trackSelectorContainer.hidden = YES;
  1182. self.videoFilterView.hidden = _videoFiltersHidden = YES;
  1183. _equalizerView.alpha = 1.;
  1184. _equalizerView.hidden = NO;
  1185. } else
  1186. _equalizerView.hidden = YES;
  1187. }
  1188. - (void)toggleChapterAndTitleSelector
  1189. {
  1190. if (_trackSelectorContainer.hidden == YES || _trackSelectorContainer.switchingTracksNotChapters == YES) {
  1191. _trackSelectorContainer.switchingTracksNotChapters = NO;
  1192. [_trackSelectorContainer updateView];
  1193. _trackSelectorContainer.hidden = NO;
  1194. _trackSelectorContainer.alpha = 1.;
  1195. if (_equalizerView.hidden == NO)
  1196. _equalizerView.hidden = YES;
  1197. if (!_playbackSpeedViewHidden)
  1198. self.playbackSpeedView.hidden = _playbackSpeedViewHidden = YES;
  1199. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
  1200. if (!_controlsHidden) {
  1201. self.controllerPanel.hidden = _controlsHidden = YES;
  1202. }
  1203. }
  1204. _sleepTimerContainer.hidden = YES;
  1205. self.videoFilterView.hidden = _videoFiltersHidden = YES;
  1206. } else {
  1207. _trackSelectorContainer.hidden = YES;
  1208. }
  1209. }
  1210. - (void)toggleRepeatMode
  1211. {
  1212. [[VLCPlaybackController sharedInstance] toggleRepeatMode];
  1213. #if !NEW_UI
  1214. _multiSelectionView.repeatMode = [VLCPlaybackController sharedInstance].repeatMode;
  1215. #else
  1216. _videoOptionsControlBar.repeatMode = [VLCPlaybackController sharedInstance].repeatMode;
  1217. #endif
  1218. }
  1219. - (void)toggleShuffleMode
  1220. {
  1221. _vpc.shuffleMode = !_vpc.isShuffleMode;
  1222. #if !NEW_UI
  1223. _multiSelectionView.shuffleMode = _vpc.isShuffleMode;
  1224. #endif
  1225. }
  1226. - (void)hideMenu
  1227. {
  1228. [UIView animateWithDuration:.2
  1229. animations:^{
  1230. #if !NEW_UI
  1231. self->_multiSelectionView.hidden = YES;
  1232. #else
  1233. self->_videoOptionsControlBar.hidden = YES;
  1234. #endif
  1235. }
  1236. completion:^(BOOL finished){
  1237. }];
  1238. [self _resetIdleTimer];
  1239. }
  1240. #pragma mark - multi-touch gestures
  1241. - (void)togglePlayPause
  1242. {
  1243. if (!_playPauseGestureEnabled)
  1244. return;
  1245. if (_vpc.isPlaying) {
  1246. [_vpc pause];
  1247. [self setControlsHidden:NO animated:_controlsHidden];
  1248. } else {
  1249. [_vpc play];
  1250. }
  1251. }
  1252. - (BOOL)prefersHomeIndicatorAutoHidden
  1253. {
  1254. return YES;
  1255. }
  1256. - (VLCPanType)detectPanTypeForPan:(UIPanGestureRecognizer*)panRecognizer
  1257. {
  1258. NSString *deviceType = [[UIDevice currentDevice] model];
  1259. UIWindow *window = [[UIApplication sharedApplication] keyWindow];
  1260. CGFloat windowWidth = CGRectGetWidth(window.bounds);
  1261. CGPoint location = [panRecognizer locationInView:window];
  1262. VLCPanType panType = VLCPanTypeVolume; // default or right side of the screen
  1263. if (location.x < windowWidth / 2)
  1264. panType = VLCPanTypeBrightness;
  1265. // only check for seeking gesture if on iPad , will overwrite last statements if true
  1266. if ([deviceType isEqualToString:@"iPad"] && location.y < 110) {
  1267. panType = VLCPanTypeSeek;
  1268. }
  1269. if ([_vpc currentMediaIs360Video]) {
  1270. panType = VLCPanTypeProjection;
  1271. }
  1272. return panType;
  1273. }
  1274. - (void)panRecognized:(UIPanGestureRecognizer*)panRecognizer
  1275. {
  1276. CGFloat panDirectionX = [panRecognizer velocityInView:self.view].x;
  1277. CGFloat panDirectionY = [panRecognizer velocityInView:self.view].y;
  1278. if (panRecognizer.state == UIGestureRecognizerStateBegan) {
  1279. _currentPanType = [self detectPanTypeForPan:panRecognizer];
  1280. if ([_vpc currentMediaIs360Video]) {
  1281. _saveLocation = [panRecognizer locationInView:self.view];
  1282. [_deviceMotion stopDeviceMotion];
  1283. }
  1284. }
  1285. switch (_currentPanType) {
  1286. case VLCPanTypeSeek: {
  1287. if (!_seekGestureEnabled)
  1288. return;
  1289. double timeRemainingDouble = (-[_vpc remainingTime].intValue*0.001);
  1290. int timeRemaining = timeRemainingDouble;
  1291. if (panDirectionX > 0) {
  1292. if (timeRemaining > 2 ) // to not go outside duration , video will stop
  1293. [_vpc jumpForward:1];
  1294. } else
  1295. [_vpc jumpBackward:1];
  1296. break;
  1297. case VLCPanTypeVolume:
  1298. if (!_volumeGestureEnabled)
  1299. return;
  1300. MPMusicPlayerController *musicPlayer = [MPMusicPlayerController applicationMusicPlayer];
  1301. #pragma clang diagnostic push
  1302. #pragma clang diagnostic ignored "-Wdeprecated"
  1303. // there is no replacement for .volume which we want to use since Apple's susggestion is to not use their overlays
  1304. // but switch to the volume slider exclusively. meh.
  1305. if (panDirectionY > 0)
  1306. musicPlayer.volume -= 0.01;
  1307. else
  1308. musicPlayer.volume += 0.01;
  1309. #pragma clang diagnostic pop
  1310. } break;
  1311. case VLCPanTypeBrightness: {
  1312. if (!_brightnessGestureEnabled)
  1313. return;
  1314. CGFloat brightness = [UIScreen mainScreen].brightness;
  1315. if (panDirectionY > 0)
  1316. brightness = brightness - 0.01;
  1317. else
  1318. brightness = brightness + 0.01;
  1319. // Sanity check since -[UIScreen brightness] does not go by 0.01 steps
  1320. if (brightness > 1.0)
  1321. brightness = 1.0;
  1322. else if (brightness < 0.0)
  1323. brightness = 0.0;
  1324. NSAssert(brightness >= 0 && brightness <= 1, @"Brightness must be within 0 and 1 (it is %f)", brightness);
  1325. [[UIScreen mainScreen] setBrightness:brightness];
  1326. NSString *brightnessHUD = [NSString stringWithFormat:@"%@: %@ %%", NSLocalizedString(@"VFILTER_BRIGHTNESS", nil), [[[NSString stringWithFormat:@"%f",(brightness*100)] componentsSeparatedByString:@"."] objectAtIndex:0]];
  1327. [self.statusLabel showStatusMessage:brightnessHUD];
  1328. } break;
  1329. case VLCPanTypeProjection: {
  1330. [self updateProjectionWithPanRecognizer:panRecognizer];
  1331. } break;
  1332. case VLCPanTypeNone: {
  1333. } break;
  1334. }
  1335. if (panRecognizer.state == UIGestureRecognizerStateEnded) {
  1336. _currentPanType = VLCPanTypeNone;
  1337. if ([_vpc currentMediaIs360Video]) {
  1338. [_deviceMotion startDeviceMotion];
  1339. }
  1340. }
  1341. }
  1342. - (void)updateProjectionWithPanRecognizer:(UIPanGestureRecognizer *)panGestureRecognizer
  1343. {
  1344. CGPoint newLocationInView = [panGestureRecognizer locationInView:self.view];
  1345. CGFloat diffX = newLocationInView.x - _saveLocation.x;
  1346. CGFloat diffY = newLocationInView.y - _saveLocation.y;
  1347. _saveLocation = newLocationInView;
  1348. //screenSizePixel width is used twice to get a constant speed on the movement.
  1349. CGFloat diffYaw = _fov * -diffX / _screenPixelSize.width;
  1350. CGFloat diffPitch = _fov * -diffY / _screenPixelSize.width;
  1351. [self applyYaw:diffYaw pitch:diffPitch];
  1352. }
  1353. - (void)swipeRecognized:(UISwipeGestureRecognizer*)swipeRecognizer
  1354. {
  1355. if (!_seekGestureEnabled)
  1356. return;
  1357. NSString *hudString = @" ";
  1358. int swipeForwardDuration = (_variableJumpDurationEnabled) ? ((int)(_mediaDuration*0.001*0.05)) : FORWARD_SWIPE_DURATION;
  1359. int swipeBackwardDuration = (_variableJumpDurationEnabled) ? ((int)(_mediaDuration*0.001*0.05)) : BACKWARD_SWIPE_DURATION;
  1360. if (swipeRecognizer.direction == UISwipeGestureRecognizerDirectionRight) {
  1361. double timeRemainingDouble = (-[_vpc remainingTime].intValue*0.001);
  1362. int timeRemaining = timeRemainingDouble;
  1363. if (swipeForwardDuration < timeRemaining) {
  1364. if (swipeForwardDuration < 1)
  1365. swipeForwardDuration = 1;
  1366. [_vpc jumpForward:swipeForwardDuration];
  1367. hudString = [NSString stringWithFormat:@"⇒ %is", swipeForwardDuration];
  1368. } else {
  1369. [_vpc jumpForward:(timeRemaining - 5)];
  1370. hudString = [NSString stringWithFormat:@"⇒ %is",(timeRemaining - 5)];
  1371. }
  1372. } else if (swipeRecognizer.direction == UISwipeGestureRecognizerDirectionLeft) {
  1373. [_vpc jumpBackward:swipeBackwardDuration];
  1374. hudString = [NSString stringWithFormat:@"⇐ %is",swipeBackwardDuration];
  1375. } else if (swipeRecognizer.direction == UISwipeGestureRecognizerDirectionUp) {
  1376. [self backward:self];
  1377. hudString = NSLocalizedString(@"BWD_BUTTON", "");
  1378. } else if (swipeRecognizer.direction == UISwipeGestureRecognizerDirectionDown) {
  1379. [self forward:self];
  1380. hudString = NSLocalizedString(@"FWD_BUTTON", "");
  1381. }
  1382. if (swipeRecognizer.state == UIGestureRecognizerStateEnded) {
  1383. [self.statusLabel showStatusMessage:hudString];
  1384. }
  1385. }
  1386. - (void)doubleTapRecognized:(UITapGestureRecognizer *)tapRecognizer
  1387. {
  1388. if (!_seekGestureEnabled)
  1389. return;
  1390. CGFloat screenWidth = self.view.frame.size.width;
  1391. CGFloat backwardBoundary = screenWidth / 3.0;
  1392. CGFloat forwardBoundary = 2 * screenWidth / 3.0;
  1393. CGPoint tapPosition = [tapRecognizer locationInView:self.view];
  1394. //Handling seek reset if tap orientation changes.
  1395. if (tapPosition.x < backwardBoundary) {
  1396. _numberOfTapSeek = _previousJumpState == VLCMovieJumpStateForward ? -1 : _numberOfTapSeek - 1;
  1397. } else if (tapPosition.x > forwardBoundary){
  1398. _numberOfTapSeek = _previousJumpState == VLCMovieJumpStateBackward ? 1 : _numberOfTapSeek + 1;
  1399. } else {
  1400. [_vpc toggleFullScreen];
  1401. return;
  1402. }
  1403. _isTapSeeking = YES;
  1404. [self _seekFromTap];
  1405. }
  1406. - (void)equalizerViewReceivedUserInput
  1407. {
  1408. [self _resetIdleTimer];
  1409. }
  1410. #pragma mark - Video Filter UI
  1411. - (IBAction)videoFilterToggle:(id)sender
  1412. {
  1413. if (!_playbackSpeedViewHidden)
  1414. self.playbackSpeedView.hidden = _playbackSpeedViewHidden = YES;
  1415. if (_equalizerView.hidden == NO)
  1416. _equalizerView.hidden = YES;
  1417. self.videoFilterView.hidden = !_videoFiltersHidden;
  1418. _videoFiltersHidden = self.videoFilterView.hidden;
  1419. }
  1420. - (IBAction)videoFilterSliderAction:(id)sender
  1421. {
  1422. if (sender == self.hueSlider)
  1423. _vpc.hue = self.hueSlider.value;
  1424. else if (sender == self.contrastSlider)
  1425. _vpc.contrast = self.contrastSlider.value;
  1426. else if (sender == self.brightnessSlider)
  1427. _vpc.brightness = self.brightnessSlider.value;
  1428. else if (sender == self.saturationSlider)
  1429. _vpc.saturation = self.saturationSlider.value;
  1430. else if (sender == self.gammaSlider)
  1431. _vpc.gamma = self.gammaSlider.value;
  1432. else if (sender == self.resetVideoFilterButton) {
  1433. [self resetVideoFiltersSliders];
  1434. [_vpc resetFilters];
  1435. } else
  1436. APLog(@"unknown sender for videoFilterSliderAction");
  1437. [self _resetIdleTimer];
  1438. }
  1439. - (void)appBecameActive:(NSNotification *)aNotification
  1440. {
  1441. if ([_delegate movieViewControllerShouldBeDisplayed:self]) {
  1442. [_vpc recoverDisplayedMetadata];
  1443. if (_vpc.videoOutputView != self.movieView) {
  1444. _vpc.videoOutputView = self.movieView;
  1445. }
  1446. }
  1447. }
  1448. #pragma mark - playback view
  1449. - (IBAction)videoDimensionAction:(id)sender
  1450. {
  1451. if (sender == self.timeNavigationTitleView.aspectRatioButton) {
  1452. [[VLCPlaybackController sharedInstance] switchAspectRatio];
  1453. }
  1454. }
  1455. - (IBAction)showPlaybackSpeedView {
  1456. if (!_videoFiltersHidden)
  1457. self.videoFilterView.hidden = _videoFiltersHidden = YES;
  1458. if (_equalizerView.hidden == NO)
  1459. _equalizerView.hidden = YES;
  1460. self.playbackSpeedView.hidden = !_playbackSpeedViewHidden;
  1461. _playbackSpeedViewHidden = self.playbackSpeedView.hidden;
  1462. [self _resetIdleTimer];
  1463. }
  1464. #pragma mark - autorotation
  1465. - (UIInterfaceOrientationMask)supportedInterfaceOrientations
  1466. {
  1467. BOOL orientationIslocked = _interfaceIsLocked || [_vpc currentMediaIs360Video];
  1468. UIInterfaceOrientationMask maskFromOrientation = 1 << _lockedOrientation;
  1469. return orientationIslocked ? maskFromOrientation : UIInterfaceOrientationMaskAll;
  1470. }
  1471. - (BOOL)shouldAutorotate
  1472. {
  1473. UIInterfaceOrientation toInterfaceOrientation = [[UIApplication sharedApplication] statusBarOrientation];
  1474. return UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad
  1475. || toInterfaceOrientation != UIInterfaceOrientationPortraitUpsideDown;
  1476. }
  1477. - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
  1478. {
  1479. [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
  1480. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
  1481. [coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
  1482. if (self.artworkImageView.image)
  1483. self.trackNameLabel.hidden = YES;
  1484. if (!self->_equalizerView.hidden)
  1485. self->_equalizerView.hidden = YES;
  1486. } completion:nil];
  1487. }
  1488. }
  1489. - (void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection
  1490. {
  1491. if (_vpc.isPlaying && _controlsHidden)
  1492. [self setControlsHidden:NO animated:YES];
  1493. }
  1494. - (NSArray *)getVideoOptionsConstraints
  1495. {
  1496. return @[
  1497. [_videoOptionsControlBar.centerXAnchor constraintEqualToAnchor:self.view.centerXAnchor],
  1498. [_videoOptionsControlBar.bottomAnchor constraintEqualToAnchor:_controllerPanel.topAnchor constant:-50],
  1499. ];
  1500. }
  1501. #pragma mark - External Display
  1502. - (void)showOnDisplay:(UIView *)view
  1503. {
  1504. // if we don't have a renderer we're mirroring and don't want to show the dialog
  1505. BOOL displayExternally = view != _movieView;
  1506. [_playingExternalView shouldDisplay:displayExternally movieView:_movieView];
  1507. _artworkImageView.hidden = displayExternally;
  1508. if (!displayExternally && _movieView.superview != self.view) {
  1509. [self.view addSubview:_movieView];
  1510. [self.view sendSubviewToBack:_movieView];
  1511. _movieView.frame = self.view.frame;
  1512. }
  1513. }
  1514. - (void)handleExternalScreenDidConnect:(NSNotification *)notification
  1515. {
  1516. [self showOnDisplay:_playingExternalView.displayView];
  1517. }
  1518. - (void)handleExternalScreenDidDisconnect:(NSNotification *)notification
  1519. {
  1520. [self showOnDisplay:_movieView];
  1521. }
  1522. #pragma mark - Renderers
  1523. - (void)setupRendererDiscovererManager
  1524. {
  1525. // Create a renderer button for VLCMovieViewController
  1526. _rendererButton = [_services.rendererDiscovererManager setupRendererButton];
  1527. // Setting rendererIcons to white since default is orange
  1528. _rendererButton.tintColor = [UIColor whiteColor];
  1529. [_rendererButton setImage:[UIImage imageNamed:@"renderer"] forState:UIControlStateNormal];
  1530. [_rendererButton setImage:[UIImage imageNamed:@"rendererFull"] forState:UIControlStateSelected];
  1531. __weak typeof(self) weakSelf = self;
  1532. [_services.rendererDiscovererManager addSelectionHandler:^(VLCRendererItem * item) {
  1533. __strong typeof(weakSelf) strongSelf = weakSelf;
  1534. if (item) {
  1535. [strongSelf showOnDisplay:strongSelf->_playingExternalView.displayView];
  1536. } else {
  1537. [strongSelf removedCurrentRendererItem:strongSelf->_vpc.renderer];
  1538. }
  1539. }];
  1540. }
  1541. #pragma mark - VLCRendererDiscovererManagerDelegate
  1542. - (void)removedCurrentRendererItem:(VLCRendererItem *)item
  1543. {
  1544. [self showOnDisplay:_movieView];
  1545. }
  1546. #pragma mark - PlaybackSpeedViewDelegate
  1547. - (void)playbackSpeedViewShouldResetIdleTimer:(PlaybackSpeedView *)playbackSpeedView
  1548. {
  1549. [self _resetIdleTimer];
  1550. }
  1551. - (void)playbackSpeedViewSleepTimerHit:(PlaybackSpeedView *)playbackSpeedView
  1552. {
  1553. [self showSleepTimer];
  1554. }
  1555. #pragma mark - VLCVideoOptionsControlBarDelegate
  1556. - (void)didSelectMoreOptions:(VLCVideoOptionsControlBar * _Nonnull)optionsBar {
  1557. [self moreActions:optionsBar.moreOptionsButton];
  1558. }
  1559. - (void)didSelectSubtitle:(VLCVideoOptionsControlBar * _Nonnull)optionsBar {
  1560. NSAssert(0, @"didSelectSubtitle not implemented");
  1561. }
  1562. - (void)didToggleFullScreen:(VLCVideoOptionsControlBar * _Nonnull)optionsBar {
  1563. [_vpc toggleFullScreen];
  1564. }
  1565. - (void)didToggleInterfaceLock:(VLCVideoOptionsControlBar * _Nonnull)optionsBar {
  1566. [self toggleUILock];
  1567. }
  1568. - (void)didToggleRepeat:(VLCVideoOptionsControlBar * _Nonnull)optionsBar {
  1569. [self toggleRepeatMode];
  1570. }
  1571. @end