VLCMovieViewController.m 77 KB

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