VLCMovieViewController.m 76 KB

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