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, VLCMediaMoreOptionsActionSheetDelegate>
  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. VLCMediaMoreOptionsActionSheet *_moreOptionsActionSheet;
  89. VLCPlaybackController *_vpc;
  90. UIView *_sleepTimerContainer;
  91. UIDatePicker *_sleepTimeDatePicker;
  92. NSInteger _mediaDuration;
  93. NSInteger _numberOfTapSeek;
  94. VLCDeviceMotion *_deviceMotion;
  95. CGFloat _fov;
  96. CGPoint _saveLocation;
  97. CGSize _screenPixelSize;
  98. UIInterfaceOrientation _lockedOrientation;
  99. UIStackView *_navigationBarStackView;
  100. UIButton *_rendererButton;
  101. }
  102. @property (nonatomic, strong) VLCMovieViewControlPanelView *controllerPanel;
  103. @property (nonatomic, strong) VLCService *services;
  104. @property (nonatomic, strong) VLCTimeNavigationTitleView *timeNavigationTitleView;
  105. @property (nonatomic, strong) IBOutlet PlayingExternallyView *playingExternalView;
  106. @property (nonatomic, strong) IBOutlet PlaybackSpeedView *playbackSpeedView;
  107. @property (nonatomic, strong) IBOutlet NSLayoutConstraint *scrubViewTopConstraint;
  108. @end
  109. @implementation VLCMovieViewController
  110. + (void)initialize
  111. {
  112. NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
  113. NSDictionary *appDefaults = @{kVLCShowRemainingTime : @(YES)};
  114. [defaults registerDefaults:appDefaults];
  115. }
  116. - (instancetype)initWithServices:(VLCService *)services
  117. {
  118. self = [super initWithNibName:nil bundle:nil];
  119. if (self) {
  120. NSAssert([services isKindOfClass:[VLCService class]], @"VLCPlayerDisplayController: Injected services class issue");
  121. _services = services;
  122. }
  123. return self;
  124. }
  125. - (void)viewDidLoad
  126. {
  127. [super viewDidLoad];
  128. _vpc = [VLCPlaybackController sharedInstance];
  129. self.extendedLayoutIncludesOpaqueBars = YES;
  130. self.edgesForExtendedLayout = UIRectEdgeAll;
  131. self.videoFilterView.hidden = YES;
  132. _videoFiltersHidden = YES;
  133. _hueLabel.text = NSLocalizedString(@"VFILTER_HUE", nil);
  134. _hueSlider.accessibilityLabel = _hueLabel.text;
  135. _contrastLabel.text = NSLocalizedString(@"VFILTER_CONTRAST", nil);
  136. _contrastSlider.accessibilityLabel = _contrastLabel.text;
  137. _brightnessLabel.text = NSLocalizedString(@"VFILTER_BRIGHTNESS", nil);
  138. _brightnessSlider.accessibilityLabel = _brightnessLabel.text;
  139. _saturationLabel.text = NSLocalizedString(@"VFILTER_SATURATION", nil);
  140. _saturationSlider.accessibilityLabel = _saturationLabel.text;
  141. _gammaLabel.text = NSLocalizedString(@"VFILTER_GAMMA", nil);
  142. _gammaSlider.accessibilityLabel = _gammaLabel.text;
  143. _resetVideoFilterButton.accessibilityLabel = NSLocalizedString(@"VIDEO_FILTER_RESET_BUTTON", nil);
  144. #if !NEW_UI
  145. [self setupMultiSelectionView];
  146. #else
  147. [self setupVideoOptionsControlBar];
  148. _moreOptionsActionSheet = [[VLCMediaMoreOptionsActionSheet alloc] init];
  149. _moreOptionsActionSheet.moreOptionsDelegate = self;
  150. #endif
  151. _scrubHelpLabel.text = NSLocalizedString(@"PLAYBACK_SCRUB_HELP", nil);
  152. self.playbackSpeedView.hidden = YES;
  153. _playbackSpeedViewHidden = YES;
  154. _playbackSpeedView.delegate = self;
  155. NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
  156. [center addObserver:self selector:@selector(handleExternalScreenDidConnect:)
  157. name:UIScreenDidConnectNotification object:nil];
  158. [center addObserver:self selector:@selector(handleExternalScreenDidDisconnect:)
  159. name:UIScreenDidDisconnectNotification object:nil];
  160. [center addObserver:self
  161. selector:@selector(appBecameActive:)
  162. name:UIApplicationDidBecomeActiveNotification
  163. object:nil];
  164. [center addObserver:self
  165. selector:@selector(playbackDidStop:)
  166. name:VLCPlaybackControllerPlaybackDidStop
  167. object:nil];
  168. self.trackNameLabel.text = self.artistNameLabel.text = self.albumNameLabel.text = @"";
  169. _movieView.userInteractionEnabled = NO;
  170. [self setupGestureRecognizers];
  171. _isTapSeeking = NO;
  172. _previousJumpState = VLCMovieJumpStateDefault;
  173. _numberOfTapSeek = 0;
  174. CGRect rect = self.resetVideoFilterButton.frame;
  175. rect.origin.y = rect.origin.y + 5.;
  176. self.resetVideoFilterButton.frame = rect;
  177. if (@available(iOS 11.0, *)) {
  178. [self.movieView setAccessibilityIgnoresInvertColors:YES];
  179. }
  180. [self.movieView setAccessibilityIdentifier:@"Video Player Title"];
  181. [self.movieView setAccessibilityLabel:NSLocalizedString(@"VO_VIDEOPLAYER_TITLE", nil)];
  182. [self.movieView setAccessibilityHint:NSLocalizedString(@"VO_VIDEOPLAYER_DOUBLETAP", nil)];
  183. _trackSelectorContainer = [[VLCTrackSelectorView alloc] initWithFrame:CGRectZero];
  184. _trackSelectorContainer.hidden = YES;
  185. void (^completionBlock)(BOOL finished) = ^(BOOL finished) {
  186. for (UIGestureRecognizer *recognizer in self.view.gestureRecognizers)
  187. [recognizer setEnabled:YES];
  188. self->_trackSelectorContainer.hidden = YES;
  189. };
  190. _trackSelectorContainer.completionHandler = completionBlock;
  191. _trackSelectorContainer.translatesAutoresizingMaskIntoConstraints = NO;
  192. [self.view addSubview:_trackSelectorContainer];
  193. _equalizerView = [[VLCEqualizerView alloc] initWithFrame:CGRectMake(0, 0, 450., 240.)];
  194. _equalizerView.delegate = [VLCPlaybackController sharedInstance];
  195. _equalizerView.UIdelegate = self;
  196. _equalizerView.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleTopMargin;
  197. _equalizerView.hidden = YES;
  198. [self.view addSubview:_equalizerView];
  199. //Sleep Timer initialization
  200. [self sleepTimerInitializer];
  201. [self setupControlPanel];
  202. CGRect screenBounds = [[UIScreen mainScreen] bounds];
  203. _screenPixelSize = CGSizeMake(screenBounds.size.width, screenBounds.size.height);
  204. [self setupConstraints];
  205. [self setupRendererDiscovererManager];
  206. }
  207. - (void) setupMultiSelectionView
  208. {
  209. _multiSelectionView = [[VLCMultiSelectionMenuView alloc] init];
  210. _multiSelectionView.delegate = self;
  211. _multiSelectionView.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin;
  212. _multiSelectionView.hidden = YES;
  213. _multiSelectionView.repeatMode = _vpc.repeatMode;
  214. [self.view addSubview:_multiSelectionView];
  215. }
  216. - (void)setupVideoOptionsControlBar
  217. {
  218. _videoOptionsControlBar = [[VLCVideoOptionsControlBar alloc] init];
  219. _videoOptionsControlBar.delegate = self;
  220. _videoOptionsControlBar.repeatMode = _vpc.repeatMode;
  221. [self.view addSubview:_videoOptionsControlBar];
  222. }
  223. - (void)setupGestureRecognizers
  224. {
  225. _tapOnVideoRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(toggleControlsVisible)];
  226. _tapOnVideoRecognizer.delegate = self;
  227. [self.view addGestureRecognizer:_tapOnVideoRecognizer];
  228. _pinchRecognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(handlePinchGesture:)];
  229. _pinchRecognizer.delegate = self;
  230. _doubleTapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doubleTapRecognized:)];
  231. [_doubleTapRecognizer setNumberOfTapsRequired:2];
  232. [self.view addGestureRecognizer:_doubleTapRecognizer];
  233. [_tapOnVideoRecognizer requireGestureRecognizerToFail:_doubleTapRecognizer];
  234. _tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(togglePlayPause)];
  235. [_tapRecognizer setNumberOfTouchesRequired:2];
  236. _currentPanType = VLCPanTypeNone;
  237. _panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panRecognized:)];
  238. [_panRecognizer setMinimumNumberOfTouches:1];
  239. [_panRecognizer setMaximumNumberOfTouches:1];
  240. _swipeRecognizerLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeRecognized:)];
  241. _swipeRecognizerLeft.direction = UISwipeGestureRecognizerDirectionLeft;
  242. _swipeRecognizerRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeRecognized:)];
  243. _swipeRecognizerRight.direction = UISwipeGestureRecognizerDirectionRight;
  244. _swipeRecognizerUp = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeRecognized:)];
  245. _swipeRecognizerUp.direction = UISwipeGestureRecognizerDirectionUp;
  246. _swipeRecognizerUp.numberOfTouchesRequired = 2;
  247. _swipeRecognizerDown = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeRecognized:)];
  248. _swipeRecognizerDown.direction = UISwipeGestureRecognizerDirectionDown;
  249. _swipeRecognizerDown.numberOfTouchesRequired = 2;
  250. [self.view addGestureRecognizer:_pinchRecognizer];
  251. [self.view addGestureRecognizer:_swipeRecognizerLeft];
  252. [self.view addGestureRecognizer:_swipeRecognizerRight];
  253. [self.view addGestureRecognizer:_swipeRecognizerUp];
  254. [self.view addGestureRecognizer:_swipeRecognizerDown];
  255. [self.view addGestureRecognizer:_panRecognizer];
  256. [self.view addGestureRecognizer:_tapRecognizer];
  257. [_panRecognizer requireGestureRecognizerToFail:_swipeRecognizerLeft];
  258. [_panRecognizer requireGestureRecognizerToFail:_swipeRecognizerRight];
  259. [_panRecognizer requireGestureRecognizerToFail:_swipeRecognizerUp];
  260. [_panRecognizer requireGestureRecognizerToFail:_swipeRecognizerDown];
  261. _panRecognizer.delegate = self;
  262. _swipeRecognizerRight.delegate = self;
  263. _swipeRecognizerLeft.delegate = self;
  264. _swipeRecognizerUp.delegate = self;
  265. _swipeRecognizerDown.delegate = self;
  266. _tapRecognizer.delegate = self;
  267. _doubleTapRecognizer.delegate = self;
  268. }
  269. - (void)setupControlPanel
  270. {
  271. _controllerPanel = [[VLCMovieViewControlPanelView alloc] initWithFrame:CGRectZero];
  272. [_controllerPanel.bwdButton addTarget:self action:@selector(backward:) forControlEvents:UIControlEventTouchUpInside];
  273. [_controllerPanel.fwdButton addTarget:self action:@selector(forward:) forControlEvents:UIControlEventTouchUpInside];
  274. [_controllerPanel.playPauseButton addTarget:self action:@selector(playPause) forControlEvents:UIControlEventTouchUpInside];
  275. [_controllerPanel.moreActionsButton addTarget:self action:@selector(moreActions:) forControlEvents:UIControlEventTouchUpInside];
  276. [_controllerPanel.playbackSpeedButton addTarget:self action:@selector(showPlaybackSpeedView) forControlEvents:UIControlEventTouchUpInside];
  277. [_controllerPanel.trackSwitcherButton addTarget:self action:@selector(switchTrack:) forControlEvents:UIControlEventTouchUpInside];
  278. [_controllerPanel.videoFilterButton addTarget:self action:@selector(videoFilterToggle:) forControlEvents:UIControlEventTouchUpInside];
  279. // HACK: get the slider from volume view
  280. UISlider *volumeSlider = nil;
  281. for (id aView in _controllerPanel.volumeView.subviews){
  282. if ([aView isKindOfClass:[UISlider class]]){
  283. volumeSlider = (UISlider *)aView;
  284. break;
  285. }
  286. }
  287. [volumeSlider addTarget:self action:@selector(volumeSliderAction:) forControlEvents:UIControlEventValueChanged];
  288. _controllerPanel.translatesAutoresizingMaskIntoConstraints = NO;
  289. [self.view addSubview:_controllerPanel];
  290. }
  291. - (void)setupConstraints
  292. {
  293. NSArray *hConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|[panel]|"
  294. options:0
  295. metrics:nil
  296. views:@{@"panel":_controllerPanel}];
  297. NSArray *vConstraints = [NSLayoutConstraint constraintsWithVisualFormat:@"V:[panel]|"
  298. options:0
  299. metrics:nil
  300. views:@{@"panel":_controllerPanel}];
  301. [self.view addConstraints:hConstraints];
  302. [self.view addConstraints:vConstraints];
  303. //constraint within _trackSelectorContainer is setting it's height to the tableviews contentview
  304. NSLayoutConstraint *widthConstraint = [NSLayoutConstraint constraintWithItem:_trackSelectorContainer attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeWidth multiplier:2.0/3.0 constant:0];
  305. widthConstraint.priority = UILayoutPriorityRequired - 1;
  306. NSArray *constraints = @[
  307. [NSLayoutConstraint constraintWithItem:_trackSelectorContainer attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterX multiplier:1 constant:0],
  308. [NSLayoutConstraint constraintWithItem:_trackSelectorContainer attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterY multiplier:1 constant:0],
  309. [NSLayoutConstraint constraintWithItem:_trackSelectorContainer attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationLessThanOrEqual toItem:nil attribute:NSLayoutAttributeWidth multiplier:1 constant:420.0],
  310. widthConstraint,
  311. [NSLayoutConstraint constraintWithItem:_trackSelectorContainer attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationLessThanOrEqual toItem:self.view attribute:NSLayoutAttributeHeight multiplier:2.0/3.0 constant:0],
  312. [_videoFilterView.bottomAnchor constraintEqualToAnchor:_controllerPanel.topAnchor]
  313. ];
  314. #if NEW_UI
  315. constraints = [constraints arrayByAddingObjectsFromArray:[self getVideoOptionsConstraints]];
  316. #endif
  317. [NSLayoutConstraint activateConstraints: constraints];
  318. }
  319. - (UIButton *)doneButton
  320. {
  321. if (!_doneButton) {
  322. _doneButton = [[UIButton alloc] initWithFrame:CGRectZero];
  323. [_doneButton setAccessibilityIdentifier:@"Done"];
  324. [_doneButton addTarget:self action:@selector(closePlayback:) forControlEvents:UIControlEventTouchUpInside];
  325. [_doneButton setTitle:NSLocalizedString(@"BUTTON_DONE", nil) forState:UIControlStateNormal];
  326. [_doneButton setTitleColor:[UIColor grayColor] forState:UIControlStateDisabled];
  327. _doneButton.translatesAutoresizingMaskIntoConstraints = NO;
  328. }
  329. return _doneButton;
  330. }
  331. - (UIStackView *)navigationBarStackView
  332. {
  333. if (!_navigationBarStackView) {
  334. _navigationBarStackView = [[UIStackView alloc] init];
  335. _navigationBarStackView.translatesAutoresizingMaskIntoConstraints = NO;
  336. _navigationBarStackView.spacing = 8;
  337. _navigationBarStackView.axis = UILayoutConstraintAxisHorizontal;
  338. _navigationBarStackView.alignment = UIStackViewAlignmentCenter;
  339. [_navigationBarStackView addArrangedSubview:self.doneButton];
  340. [_navigationBarStackView addArrangedSubview:_timeNavigationTitleView];
  341. [_navigationBarStackView addArrangedSubview:_rendererButton];
  342. }
  343. return _navigationBarStackView;
  344. }
  345. - (void)setupNavigationbar
  346. {
  347. if (!self.timeNavigationTitleView) {
  348. self.timeNavigationTitleView = [[[NSBundle mainBundle] loadNibNamed:@"VLCTimeNavigationTitleView" owner:self options:nil] objectAtIndex:0];
  349. self.timeNavigationTitleView.translatesAutoresizingMaskIntoConstraints = NO;
  350. }
  351. if (_vpc.renderer != nil) {
  352. [_rendererButton setSelected:YES];
  353. }
  354. if (self.navigationBarStackView.superview == nil) {
  355. [self.navigationController.navigationBar addSubview:self.navigationBarStackView];
  356. NSObject *guide = self.navigationController.navigationBar;
  357. if (@available(iOS 11.0, *)) {
  358. guide = self.navigationController.navigationBar.layoutMarginsGuide;
  359. }
  360. [NSLayoutConstraint activateConstraints:@[
  361. [NSLayoutConstraint constraintWithItem:self.navigationBarStackView attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self.navigationController.navigationBar attribute:NSLayoutAttributeCenterY multiplier:1 constant:0],
  362. [NSLayoutConstraint constraintWithItem:self.navigationBarStackView attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:guide attribute:NSLayoutAttributeLeft multiplier:1 constant:8],
  363. [NSLayoutConstraint constraintWithItem:self.navigationBarStackView attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:guide attribute:NSLayoutAttributeRight multiplier:1 constant:-8],
  364. [NSLayoutConstraint constraintWithItem:self.navigationBarStackView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.navigationController.navigationBar attribute:NSLayoutAttributeTop multiplier:1 constant:0],
  365. [NSLayoutConstraint constraintWithItem:self.navigationBarStackView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.navigationController.navigationBar attribute:NSLayoutAttributeBottom multiplier:1 constant:0],
  366. [NSLayoutConstraint constraintWithItem:self.timeNavigationTitleView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:self.navigationBarStackView attribute:NSLayoutAttributeHeight multiplier:1 constant:0],
  367. ]];
  368. self.scrubViewTopConstraint.constant = CGRectGetMaxY(self.navigationController.navigationBar.frame);
  369. }
  370. }
  371. - (void)resetVideoFiltersSliders
  372. {
  373. _brightnessSlider.value = 1.;
  374. _contrastSlider.value = 1.;
  375. _hueSlider.value = 0.;
  376. _saturationSlider.value = 1.;
  377. _gammaSlider.value = 1.;
  378. }
  379. - (void)viewWillAppear:(BOOL)animated
  380. {
  381. [super viewWillAppear:animated];
  382. _vpc.delegate = self;
  383. _lockedOrientation = UIInterfaceOrientationPortrait;
  384. [_vpc recoverPlaybackState];
  385. self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
  386. self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
  387. [self setupNavigationbar];
  388. /* reset audio meta data views */
  389. self.artworkImageView.image = nil;
  390. self.trackNameLabel.text = nil;
  391. self.artistNameLabel.text = nil;
  392. self.albumNameLabel.text = nil;
  393. [self setControlsHidden:NO animated:animated];
  394. [self updateDefaults];
  395. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateDefaults) name:NSUserDefaultsDidChangeNotification object:nil];
  396. VLCRendererDiscovererManager *manager = _services.rendererDiscovererManager;
  397. manager.presentingViewController = self;
  398. manager.delegate = self;
  399. if ([_vpc isPlayingOnExternalScreen]) {
  400. [self showOnDisplay:_playingExternalView.displayView];
  401. }
  402. }
  403. - (void)layoutFrameForMultiSelectionView
  404. {
  405. CGRect controllerPanelFrame = _controllerPanel.frame;
  406. CGRect multiSelectionFrame;
  407. BOOL isIphone = (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone);
  408. if (!isIphone) {
  409. _multiSelectionView.showsEqualizer = YES;
  410. return;
  411. }
  412. BOOL isLandscape = UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation]);
  413. _multiSelectionView.showsEqualizer = isLandscape;
  414. multiSelectionFrame = (CGRect){CGPointMake(0., 0.), [_multiSelectionView proposedDisplaySize]};
  415. multiSelectionFrame.origin.x = controllerPanelFrame.size.width - multiSelectionFrame.size.width;
  416. multiSelectionFrame.origin.y = controllerPanelFrame.origin.y - multiSelectionFrame.size.height;
  417. _multiSelectionView.frame = multiSelectionFrame;
  418. }
  419. - (void)viewDidAppear:(BOOL)animated
  420. {
  421. [super viewDidAppear:animated];
  422. _viewAppeared = YES;
  423. _playbackWillClose = NO;
  424. [_vpc recoverDisplayedMetadata];
  425. [self resetVideoFiltersSliders];
  426. _vpc.videoOutputView = self.movieView;
  427. #if !NEW_UI
  428. _multiSelectionView.repeatMode = _vpc.repeatMode;
  429. _multiSelectionView.shuffleMode = _vpc.isShuffleMode;
  430. #else
  431. _videoOptionsControlBar.repeatMode = _vpc.repeatMode;
  432. #endif
  433. //Media is loaded in the media player, checking the projection type and configuring accordingly.
  434. [self setupForMediaProjection];
  435. }
  436. - (void)viewDidLayoutSubviews
  437. {
  438. CGRect equalizerRect = _equalizerView.frame;
  439. equalizerRect.origin.x = CGRectGetMidX(self.view.bounds) - CGRectGetWidth(equalizerRect)/2.0;
  440. equalizerRect.origin.y = CGRectGetMidY(self.view.bounds) - CGRectGetHeight(equalizerRect)/2.0;
  441. _equalizerView.frame = equalizerRect;
  442. #if !NEW_UI
  443. [self layoutFrameForMultiSelectionView];
  444. #endif
  445. self.scrubViewTopConstraint.constant = CGRectGetMaxY(self.navigationController.navigationBar.frame);
  446. }
  447. - (void)viewWillDisappear:(BOOL)animated
  448. {
  449. if (_vpc.videoOutputView == self.movieView) {
  450. _vpc.videoOutputView = nil;
  451. }
  452. _viewAppeared = NO;
  453. if (_idleTimer) {
  454. [_idleTimer invalidate];
  455. _idleTimer = nil;
  456. }
  457. [super viewWillDisappear:animated];
  458. // hide filter UI for next run
  459. if (!_videoFiltersHidden)
  460. _videoFiltersHidden = YES;
  461. if (_equalizerView.hidden == NO)
  462. _equalizerView.hidden = YES;
  463. if (!_playbackSpeedViewHidden)
  464. _playbackSpeedViewHidden = YES;
  465. if (_interfaceIsLocked)
  466. [self toggleUILock];
  467. // reset tap to seek values
  468. _isTapSeeking = NO;
  469. _previousJumpState = VLCMovieJumpStateDefault;
  470. _numberOfTapSeek = 0;
  471. [[NSNotificationCenter defaultCenter] removeObserver:self name:NSUserDefaultsDidChangeNotification object:nil];
  472. [[NSUserDefaults standardUserDefaults] setBool:_displayRemainingTime forKey:kVLCShowRemainingTime];
  473. }
  474. - (void)viewDidDisappear:(BOOL)animated
  475. {
  476. [super viewDidDisappear:animated];
  477. [self.deviceMotion stopDeviceMotion];
  478. }
  479. - (BOOL)canBecomeFirstResponder
  480. {
  481. return YES;
  482. }
  483. - (void)dismissViewControllerAnimated:(BOOL)flag completion:(void (^)(void))completion
  484. {
  485. [self setControlsHidden:YES animated:flag];
  486. [super dismissViewControllerAnimated:flag completion:completion];
  487. }
  488. - (void)updateDefaults
  489. {
  490. NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
  491. if (!_playbackWillClose) {
  492. _displayRemainingTime = [[defaults objectForKey:kVLCShowRemainingTime] boolValue];
  493. [self updateTimeDisplayButton];
  494. }
  495. _volumeGestureEnabled = [[defaults objectForKey:kVLCSettingVolumeGesture] boolValue];
  496. _playPauseGestureEnabled = [[defaults objectForKey:kVLCSettingPlayPauseGesture] boolValue];
  497. _brightnessGestureEnabled = [[defaults objectForKey:kVLCSettingBrightnessGesture] boolValue];
  498. _seekGestureEnabled = [[defaults objectForKey:kVLCSettingSeekGesture] boolValue];
  499. _closeGestureEnabled = [[defaults objectForKey:kVLCSettingCloseGesture] boolValue];
  500. _variableJumpDurationEnabled = [[defaults objectForKey:kVLCSettingVariableJumpDuration] boolValue];
  501. }
  502. #pragma mark - Initializer helper
  503. - (void)sleepTimerInitializer
  504. {
  505. /* add sleep timer UI */
  506. _sleepTimerContainer = [[VLCFrostedGlasView alloc] initWithFrame:CGRectMake(0., 0., 300., 200.)];
  507. _sleepTimerContainer.center = self.view.center;
  508. _sleepTimerContainer.clipsToBounds = YES;
  509. _sleepTimerContainer.layer.cornerRadius = 5;
  510. _sleepTimerContainer.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleTopMargin;
  511. //Layers used to create a separator for the buttons.
  512. CALayer *horizontalSeparator = [CALayer layer];
  513. horizontalSeparator.frame = CGRectMake(0., 162., 300., 1.);
  514. horizontalSeparator.backgroundColor = [UIColor VLCLightTextColor].CGColor;
  515. CALayer *verticalSeparator = [CALayer layer];
  516. verticalSeparator.frame = CGRectMake(150., 162., 1., 48.);
  517. verticalSeparator.backgroundColor = [UIColor VLCLightTextColor].CGColor;
  518. _sleepTimeDatePicker = [[UIDatePicker alloc] init];
  519. _sleepTimeDatePicker.opaque = NO;
  520. _sleepTimeDatePicker.backgroundColor = [UIColor clearColor];
  521. _sleepTimeDatePicker.tintColor = [UIColor VLCLightTextColor];
  522. _sleepTimeDatePicker.frame = CGRectMake(0., 0., 300., 162.);
  523. _sleepTimeDatePicker.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleTopMargin;
  524. [_sleepTimerContainer addSubview:_sleepTimeDatePicker];
  525. [_sleepTimerContainer.layer addSublayer:horizontalSeparator];
  526. [_sleepTimerContainer.layer addSublayer:verticalSeparator];
  527. UIButton *cancelSleepTimer = [[UIButton alloc] initWithFrame:CGRectMake(0., 162., 150., 48.)];
  528. cancelSleepTimer.backgroundColor = [UIColor clearColor];
  529. [cancelSleepTimer setTitle:NSLocalizedString(@"BUTTON_RESET", nil) forState:UIControlStateNormal];
  530. [cancelSleepTimer setTintColor:[UIColor VLCLightTextColor]];
  531. [cancelSleepTimer setTitleColor:[UIColor VLCDarkTextShadowColor] forState:UIControlStateHighlighted];
  532. [cancelSleepTimer addTarget:self action:@selector(sleepTimerCancel:) forControlEvents:UIControlEventTouchDown];
  533. cancelSleepTimer.contentEdgeInsets = UIEdgeInsetsMake(0, 0, 10, 0);
  534. [_sleepTimerContainer addSubview:cancelSleepTimer];
  535. UIButton *confirmSleepTimer = [[UIButton alloc] initWithFrame:CGRectMake(150., 162., 150., 48.)];
  536. confirmSleepTimer.backgroundColor = [UIColor clearColor];
  537. [confirmSleepTimer setTitle:NSLocalizedString(@"BUTTON_SET", nil) forState:UIControlStateNormal];
  538. [confirmSleepTimer setTintColor:[UIColor VLCLightTextColor]];
  539. [confirmSleepTimer setTitleColor:[UIColor VLCDarkTextShadowColor] forState:UIControlStateHighlighted];
  540. [confirmSleepTimer addTarget:self action:@selector(sleepTimerAction:) forControlEvents:UIControlEventTouchDown];
  541. confirmSleepTimer.contentEdgeInsets = UIEdgeInsetsMake(0, 0, 10, 0);
  542. [_sleepTimerContainer addSubview:confirmSleepTimer];
  543. /* adapt the date picker style to suit our needs */
  544. [_sleepTimeDatePicker setValue:[UIColor whiteColor] forKeyPath:@"textColor"];
  545. SEL selector = NSSelectorFromString(@"setHighlightsToday:");
  546. NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[UIDatePicker instanceMethodSignatureForSelector:selector]];
  547. BOOL no = NO;
  548. [invocation setSelector:selector];
  549. [invocation setArgument:&no atIndex:2];
  550. [invocation invokeWithTarget:_sleepTimeDatePicker];
  551. if (_sleepTimerContainer.subviews.count > 0) {
  552. NSArray *subviewsOfSubview = [_sleepTimeDatePicker.subviews[0] subviews];
  553. NSUInteger subviewCount = subviewsOfSubview.count;
  554. for (NSUInteger x = 0; x < subviewCount; x++) {
  555. if ([subviewsOfSubview[x] isKindOfClass:[UILabel class]])
  556. [subviewsOfSubview[x] setTextColor:[UIColor VLCLightTextColor]];
  557. }
  558. }
  559. _sleepTimeDatePicker.datePickerMode = UIDatePickerModeCountDownTimer;
  560. _sleepTimeDatePicker.minuteInterval = 1;
  561. _sleepTimeDatePicker.minimumDate = [NSDate date];
  562. _sleepTimeDatePicker.countDownDuration = 1200.;
  563. [self.view addSubview:_sleepTimerContainer];
  564. }
  565. #pragma mark - controls visibility
  566. - (NSArray *)itemsForInterfaceLock
  567. {
  568. NSArray *arr = [NSArray arrayWithObjects:
  569. _pinchRecognizer,
  570. _panRecognizer,
  571. _tapRecognizer,
  572. _doneButton,
  573. _doubleTapRecognizer,
  574. _timeNavigationTitleView.minimizePlaybackButton,
  575. _timeNavigationTitleView.positionSlider,
  576. _timeNavigationTitleView.aspectRatioButton,
  577. _controllerPanel.playbackSpeedButton,
  578. _controllerPanel.trackSwitcherButton,
  579. _controllerPanel.bwdButton,
  580. _controllerPanel.playPauseButton,
  581. _controllerPanel.fwdButton,
  582. _controllerPanel.videoFilterButton,
  583. _controllerPanel.volumeView,
  584. _rendererButton,
  585. nil];
  586. #if !NEW_UI
  587. return [arr arrayByAddingObjectsFromArray:
  588. @[_multiSelectionView.equalizerButton,
  589. _multiSelectionView.chapterSelectorButton,
  590. _multiSelectionView.repeatButton,
  591. _multiSelectionView.shuffleButton,
  592. _controllerPanel.volumeView,
  593. _rendererButton]];
  594. #else
  595. return [arr arrayByAddingObjectsFromArray:
  596. @[_videoOptionsControlBar.toggleFullScreenButton,
  597. _videoOptionsControlBar.selectSubtitleButton,
  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 = NO;
  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. }
  898. _positionSet = NO;
  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)moreActions:(UIButton *)sender
  1122. {
  1123. #if !NEW_UI
  1124. [self toggleMultiSelectionView:sender];
  1125. #endif
  1126. [self _resetIdleTimer];
  1127. }
  1128. #pragma mark - multi-select delegation
  1129. - (void)toggleUILock
  1130. {
  1131. _interfaceIsLocked = !_interfaceIsLocked;
  1132. if (_interfaceIsLocked) {
  1133. _lockedOrientation = [[UIApplication sharedApplication] statusBarOrientation];
  1134. }
  1135. NSArray *items = [self itemsForInterfaceLock];
  1136. for (NSObject *item in items) {
  1137. if ([item isKindOfClass:[UIControl class]]) {
  1138. UIControl *control = (UIControl *)item;
  1139. control.enabled = !_interfaceIsLocked;
  1140. } else if ([item isKindOfClass:[UIGestureRecognizer class]]){
  1141. UIGestureRecognizer *gestureRecognizer = (UIGestureRecognizer *)item;
  1142. gestureRecognizer.enabled = !_interfaceIsLocked;
  1143. } else if ([item isKindOfClass:[VLCVolumeView class]]) {
  1144. //The MPVolumeview doesn't adjust it's UI when disabled so we need to set the alpha by hand
  1145. VLCVolumeView *view = (VLCVolumeView *)item;
  1146. view.userInteractionEnabled = !_interfaceIsLocked;
  1147. view.alpha = _interfaceIsLocked ? 0.5 : 1;
  1148. } else {
  1149. NSAssert(NO, @"class not handled");
  1150. }
  1151. }
  1152. #if !NEW_UI
  1153. _multiSelectionView.displayLock = _interfaceIsLocked;
  1154. #else
  1155. _videoOptionsControlBar.interfaceDisabled = _interfaceIsLocked;
  1156. _moreOptionsActionSheet.interfaceDisabled = _interfaceIsLocked;
  1157. #endif
  1158. }
  1159. - (void)toggleEqualizer
  1160. {
  1161. if (_equalizerView.hidden) {
  1162. if (!_playbackSpeedViewHidden)
  1163. self.playbackSpeedView.hidden = _playbackSpeedViewHidden = YES;
  1164. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
  1165. if (!_controlsHidden) {
  1166. self.controllerPanel.hidden = _controlsHidden = YES;
  1167. self.navigationController.navigationBar.hidden = YES;
  1168. }
  1169. }
  1170. _trackSelectorContainer.hidden = YES;
  1171. self.videoFilterView.hidden = _videoFiltersHidden = YES;
  1172. _equalizerView.alpha = 1.;
  1173. _equalizerView.hidden = NO;
  1174. } else
  1175. _equalizerView.hidden = YES;
  1176. }
  1177. - (void)toggleChapterAndTitleSelector
  1178. {
  1179. if (_trackSelectorContainer.hidden == YES || _trackSelectorContainer.switchingTracksNotChapters == YES) {
  1180. _trackSelectorContainer.switchingTracksNotChapters = NO;
  1181. [_trackSelectorContainer updateView];
  1182. _trackSelectorContainer.hidden = NO;
  1183. _trackSelectorContainer.alpha = 1.;
  1184. if (_equalizerView.hidden == NO)
  1185. _equalizerView.hidden = YES;
  1186. if (!_playbackSpeedViewHidden)
  1187. self.playbackSpeedView.hidden = _playbackSpeedViewHidden = YES;
  1188. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
  1189. if (!_controlsHidden) {
  1190. self.controllerPanel.hidden = _controlsHidden = YES;
  1191. }
  1192. }
  1193. _sleepTimerContainer.hidden = YES;
  1194. self.videoFilterView.hidden = _videoFiltersHidden = YES;
  1195. } else {
  1196. _trackSelectorContainer.hidden = YES;
  1197. }
  1198. }
  1199. - (void)toggleRepeatMode
  1200. {
  1201. [[VLCPlaybackController sharedInstance] toggleRepeatMode];
  1202. #if !NEW_UI
  1203. _multiSelectionView.repeatMode = [VLCPlaybackController sharedInstance].repeatMode;
  1204. #else
  1205. _videoOptionsControlBar.repeatMode = [VLCPlaybackController sharedInstance].repeatMode;
  1206. #endif
  1207. }
  1208. - (void)toggleShuffleMode
  1209. {
  1210. _vpc.shuffleMode = !_vpc.isShuffleMode;
  1211. #if !NEW_UI
  1212. _multiSelectionView.shuffleMode = _vpc.isShuffleMode;
  1213. #endif
  1214. }
  1215. - (void)hideMenu
  1216. {
  1217. [UIView animateWithDuration:.2
  1218. animations:^{
  1219. #if !NEW_UI
  1220. self->_multiSelectionView.hidden = YES;
  1221. #else
  1222. self->_videoOptionsControlBar.hidden = YES;
  1223. #endif
  1224. }
  1225. completion:nil];
  1226. [self _resetIdleTimer];
  1227. }
  1228. #pragma mark - multi-touch gestures
  1229. - (void)togglePlayPause
  1230. {
  1231. if (!_playPauseGestureEnabled)
  1232. return;
  1233. if (_vpc.isPlaying) {
  1234. [_vpc pause];
  1235. [self setControlsHidden:NO animated:_controlsHidden];
  1236. } else {
  1237. [_vpc play];
  1238. }
  1239. }
  1240. - (BOOL)prefersHomeIndicatorAutoHidden
  1241. {
  1242. return YES;
  1243. }
  1244. - (VLCPanType)detectPanTypeForPan:(UIPanGestureRecognizer*)panRecognizer
  1245. {
  1246. NSString *deviceType = [[UIDevice currentDevice] model];
  1247. UIWindow *window = [[UIApplication sharedApplication] keyWindow];
  1248. CGFloat windowWidth = CGRectGetWidth(window.bounds);
  1249. CGPoint location = [panRecognizer locationInView:window];
  1250. VLCPanType panType = VLCPanTypeVolume; // default or right side of the screen
  1251. if (location.x < windowWidth / 2)
  1252. panType = VLCPanTypeBrightness;
  1253. // only check for seeking gesture if on iPad , will overwrite last statements if true
  1254. if ([deviceType isEqualToString:@"iPad"] && location.y < 110) {
  1255. panType = VLCPanTypeSeek;
  1256. }
  1257. if ([_vpc currentMediaIs360Video]) {
  1258. panType = VLCPanTypeProjection;
  1259. }
  1260. return panType;
  1261. }
  1262. - (void)panRecognized:(UIPanGestureRecognizer*)panRecognizer
  1263. {
  1264. CGFloat panDirectionX = [panRecognizer velocityInView:self.view].x;
  1265. CGFloat panDirectionY = [panRecognizer velocityInView:self.view].y;
  1266. if (panRecognizer.state == UIGestureRecognizerStateBegan) {
  1267. _currentPanType = [self detectPanTypeForPan:panRecognizer];
  1268. if ([_vpc currentMediaIs360Video]) {
  1269. _saveLocation = [panRecognizer locationInView:self.view];
  1270. [_deviceMotion stopDeviceMotion];
  1271. }
  1272. }
  1273. switch (_currentPanType) {
  1274. case VLCPanTypeSeek: {
  1275. if (!_seekGestureEnabled)
  1276. return;
  1277. double timeRemainingDouble = (-[_vpc remainingTime].intValue*0.001);
  1278. int timeRemaining = timeRemainingDouble;
  1279. if (panDirectionX > 0) {
  1280. if (timeRemaining > 2 ) // to not go outside duration , video will stop
  1281. [_vpc jumpForward:1];
  1282. } else
  1283. [_vpc jumpBackward:1];
  1284. break;
  1285. case VLCPanTypeVolume:
  1286. if (!_volumeGestureEnabled)
  1287. return;
  1288. MPMusicPlayerController *musicPlayer = [MPMusicPlayerController applicationMusicPlayer];
  1289. #pragma clang diagnostic push
  1290. #pragma clang diagnostic ignored "-Wdeprecated"
  1291. // there is no replacement for .volume which we want to use since Apple's susggestion is to not use their overlays
  1292. // but switch to the volume slider exclusively. meh.
  1293. if (panDirectionY > 0)
  1294. musicPlayer.volume -= 0.01;
  1295. else
  1296. musicPlayer.volume += 0.01;
  1297. #pragma clang diagnostic pop
  1298. } break;
  1299. case VLCPanTypeBrightness: {
  1300. if (!_brightnessGestureEnabled)
  1301. return;
  1302. CGFloat brightness = [UIScreen mainScreen].brightness;
  1303. if (panDirectionY > 0)
  1304. brightness = brightness - 0.01;
  1305. else
  1306. brightness = brightness + 0.01;
  1307. // Sanity check since -[UIScreen brightness] does not go by 0.01 steps
  1308. if (brightness > 1.0)
  1309. brightness = 1.0;
  1310. else if (brightness < 0.0)
  1311. brightness = 0.0;
  1312. NSAssert(brightness >= 0 && brightness <= 1, @"Brightness must be within 0 and 1 (it is %f)", brightness);
  1313. [[UIScreen mainScreen] setBrightness:brightness];
  1314. NSString *brightnessHUD = [NSString stringWithFormat:@"%@: %@ %%", NSLocalizedString(@"VFILTER_BRIGHTNESS", nil), [[[NSString stringWithFormat:@"%f",(brightness*100)] componentsSeparatedByString:@"."] objectAtIndex:0]];
  1315. [self.statusLabel showStatusMessage:brightnessHUD];
  1316. } break;
  1317. case VLCPanTypeProjection: {
  1318. [self updateProjectionWithPanRecognizer:panRecognizer];
  1319. } break;
  1320. case VLCPanTypeNone: {
  1321. } break;
  1322. }
  1323. if (panRecognizer.state == UIGestureRecognizerStateEnded) {
  1324. _currentPanType = VLCPanTypeNone;
  1325. if ([_vpc currentMediaIs360Video]) {
  1326. [_deviceMotion startDeviceMotion];
  1327. }
  1328. }
  1329. }
  1330. - (void)updateProjectionWithPanRecognizer:(UIPanGestureRecognizer *)panGestureRecognizer
  1331. {
  1332. CGPoint newLocationInView = [panGestureRecognizer locationInView:self.view];
  1333. CGFloat diffX = newLocationInView.x - _saveLocation.x;
  1334. CGFloat diffY = newLocationInView.y - _saveLocation.y;
  1335. _saveLocation = newLocationInView;
  1336. //screenSizePixel width is used twice to get a constant speed on the movement.
  1337. CGFloat diffYaw = _fov * -diffX / _screenPixelSize.width;
  1338. CGFloat diffPitch = _fov * -diffY / _screenPixelSize.width;
  1339. [self applyYaw:diffYaw pitch:diffPitch];
  1340. }
  1341. - (void)swipeRecognized:(UISwipeGestureRecognizer*)swipeRecognizer
  1342. {
  1343. if (!_seekGestureEnabled)
  1344. return;
  1345. NSString *hudString = @" ";
  1346. int swipeForwardDuration = (_variableJumpDurationEnabled) ? ((int)(_mediaDuration*0.001*0.05)) : FORWARD_SWIPE_DURATION;
  1347. int swipeBackwardDuration = (_variableJumpDurationEnabled) ? ((int)(_mediaDuration*0.001*0.05)) : BACKWARD_SWIPE_DURATION;
  1348. if (swipeRecognizer.direction == UISwipeGestureRecognizerDirectionRight) {
  1349. double timeRemainingDouble = (-[_vpc remainingTime].intValue*0.001);
  1350. int timeRemaining = timeRemainingDouble;
  1351. if (swipeForwardDuration < timeRemaining) {
  1352. if (swipeForwardDuration < 1)
  1353. swipeForwardDuration = 1;
  1354. [_vpc jumpForward:swipeForwardDuration];
  1355. hudString = [NSString stringWithFormat:@"⇒ %is", swipeForwardDuration];
  1356. } else {
  1357. [_vpc jumpForward:(timeRemaining - 5)];
  1358. hudString = [NSString stringWithFormat:@"⇒ %is",(timeRemaining - 5)];
  1359. }
  1360. } else if (swipeRecognizer.direction == UISwipeGestureRecognizerDirectionLeft) {
  1361. [_vpc jumpBackward:swipeBackwardDuration];
  1362. hudString = [NSString stringWithFormat:@"⇐ %is",swipeBackwardDuration];
  1363. } else if (swipeRecognizer.direction == UISwipeGestureRecognizerDirectionUp) {
  1364. [self backward:self];
  1365. hudString = NSLocalizedString(@"BWD_BUTTON", "");
  1366. } else if (swipeRecognizer.direction == UISwipeGestureRecognizerDirectionDown) {
  1367. [self forward:self];
  1368. hudString = NSLocalizedString(@"FWD_BUTTON", "");
  1369. }
  1370. if (swipeRecognizer.state == UIGestureRecognizerStateEnded) {
  1371. [self.statusLabel showStatusMessage:hudString];
  1372. }
  1373. }
  1374. - (void)doubleTapRecognized:(UITapGestureRecognizer *)tapRecognizer
  1375. {
  1376. if (!_seekGestureEnabled)
  1377. return;
  1378. CGFloat screenWidth = self.view.frame.size.width;
  1379. CGFloat backwardBoundary = screenWidth / 3.0;
  1380. CGFloat forwardBoundary = 2 * screenWidth / 3.0;
  1381. CGPoint tapPosition = [tapRecognizer locationInView:self.view];
  1382. //Handling seek reset if tap orientation changes.
  1383. if (tapPosition.x < backwardBoundary) {
  1384. _numberOfTapSeek = _previousJumpState == VLCMovieJumpStateForward ? -1 : _numberOfTapSeek - 1;
  1385. } else if (tapPosition.x > forwardBoundary){
  1386. _numberOfTapSeek = _previousJumpState == VLCMovieJumpStateBackward ? 1 : _numberOfTapSeek + 1;
  1387. } else {
  1388. [_vpc toggleFullScreen];
  1389. return;
  1390. }
  1391. _isTapSeeking = YES;
  1392. [self _seekFromTap];
  1393. }
  1394. - (void)equalizerViewReceivedUserInput
  1395. {
  1396. [self _resetIdleTimer];
  1397. }
  1398. #pragma mark - Video Filter UI
  1399. - (IBAction)videoFilterToggle:(id)sender
  1400. {
  1401. if (!_playbackSpeedViewHidden)
  1402. self.playbackSpeedView.hidden = _playbackSpeedViewHidden = YES;
  1403. if (_equalizerView.hidden == NO)
  1404. _equalizerView.hidden = YES;
  1405. self.videoFilterView.hidden = !_videoFiltersHidden;
  1406. _videoFiltersHidden = self.videoFilterView.hidden;
  1407. }
  1408. - (IBAction)videoFilterSliderAction:(id)sender
  1409. {
  1410. if (sender == self.hueSlider)
  1411. _vpc.hue = self.hueSlider.value;
  1412. else if (sender == self.contrastSlider)
  1413. _vpc.contrast = self.contrastSlider.value;
  1414. else if (sender == self.brightnessSlider)
  1415. _vpc.brightness = self.brightnessSlider.value;
  1416. else if (sender == self.saturationSlider)
  1417. _vpc.saturation = self.saturationSlider.value;
  1418. else if (sender == self.gammaSlider)
  1419. _vpc.gamma = self.gammaSlider.value;
  1420. else if (sender == self.resetVideoFilterButton) {
  1421. [self resetVideoFiltersSliders];
  1422. [_vpc resetFilters];
  1423. } else
  1424. APLog(@"unknown sender for videoFilterSliderAction");
  1425. [self _resetIdleTimer];
  1426. }
  1427. - (void)appBecameActive:(NSNotification *)aNotification
  1428. {
  1429. if ([_delegate movieViewControllerShouldBeDisplayed:self]) {
  1430. [_vpc recoverDisplayedMetadata];
  1431. if (_vpc.videoOutputView != self.movieView) {
  1432. _vpc.videoOutputView = self.movieView;
  1433. }
  1434. }
  1435. }
  1436. #pragma mark - playback view
  1437. - (IBAction)videoDimensionAction:(id)sender
  1438. {
  1439. if (sender == self.timeNavigationTitleView.aspectRatioButton) {
  1440. [[VLCPlaybackController sharedInstance] switchAspectRatio];
  1441. }
  1442. }
  1443. - (IBAction)showPlaybackSpeedView {
  1444. if (!_videoFiltersHidden)
  1445. self.videoFilterView.hidden = _videoFiltersHidden = YES;
  1446. if (_equalizerView.hidden == NO)
  1447. _equalizerView.hidden = YES;
  1448. self.playbackSpeedView.hidden = !_playbackSpeedViewHidden;
  1449. _playbackSpeedViewHidden = self.playbackSpeedView.hidden;
  1450. [self _resetIdleTimer];
  1451. }
  1452. #pragma mark - autorotation
  1453. - (UIInterfaceOrientationMask)supportedInterfaceOrientations
  1454. {
  1455. BOOL orientationIslocked = _interfaceIsLocked || [_vpc currentMediaIs360Video];
  1456. UIInterfaceOrientationMask maskFromOrientation = 1 << _lockedOrientation;
  1457. return orientationIslocked ? maskFromOrientation : UIInterfaceOrientationMaskAll;
  1458. }
  1459. - (BOOL)shouldAutorotate
  1460. {
  1461. UIInterfaceOrientation toInterfaceOrientation = [[UIApplication sharedApplication] statusBarOrientation];
  1462. return UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad
  1463. || toInterfaceOrientation != UIInterfaceOrientationPortraitUpsideDown;
  1464. }
  1465. - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
  1466. {
  1467. [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
  1468. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
  1469. [coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
  1470. if (self.artworkImageView.image)
  1471. self.trackNameLabel.hidden = YES;
  1472. if (!self->_equalizerView.hidden)
  1473. self->_equalizerView.hidden = YES;
  1474. } completion:nil];
  1475. }
  1476. }
  1477. - (void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection
  1478. {
  1479. if (_vpc.isPlaying && _controlsHidden)
  1480. [self setControlsHidden:NO animated:YES];
  1481. }
  1482. - (NSArray *)getVideoOptionsConstraints
  1483. {
  1484. return @[
  1485. [_videoOptionsControlBar.centerXAnchor constraintEqualToAnchor:self.view.centerXAnchor],
  1486. [_videoOptionsControlBar.bottomAnchor constraintEqualToAnchor:_controllerPanel.topAnchor constant:-50],
  1487. ];
  1488. }
  1489. #pragma mark - External Display
  1490. - (void)showOnDisplay:(UIView *)view
  1491. {
  1492. // if we don't have a renderer we're mirroring and don't want to show the dialog
  1493. BOOL displayExternally = view != _movieView;
  1494. [_playingExternalView shouldDisplay:displayExternally movieView:_movieView];
  1495. _artworkImageView.hidden = displayExternally;
  1496. if (!displayExternally && _movieView.superview != self.view) {
  1497. [self.view addSubview:_movieView];
  1498. [self.view sendSubviewToBack:_movieView];
  1499. _movieView.frame = self.view.frame;
  1500. }
  1501. }
  1502. - (void)handleExternalScreenDidConnect:(NSNotification *)notification
  1503. {
  1504. [self showOnDisplay:_playingExternalView.displayView];
  1505. }
  1506. - (void)handleExternalScreenDidDisconnect:(NSNotification *)notification
  1507. {
  1508. [self showOnDisplay:_movieView];
  1509. }
  1510. #pragma mark - Renderers
  1511. - (void)setupRendererDiscovererManager
  1512. {
  1513. // Create a renderer button for VLCMovieViewController
  1514. _rendererButton = [_services.rendererDiscovererManager setupRendererButton];
  1515. // Setting rendererIcons to white since default is orange
  1516. _rendererButton.tintColor = [UIColor whiteColor];
  1517. [_rendererButton setImage:[UIImage imageNamed:@"renderer"] forState:UIControlStateNormal];
  1518. [_rendererButton setImage:[UIImage imageNamed:@"rendererFull"] forState:UIControlStateSelected];
  1519. __weak typeof(self) weakSelf = self;
  1520. [_services.rendererDiscovererManager addSelectionHandler:^(VLCRendererItem * item) {
  1521. __strong typeof(weakSelf) strongSelf = weakSelf;
  1522. if (item) {
  1523. [strongSelf showOnDisplay:strongSelf->_playingExternalView.displayView];
  1524. } else {
  1525. [strongSelf removedCurrentRendererItem:strongSelf->_vpc.renderer];
  1526. }
  1527. }];
  1528. }
  1529. #pragma mark - VLCRendererDiscovererManagerDelegate
  1530. - (void)removedCurrentRendererItem:(VLCRendererItem *)item
  1531. {
  1532. [self showOnDisplay:_movieView];
  1533. }
  1534. #pragma mark - PlaybackSpeedViewDelegate
  1535. - (void)playbackSpeedViewShouldResetIdleTimer:(PlaybackSpeedView *)playbackSpeedView
  1536. {
  1537. [self _resetIdleTimer];
  1538. }
  1539. - (void)playbackSpeedViewSleepTimerHit:(PlaybackSpeedView *)playbackSpeedView
  1540. {
  1541. [self showSleepTimer];
  1542. }
  1543. #pragma mark - VLCVideoOptionsControlBarDelegate
  1544. - (void)didSelectMoreOptions:(VLCVideoOptionsControlBar * _Nonnull)optionsBar {
  1545. [self toggleMoreOptionsActionSheet];
  1546. }
  1547. - (void)didSelectSubtitle:(VLCVideoOptionsControlBar * _Nonnull)optionsBar {
  1548. NSAssert(0, @"didSelectSubtitle not implemented");
  1549. }
  1550. - (void)didToggleFullScreen:(VLCVideoOptionsControlBar * _Nonnull)optionsBar {
  1551. [_vpc toggleFullScreen];
  1552. }
  1553. - (void)didToggleInterfaceLock:(VLCVideoOptionsControlBar * _Nonnull)optionsBar {
  1554. [self toggleUILock];
  1555. }
  1556. - (void)didToggleRepeat:(VLCVideoOptionsControlBar * _Nonnull)optionsBar {
  1557. [self toggleRepeatMode];
  1558. }
  1559. - (void)toggleMoreOptionsActionSheet
  1560. {
  1561. [self presentViewController:_moreOptionsActionSheet animated:false completion:^{
  1562. self->_moreOptionsActionSheet.interfaceDisabled = self->_interfaceIsLocked;
  1563. }];
  1564. }
  1565. #pragma mark - VLCMediaMoreOptionsActionSheetDelegate
  1566. - (void) mediaMoreOptionsDidToggleInterfaceLockWithState:(BOOL)state
  1567. {
  1568. [self toggleUILock];
  1569. }
  1570. @end