VLCMovieViewController.m 60 KB

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