VLCMovieViewController.m 64 KB

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