VLCMovieViewController.m 75 KB

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