VLCMovieViewController.m 62 KB

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