VLCMovieViewController.m 70 KB

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