VLCMovieViewController.m 77 KB

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