VLCMovieViewController.m 64 KB

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