VLCMovieViewController.m 76 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059
  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. #if NEW_UI
  1107. _videoOptionsControlBar.toggleFullScreenButton.hidden = _audioOnly;
  1108. #endif
  1109. }
  1110. - (IBAction)playPause
  1111. {
  1112. [_vpc playPause];
  1113. }
  1114. - (IBAction)forward:(id)sender
  1115. {
  1116. [_vpc next];
  1117. }
  1118. - (IBAction)backward:(id)sender
  1119. {
  1120. [_vpc previous];
  1121. }
  1122. - (IBAction)switchTrack:(id)sender
  1123. {
  1124. if (_trackSelectorContainer.hidden == YES || _trackSelectorContainer.switchingTracksNotChapters == NO) {
  1125. _trackSelectorContainer.switchingTracksNotChapters = YES;
  1126. _trackSelectorContainer.hidden = NO;
  1127. _trackSelectorContainer.alpha = 1.;
  1128. [_trackSelectorContainer updateView];
  1129. if (_equalizerView.hidden == NO)
  1130. _equalizerView.hidden = YES;
  1131. if (!_playbackSpeedViewHidden)
  1132. self.playbackSpeedView.hidden = _playbackSpeedViewHidden = YES;
  1133. self.videoFilterView.hidden = _videoFiltersHidden = YES;
  1134. for (UIGestureRecognizer *recognizer in self.view.gestureRecognizers)
  1135. [recognizer setEnabled:NO];
  1136. [_tapOnVideoRecognizer setEnabled:YES];
  1137. } else {
  1138. _trackSelectorContainer.hidden = YES;
  1139. _trackSelectorContainer.switchingTracksNotChapters = NO;
  1140. }
  1141. }
  1142. - (IBAction)toggleTimeDisplay:(id)sender
  1143. {
  1144. _displayRemainingTime = !_displayRemainingTime;
  1145. [self updateTimeDisplayButton];
  1146. [self _resetIdleTimer];
  1147. }
  1148. - (void)showSleepTimer
  1149. {
  1150. if (!_playbackSpeedViewHidden)
  1151. self.playbackSpeedView.hidden = _playbackSpeedViewHidden = YES;
  1152. if (_equalizerView.hidden == NO)
  1153. _equalizerView.hidden = YES;
  1154. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
  1155. if (!_controlsHidden) {
  1156. self.controllerPanel.hidden = _controlsHidden = YES;
  1157. }
  1158. }
  1159. self.videoFilterView.hidden = _videoFiltersHidden = YES;
  1160. _sleepTimerContainer.alpha = 1.;
  1161. _sleepTimerContainer.hidden = NO;
  1162. }
  1163. - (IBAction)sleepTimerCancel:(id)sender
  1164. {
  1165. NSTimer *sleepTimer = [_vpc sleepTimer];
  1166. if (sleepTimer) {
  1167. [sleepTimer invalidate];
  1168. sleepTimer = nil;
  1169. }
  1170. [self.statusLabel showStatusMessage:NSLocalizedString(@"SLEEP_TIMER_UPDATED", nil)];
  1171. [self setControlsHidden:YES animated:YES];
  1172. }
  1173. - (IBAction)sleepTimerAction:(id)sender
  1174. {
  1175. [_vpc scheduleSleepTimerWithInterval:_sleepTimeDatePicker.countDownDuration];
  1176. [_playbackSpeedView setupSleepTimerIfNecessary];
  1177. [self.statusLabel showStatusMessage:NSLocalizedString(@"SLEEP_TIMER_UPDATED", nil)];
  1178. [self setControlsHidden:YES animated:YES];
  1179. }
  1180. - (void)toggleMultiSelectionView:(UIButton *)sender {
  1181. if (_multiSelectionView.hidden == NO) {
  1182. [UIView animateWithDuration:.3
  1183. animations:^{
  1184. self->_multiSelectionView.hidden = YES;
  1185. }
  1186. completion:nil];
  1187. return;
  1188. }
  1189. BOOL isLandscape = UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation]);
  1190. BOOL isIphone = (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone);
  1191. _multiSelectionView.showsEqualizer = (isLandscape && isIphone) || !isIphone;
  1192. CGRect workFrame = _multiSelectionView.frame;
  1193. workFrame.size = [_multiSelectionView proposedDisplaySize];
  1194. workFrame.origin.x = CGRectGetMaxX(sender.frame) - workFrame.size.width;
  1195. _multiSelectionView.alpha = 1.0f;
  1196. /* animate */
  1197. _multiSelectionView.frame = CGRectMake(workFrame.origin.x, workFrame.origin.y + workFrame.size.height, workFrame.size.width, 0.);
  1198. [UIView animateWithDuration:.3
  1199. animations:^{
  1200. self->_multiSelectionView.frame = workFrame;
  1201. self->_multiSelectionView.hidden = NO;
  1202. }
  1203. completion:nil];
  1204. }
  1205. - (void)moreActions:(UIButton *)sender
  1206. {
  1207. #if !NEW_UI
  1208. [self toggleMultiSelectionView:sender];
  1209. #endif
  1210. [self _resetIdleTimer];
  1211. }
  1212. #pragma mark - multi-select delegation
  1213. - (void)toggleUILock
  1214. {
  1215. _interfaceIsLocked = !_interfaceIsLocked;
  1216. if (_interfaceIsLocked) {
  1217. _lockedOrientation = [[UIApplication sharedApplication] statusBarOrientation];
  1218. }
  1219. NSArray *items = [self itemsForInterfaceLock];
  1220. for (NSObject *item in items) {
  1221. if ([item isKindOfClass:[UIControl class]]) {
  1222. UIControl *control = (UIControl *)item;
  1223. if (NEW_UI && item == _mediaNavigationBar.chromeCastButton) {
  1224. control.enabled = !_interfaceIsLocked;
  1225. } else {
  1226. control.enabled = !_interfaceIsLocked;
  1227. }
  1228. } else if ([item isKindOfClass:[UIGestureRecognizer class]]){
  1229. UIGestureRecognizer *gestureRecognizer = (UIGestureRecognizer *)item;
  1230. gestureRecognizer.enabled = !_interfaceIsLocked;
  1231. } else if ([item isKindOfClass:[VLCVolumeView class]]) {
  1232. //The MPVolumeview doesn't adjust it's UI when disabled so we need to set the alpha by hand
  1233. VLCVolumeView *view = (VLCVolumeView *)item;
  1234. view.userInteractionEnabled = !_interfaceIsLocked;
  1235. view.alpha = _interfaceIsLocked ? 0.5 : 1;
  1236. } else if(@available(iOS 11.0, *)){
  1237. if ([item isKindOfClass:[AVRoutePickerView class]]) {
  1238. AVRoutePickerView *airplayView = (AVRoutePickerView *)item;
  1239. airplayView.userInteractionEnabled = !_interfaceIsLocked;
  1240. airplayView.alpha = _interfaceIsLocked ? 0.5 : 1;
  1241. }
  1242. } else {
  1243. NSAssert(NO, @"class not handled");
  1244. }
  1245. }
  1246. #if !NEW_UI
  1247. _multiSelectionView.displayLock = _interfaceIsLocked;
  1248. #else
  1249. _videoOptionsControlBar.interfaceDisabled = _interfaceIsLocked;
  1250. _moreOptionsActionSheet.interfaceDisabled = _interfaceIsLocked;
  1251. #endif
  1252. }
  1253. - (void)toggleEqualizer
  1254. {
  1255. if (_equalizerView.hidden) {
  1256. if (!_playbackSpeedViewHidden)
  1257. self.playbackSpeedView.hidden = _playbackSpeedViewHidden = YES;
  1258. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
  1259. if (!_controlsHidden) {
  1260. self.controllerPanel.hidden = _controlsHidden = YES;
  1261. self.navigationController.navigationBar.hidden = YES;
  1262. }
  1263. }
  1264. _trackSelectorContainer.hidden = YES;
  1265. self.videoFilterView.hidden = _videoFiltersHidden = YES;
  1266. _equalizerView.alpha = 1.;
  1267. _equalizerView.hidden = NO;
  1268. } else
  1269. _equalizerView.hidden = YES;
  1270. }
  1271. - (void)toggleChapterAndTitleSelector
  1272. {
  1273. if (_trackSelectorContainer.hidden == YES || _trackSelectorContainer.switchingTracksNotChapters == YES) {
  1274. _trackSelectorContainer.switchingTracksNotChapters = NO;
  1275. [_trackSelectorContainer updateView];
  1276. _trackSelectorContainer.hidden = NO;
  1277. _trackSelectorContainer.alpha = 1.;
  1278. if (_equalizerView.hidden == NO)
  1279. _equalizerView.hidden = YES;
  1280. if (!_playbackSpeedViewHidden)
  1281. self.playbackSpeedView.hidden = _playbackSpeedViewHidden = YES;
  1282. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
  1283. if (!_controlsHidden) {
  1284. self.controllerPanel.hidden = _controlsHidden = YES;
  1285. }
  1286. }
  1287. _sleepTimerContainer.hidden = YES;
  1288. self.videoFilterView.hidden = _videoFiltersHidden = YES;
  1289. } else {
  1290. _trackSelectorContainer.hidden = YES;
  1291. }
  1292. }
  1293. - (void)toggleRepeatMode
  1294. {
  1295. [[VLCPlaybackService sharedInstance] toggleRepeatMode];
  1296. #if !NEW_UI
  1297. _multiSelectionView.repeatMode = [VLCPlaybackService sharedInstance].repeatMode;
  1298. #else
  1299. _videoOptionsControlBar.repeatMode = [VLCPlaybackService sharedInstance].repeatMode;
  1300. #endif
  1301. }
  1302. - (void)toggleShuffleMode
  1303. {
  1304. _vpc.shuffleMode = !_vpc.isShuffleMode;
  1305. #if !NEW_UI
  1306. _multiSelectionView.shuffleMode = _vpc.isShuffleMode;
  1307. #endif
  1308. }
  1309. - (void)hideMenu
  1310. {
  1311. [UIView animateWithDuration:.2
  1312. animations:^{
  1313. #if !NEW_UI
  1314. self->_multiSelectionView.hidden = YES;
  1315. #else
  1316. self->_videoOptionsControlBar.hidden = YES;
  1317. #endif
  1318. }
  1319. completion:nil];
  1320. [self _resetIdleTimer];
  1321. }
  1322. #pragma mark - multi-touch gestures
  1323. - (void)togglePlayPause
  1324. {
  1325. if (!_playPauseGestureEnabled)
  1326. return;
  1327. if (_vpc.isPlaying) {
  1328. [_vpc pause];
  1329. [self setControlsHidden:NO animated:_controlsHidden];
  1330. } else {
  1331. [_vpc play];
  1332. }
  1333. }
  1334. - (BOOL)prefersHomeIndicatorAutoHidden
  1335. {
  1336. return YES;
  1337. }
  1338. - (VLCPanType)detectPanTypeForPan:(UIPanGestureRecognizer*)panRecognizer
  1339. {
  1340. NSString *deviceType = [[UIDevice currentDevice] model];
  1341. UIWindow *window = [[UIApplication sharedApplication] keyWindow];
  1342. CGFloat windowWidth = CGRectGetWidth(window.bounds);
  1343. CGPoint location = [panRecognizer locationInView:window];
  1344. VLCPanType panType = VLCPanTypeVolume; // default or right side of the screen
  1345. if (location.x < windowWidth / 2)
  1346. panType = VLCPanTypeBrightness;
  1347. // only check for seeking gesture if on iPad , will overwrite last statements if true
  1348. if ([deviceType isEqualToString:@"iPad"] && location.y < 110) {
  1349. panType = VLCPanTypeSeek;
  1350. }
  1351. if ([_vpc currentMediaIs360Video]) {
  1352. panType = VLCPanTypeProjection;
  1353. }
  1354. return panType;
  1355. }
  1356. - (void)panRecognized:(UIPanGestureRecognizer*)panRecognizer
  1357. {
  1358. CGFloat panDirectionX = [panRecognizer velocityInView:self.view].x;
  1359. CGFloat panDirectionY = [panRecognizer velocityInView:self.view].y;
  1360. if (panRecognizer.state == UIGestureRecognizerStateBegan) {
  1361. _currentPanType = [self detectPanTypeForPan:panRecognizer];
  1362. if ([_vpc currentMediaIs360Video]) {
  1363. _saveLocation = [panRecognizer locationInView:self.view];
  1364. [_deviceMotion stopDeviceMotion];
  1365. }
  1366. }
  1367. switch (_currentPanType) {
  1368. case VLCPanTypeSeek: {
  1369. if (!_seekGestureEnabled)
  1370. return;
  1371. double timeRemainingDouble = (-[_vpc remainingTime].intValue*0.001);
  1372. int timeRemaining = timeRemainingDouble;
  1373. if (panDirectionX > 0) {
  1374. if (timeRemaining > 2 ) // to not go outside duration , video will stop
  1375. [_vpc jumpForward:1];
  1376. } else
  1377. [_vpc jumpBackward:1];
  1378. break;
  1379. case VLCPanTypeVolume:
  1380. if (!_volumeGestureEnabled)
  1381. return;
  1382. MPMusicPlayerController *musicPlayer = [MPMusicPlayerController applicationMusicPlayer];
  1383. #pragma clang diagnostic push
  1384. #pragma clang diagnostic ignored "-Wdeprecated"
  1385. // there is no replacement for .volume which we want to use since Apple's susggestion is to not use their overlays
  1386. // but switch to the volume slider exclusively. meh.
  1387. if (panDirectionY > 0)
  1388. musicPlayer.volume -= 0.01;
  1389. else
  1390. musicPlayer.volume += 0.01;
  1391. #pragma clang diagnostic pop
  1392. } break;
  1393. case VLCPanTypeBrightness: {
  1394. if (!_brightnessGestureEnabled)
  1395. return;
  1396. CGFloat brightness = [UIScreen mainScreen].brightness;
  1397. if (panDirectionY > 0)
  1398. brightness = brightness - 0.01;
  1399. else
  1400. brightness = brightness + 0.01;
  1401. // Sanity check since -[UIScreen brightness] does not go by 0.01 steps
  1402. if (brightness > 1.0)
  1403. brightness = 1.0;
  1404. else if (brightness < 0.0)
  1405. brightness = 0.0;
  1406. NSAssert(brightness >= 0 && brightness <= 1, @"Brightness must be within 0 and 1 (it is %f)", brightness);
  1407. [[UIScreen mainScreen] setBrightness:brightness];
  1408. NSString *brightnessHUD = [NSString stringWithFormat:@"%@: %@ %%", NSLocalizedString(@"VFILTER_BRIGHTNESS", nil), [[[NSString stringWithFormat:@"%f",(brightness*100)] componentsSeparatedByString:@"."] objectAtIndex:0]];
  1409. [self.statusLabel showStatusMessage:brightnessHUD];
  1410. } break;
  1411. case VLCPanTypeProjection: {
  1412. [self updateProjectionWithPanRecognizer:panRecognizer];
  1413. } break;
  1414. case VLCPanTypeNone: {
  1415. } break;
  1416. }
  1417. if (panRecognizer.state == UIGestureRecognizerStateEnded) {
  1418. _currentPanType = VLCPanTypeNone;
  1419. if ([_vpc currentMediaIs360Video]) {
  1420. [_deviceMotion startDeviceMotion];
  1421. }
  1422. }
  1423. }
  1424. - (void)updateProjectionWithPanRecognizer:(UIPanGestureRecognizer *)panGestureRecognizer
  1425. {
  1426. CGPoint newLocationInView = [panGestureRecognizer locationInView:self.view];
  1427. CGFloat diffX = newLocationInView.x - _saveLocation.x;
  1428. CGFloat diffY = newLocationInView.y - _saveLocation.y;
  1429. _saveLocation = newLocationInView;
  1430. //screenSizePixel width is used twice to get a constant speed on the movement.
  1431. CGFloat diffYaw = _fov * -diffX / _screenPixelSize.width;
  1432. CGFloat diffPitch = _fov * -diffY / _screenPixelSize.width;
  1433. [self applyYaw:diffYaw pitch:diffPitch];
  1434. }
  1435. - (void)swipeRecognized:(UISwipeGestureRecognizer*)swipeRecognizer
  1436. {
  1437. if (!_seekGestureEnabled)
  1438. return;
  1439. NSString *hudString = @" ";
  1440. int swipeForwardDuration = (_variableJumpDurationEnabled) ? ((int)(_mediaDuration*0.001*0.05)) : FORWARD_SWIPE_DURATION;
  1441. int swipeBackwardDuration = (_variableJumpDurationEnabled) ? ((int)(_mediaDuration*0.001*0.05)) : BACKWARD_SWIPE_DURATION;
  1442. if (swipeRecognizer.direction == UISwipeGestureRecognizerDirectionRight) {
  1443. double timeRemainingDouble = (-[_vpc remainingTime].intValue*0.001);
  1444. int timeRemaining = timeRemainingDouble;
  1445. if (swipeForwardDuration < timeRemaining) {
  1446. if (swipeForwardDuration < 1)
  1447. swipeForwardDuration = 1;
  1448. [_vpc jumpForward:swipeForwardDuration];
  1449. hudString = [NSString stringWithFormat:@"⇒ %is", swipeForwardDuration];
  1450. } else {
  1451. [_vpc jumpForward:(timeRemaining - 5)];
  1452. hudString = [NSString stringWithFormat:@"⇒ %is",(timeRemaining - 5)];
  1453. }
  1454. } else if (swipeRecognizer.direction == UISwipeGestureRecognizerDirectionLeft) {
  1455. [_vpc jumpBackward:swipeBackwardDuration];
  1456. hudString = [NSString stringWithFormat:@"⇐ %is",swipeBackwardDuration];
  1457. } else if (swipeRecognizer.direction == UISwipeGestureRecognizerDirectionUp) {
  1458. [self backward:self];
  1459. hudString = NSLocalizedString(@"BWD_BUTTON", "");
  1460. } else if (swipeRecognizer.direction == UISwipeGestureRecognizerDirectionDown) {
  1461. [self forward:self];
  1462. hudString = NSLocalizedString(@"FWD_BUTTON", "");
  1463. }
  1464. if (swipeRecognizer.state == UIGestureRecognizerStateEnded) {
  1465. [self.statusLabel showStatusMessage:hudString];
  1466. }
  1467. }
  1468. - (void)viewSafeAreaInsetsDidChange
  1469. {
  1470. [super viewSafeAreaInsetsDidChange];
  1471. if (UI_USER_INTERFACE_IDIOM() != UIUserInterfaceIdiomPhone) {
  1472. return;
  1473. }
  1474. // safeAreaInsets can take some time to get set.
  1475. // Once updated, check if we need to update the constraints for notches
  1476. [self adaptMovieViewToNotch];
  1477. }
  1478. - (void)adaptMovieViewToNotch API_AVAILABLE(ios(11))
  1479. {
  1480. // Ignore the constraint updates for iPads and notchless devices.
  1481. if (UI_USER_INTERFACE_IDIOM() != UIUserInterfaceIdiomPhone
  1482. || (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone && self.view.safeAreaInsets.bottom == 0)) {
  1483. return;
  1484. }
  1485. // 30.0 represents the exact size of the notch
  1486. CGFloat constant = _vpc.currentAspectRatio != VLCAspectRatioFillToScreen ? 30.0 : 0.0;
  1487. UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
  1488. if (orientation == UIDeviceOrientationLandscapeLeft
  1489. || orientation == UIDeviceOrientationLandscapeRight) {
  1490. [_movieViewLeadingConstraint setConstant:constant];
  1491. [_movieViewTrailingConstraint setConstant:-constant];
  1492. } else {
  1493. // Reset when in portrait
  1494. [_movieViewLeadingConstraint setConstant:0];
  1495. [_movieViewTrailingConstraint setConstant:0];
  1496. }
  1497. [_movieView layoutIfNeeded];
  1498. }
  1499. - (void)doubleTapRecognized:(UITapGestureRecognizer *)tapRecognizer
  1500. {
  1501. if (!_seekGestureEnabled)
  1502. return;
  1503. CGFloat screenWidth = self.view.frame.size.width;
  1504. CGFloat backwardBoundary = screenWidth / 3.0;
  1505. CGFloat forwardBoundary = 2 * screenWidth / 3.0;
  1506. CGPoint tapPosition = [tapRecognizer locationInView:self.view];
  1507. //Handling seek reset if tap orientation changes.
  1508. if (tapPosition.x < backwardBoundary) {
  1509. _numberOfTapSeek = _previousJumpState == VLCMovieJumpStateForward ? -1 : _numberOfTapSeek - 1;
  1510. } else if (tapPosition.x > forwardBoundary){
  1511. _numberOfTapSeek = _previousJumpState == VLCMovieJumpStateBackward ? 1 : _numberOfTapSeek + 1;
  1512. } else {
  1513. [_vpc switchAspectRatio:YES];
  1514. return;
  1515. }
  1516. _isTapSeeking = YES;
  1517. [self _seekFromTap];
  1518. }
  1519. - (void)equalizerViewReceivedUserInput
  1520. {
  1521. [self _resetIdleTimer];
  1522. }
  1523. #pragma mark - Video Filter UI
  1524. - (IBAction)videoFilterToggle:(id)sender
  1525. {
  1526. if (!_playbackSpeedViewHidden)
  1527. self.playbackSpeedView.hidden = _playbackSpeedViewHidden = YES;
  1528. if (_equalizerView.hidden == NO)
  1529. _equalizerView.hidden = YES;
  1530. self.videoFilterView.hidden = !_videoFiltersHidden;
  1531. _videoFiltersHidden = self.videoFilterView.hidden;
  1532. }
  1533. - (IBAction)videoFilterSliderAction:(id)sender
  1534. {
  1535. if (sender == self.hueSlider)
  1536. _vpc.hue = self.hueSlider.value;
  1537. else if (sender == self.contrastSlider)
  1538. _vpc.contrast = self.contrastSlider.value;
  1539. else if (sender == self.brightnessSlider)
  1540. _vpc.brightness = self.brightnessSlider.value;
  1541. else if (sender == self.saturationSlider)
  1542. _vpc.saturation = self.saturationSlider.value;
  1543. else if (sender == self.gammaSlider)
  1544. _vpc.gamma = self.gammaSlider.value;
  1545. else if (sender == self.resetVideoFilterButton) {
  1546. [self resetVideoFiltersSliders];
  1547. [_vpc resetFilters];
  1548. } else
  1549. APLog(@"unknown sender for videoFilterSliderAction");
  1550. [self _resetIdleTimer];
  1551. }
  1552. - (void)appBecameActive:(NSNotification *)aNotification
  1553. {
  1554. if ([_delegate movieViewControllerShouldBeDisplayed:self]) {
  1555. [_vpc recoverDisplayedMetadata];
  1556. if (_vpc.videoOutputView != self.movieView) {
  1557. _vpc.videoOutputView = self.movieView;
  1558. }
  1559. }
  1560. }
  1561. #pragma mark - playback view
  1562. - (IBAction)videoDimensionAction:(id)sender
  1563. {
  1564. if (sender == self.timeNavigationTitleView.aspectRatioButton) {
  1565. [[VLCPlaybackService sharedInstance] switchAspectRatio:NO];
  1566. }
  1567. }
  1568. - (IBAction)showPlaybackSpeedView {
  1569. if (!_videoFiltersHidden)
  1570. self.videoFilterView.hidden = _videoFiltersHidden = YES;
  1571. if (_equalizerView.hidden == NO)
  1572. _equalizerView.hidden = YES;
  1573. self.playbackSpeedView.hidden = !_playbackSpeedViewHidden;
  1574. _playbackSpeedViewHidden = self.playbackSpeedView.hidden;
  1575. [self _resetIdleTimer];
  1576. }
  1577. #pragma mark - autorotation
  1578. - (UIInterfaceOrientationMask)supportedInterfaceOrientations
  1579. {
  1580. BOOL orientationIslocked = _interfaceIsLocked || [_vpc currentMediaIs360Video];
  1581. UIInterfaceOrientationMask maskFromOrientation = 1 << _lockedOrientation;
  1582. return orientationIslocked ? maskFromOrientation : UIInterfaceOrientationMaskAll;
  1583. }
  1584. - (BOOL)shouldAutorotate
  1585. {
  1586. UIInterfaceOrientation toInterfaceOrientation = [[UIApplication sharedApplication] statusBarOrientation];
  1587. return UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad
  1588. || toInterfaceOrientation != UIInterfaceOrientationPortraitUpsideDown;
  1589. }
  1590. - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
  1591. {
  1592. [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
  1593. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
  1594. [coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
  1595. if (self.artworkImageView.image)
  1596. #if !NEW_UI
  1597. self.trackNameLabel.hidden = YES;
  1598. #endif
  1599. if (!self->_equalizerView.hidden)
  1600. self->_equalizerView.hidden = YES;
  1601. } completion:nil];
  1602. }
  1603. }
  1604. - (void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection
  1605. {
  1606. if (_vpc.isPlaying && _controlsHidden)
  1607. [self setControlsHidden:NO animated:YES];
  1608. }
  1609. - (NSArray *)getVideoOptionsConstraints
  1610. {
  1611. return @[
  1612. [_videoOptionsControlBar.centerXAnchor constraintEqualToAnchor:self.view.centerXAnchor],
  1613. [_videoOptionsControlBar.bottomAnchor constraintEqualToAnchor:_controllerPanel.topAnchor constant:-50],
  1614. ];
  1615. }
  1616. #pragma mark - External Display
  1617. - (void)showOnDisplay:(UIView *)view
  1618. {
  1619. // if we don't have a renderer we're mirroring and don't want to show the dialog
  1620. BOOL displayExternally = view != _movieView;
  1621. [_playingExternalView shouldDisplay:displayExternally movieView:_movieView];
  1622. _artworkImageView.hidden = displayExternally;
  1623. if (!displayExternally && _movieView.superview != self.view) {
  1624. [self.view addSubview:_movieView];
  1625. [self.view sendSubviewToBack:_movieView];
  1626. _movieView.frame = self.view.frame;
  1627. }
  1628. }
  1629. - (void)handleExternalScreenDidConnect:(NSNotification *)notification
  1630. {
  1631. [self showOnDisplay:_playingExternalView.displayView];
  1632. }
  1633. - (void)handleExternalScreenDidDisconnect:(NSNotification *)notification
  1634. {
  1635. [self showOnDisplay:_movieView];
  1636. }
  1637. #pragma mark - Renderers
  1638. - (void)setupRendererDiscovererManager
  1639. {
  1640. // Create a renderer button for VLCMovieViewController
  1641. _rendererButton = [_services.rendererDiscovererManager setupRendererButton];
  1642. // Setting rendererIcons to white since default is orange
  1643. _rendererButton.tintColor = [UIColor whiteColor];
  1644. [_rendererButton setImage:[UIImage imageNamed:@"renderer"] forState:UIControlStateNormal];
  1645. [_rendererButton setImage:[UIImage imageNamed:@"rendererFull"] forState:UIControlStateSelected];
  1646. __weak typeof(self) weakSelf = self;
  1647. [_services.rendererDiscovererManager addSelectionHandler:^(VLCRendererItem * item) {
  1648. __strong typeof(weakSelf) strongSelf = weakSelf;
  1649. if (item) {
  1650. [strongSelf showOnDisplay:strongSelf->_playingExternalView.displayView];
  1651. } else {
  1652. [strongSelf removedCurrentRendererItem:strongSelf->_vpc.renderer];
  1653. }
  1654. }];
  1655. }
  1656. #pragma mark - VLCRendererDiscovererManagerDelegate
  1657. - (void)removedCurrentRendererItem:(VLCRendererItem *)item
  1658. {
  1659. [self showOnDisplay:_movieView];
  1660. }
  1661. #pragma mark - PlaybackSpeedViewDelegate
  1662. - (void)playbackSpeedViewShouldResetIdleTimer:(PlaybackSpeedView *)playbackSpeedView
  1663. {
  1664. [self _resetIdleTimer];
  1665. }
  1666. - (void)playbackSpeedViewSleepTimerHit:(PlaybackSpeedView *)playbackSpeedView
  1667. {
  1668. [self showSleepTimer];
  1669. }
  1670. #pragma mark - VLCVideoOptionsControlBarDelegate
  1671. - (void)didSelectMoreOptions:(VLCVideoOptionsControlBar * _Nonnull)optionsBar {
  1672. [self toggleMoreOptionsActionSheet];
  1673. }
  1674. - (void)didSelectSubtitle:(VLCVideoOptionsControlBar * _Nonnull)optionsBar {
  1675. NSAssert(0, @"didSelectSubtitle not implemented");
  1676. }
  1677. - (void)didToggleFullScreen:(VLCVideoOptionsControlBar * _Nonnull)optionsBar {
  1678. [_vpc switchAspectRatio:YES];
  1679. }
  1680. - (void)didToggleInterfaceLock:(VLCVideoOptionsControlBar * _Nonnull)optionsBar {
  1681. [self toggleUILock];
  1682. }
  1683. - (void)didToggleRepeat:(VLCVideoOptionsControlBar * _Nonnull)optionsBar {
  1684. [self toggleRepeatMode];
  1685. }
  1686. #pragma mark - VLCMediaMoreOptionsActionSheetDelegate
  1687. - (void)toggleMoreOptionsActionSheet
  1688. {
  1689. [self presentViewController:_moreOptionsActionSheet animated:false completion:^{
  1690. self->_moreOptionsActionSheet.interfaceDisabled = self->_interfaceIsLocked;
  1691. }];
  1692. }
  1693. #pragma mark - VLCMediaMoreOptionsActionSheetDelegate
  1694. - (void) mediaMoreOptionsActionSheetDidToggleInterfaceLockWithState:(BOOL)state
  1695. {
  1696. [self toggleUILock];
  1697. }
  1698. #pragma mark - VLCMediaNavigationBarDelegate
  1699. - (void)mediaNavigationBarDidTapMinimize:(VLCMediaNavigationBar * _Nonnull)mediaNavigationBar {
  1700. [_delegate movieViewControllerDidSelectMinimize:self];
  1701. }
  1702. - (void)mediaNavigationBarDidLongPressMinimize:(VLCMediaNavigationBar * _Nonnull)mediaNavigationBar {
  1703. [self closePlayback:mediaNavigationBar.minimizePlaybackButton];
  1704. }
  1705. - (void)mediaNavigationBarDidToggleChromeCast:(VLCMediaNavigationBar * _Nonnull)mediaNavigationBar {
  1706. // TODO: Add current renderer functionality to chromeCast Button
  1707. NSAssert(0, @"didToggleChromeCast not implemented");
  1708. }
  1709. @end