VLCMovieViewController.m 61 KB

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