VLCMovieViewController.m 64 KB

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