Commit a63b554d authored by Carola Nitz's avatar Carola Nitz

PlaybackSpeedView: move code into own class

(cherry picked from commit c7147d20)
parent 6e3873f4
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
/*****************************************************************************
* PlaybaclSpeedView.swift
*
* Copyright © 2018 VLC authors and VideoLAN
* Copyright © 2018 Videolabs
*
* Authors: Carola Nitz <caro@videolan.org>
*
* Refer to the COPYING file of the official project for license.
*****************************************************************************/
@objc protocol PlaybackSpeedViewDelegate: NSObjectProtocol {
func playbackSpeedViewShouldResetIdleTimer(_ playbackSpeedView: PlaybackSpeedView)
func playbackSpeedViewSleepTimerHit(_ playbackSpeedView: PlaybackSpeedView)
}
class PlaybackSpeedView: VLCFrostedGlasView {
@IBInspectable var nibName: String?
@IBOutlet weak var playbackSpeedSlider: UISlider!
@IBOutlet weak var playbackSpeedLabel: UILabel!
@IBOutlet weak var playbackSpeedIndicator: UILabel!
@IBOutlet weak var audioDelaySlider: UISlider!
@IBOutlet weak var audioDelayLabel: UILabel!
@IBOutlet weak var audioDelayIndicator: UILabel!
@IBOutlet weak var spuDelaySlider: UISlider!
@IBOutlet weak var spuDelayLabel: UILabel!
@IBOutlet weak var spuDelayIndicator: UILabel!
@IBOutlet weak var sleepTimerButton: UIButton!
@objc weak var delegate: PlaybackSpeedViewDelegate?
private var sleepCountDownTimer: Timer?
let vpc = VLCPlaybackController.sharedInstance()
override func awakeFromNib() {
super.awakeFromNib()
xibSetup()
playbackSpeedLabel.text = NSLocalizedString("PLAYBACK_SPEED", comment:"")
playbackSpeedSlider.accessibilityLabel = playbackSpeedLabel.text
audioDelayLabel.text = NSLocalizedString("AUDIO_DELAY", comment:"")
audioDelaySlider.accessibilityLabel = audioDelayLabel.text
spuDelayLabel.text = NSLocalizedString("SPU_DELAY", comment:"")
spuDelaySlider.accessibilityLabel = spuDelayLabel.text
sleepTimerButton.setTitle(NSLocalizedString("BUTTON_SLEEP_TIMER", comment:""), for: .normal)
sleepTimerButton.accessibilityLabel = sleepTimerButton.title(for: .normal)
}
func xibSetup() {
guard let view = loadViewFromNib() else { return }
view.frame = bounds
view.autoresizingMask =
[.flexibleWidth, .flexibleHeight]
addSubview(view)
}
func loadViewFromNib() -> PlaybackSpeedView? {
guard let nibName = nibName else { return nil }
let bundle = Bundle(for: type(of: self))
let nib = UINib(nibName: nibName, bundle: bundle)
return nib.instantiate(
withOwner: self,
options: nil).first as? PlaybackSpeedView
}
@objc func prepareForMediaPlayback(controller: VLCPlaybackController) {
let playbackRate = controller.playbackRate
playbackSpeedSlider.value = log2(playbackRate)
playbackSpeedIndicator.text = String(format: "%.2fx", playbackRate)
let audioDelay = controller.audioDelay
audioDelaySlider.value = audioDelay
audioDelayIndicator.text = String(format: "%d ms", audioDelay)
let subtitleDelay = controller.subtitleDelay
spuDelaySlider.value = subtitleDelay
spuDelayIndicator.text = String(format: "%d ms", subtitleDelay)
}
@objc func updateSleepTimerButton() {
var title = NSLocalizedString("BUTTON_SLEEP_TIMER", comment:"")
if vpc.sleepTimer.isValid {
let remainSeconds = vpc.sleepTimer.fireDate.timeIntervalSinceNow
let hour = remainSeconds / 3600
let minute = (remainSeconds - hour * 3600) / 60
let second = remainSeconds.truncatingRemainder(dividingBy: 60)
title = title.appendingFormat(" %02d:%02d:%02d", hour, minute, second)
} else {
sleepCountDownTimer?.invalidate()
}
sleepTimerButton.setTitle(title, for: .normal)
}
@objc func setupSleepTimerIfNecessary() {
if sleepCountDownTimer == nil || !sleepCountDownTimer!.isValid {
sleepCountDownTimer = Timer(timeInterval: 1, target: self, selector: #selector(updateSleepTimerButton), userInfo: nil, repeats: true)
}
}
@IBAction func sleepTimer(sender: UIButton) {
delegate?.playbackSpeedViewSleepTimerHit(self)
}
@IBAction func playbackSliderAction(sender: UISlider) {
if sender == playbackSpeedSlider {
let speed = exp2(sender.value)
vpc.playbackRate = speed
playbackSpeedIndicator.text = String(format: "%.2fx", speed)
} else if sender == audioDelaySlider {
let delay = round(sender.value / 50) * 50
vpc.audioDelay = delay
sender.setValue(delay, animated: false)
audioDelayIndicator.text = String(format: "%.0f ms", delay)
} else if sender == spuDelaySlider {
let delay = round(sender.value / 50) * 50
vpc.subtitleDelay = delay
sender.setValue(delay, animated: false)
spuDelayIndicator.text = String(format: "%.0f ms", delay)
}
delegate?.playbackSpeedViewShouldResetIdleTimer(self)
}
}
......@@ -32,7 +32,6 @@ typedef NS_ENUM(NSInteger, VLCMovieJumpState) {
@property (nonatomic, strong) IBOutlet UIView *movieView;
@property (nonatomic, strong) IBOutlet VLCTimeNavigationTitleView *timeNavigationTitleView;
@property (nonatomic, strong) IBOutlet UIButton *sleepTimerButton;
@property (nonatomic, strong) IBOutlet VLCStatusLabel *statusLabel;
@property (nonatomic, strong) IBOutlet VLCFrostedGlasView *videoFilterView;
......@@ -48,17 +47,6 @@ typedef NS_ENUM(NSInteger, VLCMovieJumpState) {
@property (nonatomic, strong) IBOutlet UISlider *gammaSlider;
@property (nonatomic, strong) IBOutlet UIButton *resetVideoFilterButton;
@property (nonatomic, strong) IBOutlet VLCFrostedGlasView *playbackSpeedView;
@property (nonatomic, strong) IBOutlet UISlider *playbackSpeedSlider;
@property (nonatomic, strong) IBOutlet UILabel *playbackSpeedLabel;
@property (nonatomic, strong) IBOutlet UILabel *playbackSpeedIndicator;
@property (nonatomic, strong) IBOutlet UISlider *audioDelaySlider;
@property (nonatomic, strong) IBOutlet UILabel *audioDelayLabel;
@property (nonatomic, strong) IBOutlet UILabel *audioDelayIndicator;
@property (nonatomic, strong) IBOutlet UISlider *spuDelaySlider;
@property (nonatomic, strong) IBOutlet UILabel *spuDelayLabel;
@property (nonatomic, strong) IBOutlet UILabel *spuDelayIndicator;
@property (nonatomic, strong) IBOutlet VLCFrostedGlasView *scrubIndicatorView;
@property (nonatomic, strong) IBOutlet UILabel *currentScrubSpeedLabel;
@property (nonatomic, strong) IBOutlet UILabel *scrubHelpLabel;
......@@ -80,11 +68,8 @@ typedef NS_ENUM(NSInteger, VLCMovieJumpState) {
- (IBAction)positionSliderDrag:(id)sender;
- (IBAction)toggleTimeDisplay:(id)sender;
- (IBAction)sleepTimer:(id)sender;
- (IBAction)videoFilterSliderAction:(id)sender;
- (IBAction)playbackSliderAction:(id)sender;
- (IBAction)videoDimensionAction:(id)sender;
- (void)toggleRepeatMode;
......
......@@ -2,7 +2,7 @@
* VLCMovieViewController.m
* VLC for iOS
*****************************************************************************
* Copyright (c) 2013-2017 VideoLAN. All rights reserved.
* Copyright (c) 2013-2018 VideoLAN. All rights reserved.
* $Id$
*
* Authors: Felix Paul Kühne <fkuehne # videolan.org>
......@@ -54,7 +54,7 @@ typedef NS_ENUM(NSInteger, VLCPanType) {
VLCPanTypeProjection
};
@interface VLCMovieViewController () <UIGestureRecognizerDelegate, VLCMultiSelectionViewDelegate, VLCEqualizerViewUIDelegate, VLCPlaybackControllerDelegate, VLCDeviceMotionDelegate, VLCRendererDiscovererManagerDelegate>
@interface VLCMovieViewController () <UIGestureRecognizerDelegate, VLCMultiSelectionViewDelegate, VLCEqualizerViewUIDelegate, VLCPlaybackControllerDelegate, VLCDeviceMotionDelegate, VLCRendererDiscovererManagerDelegate, PlaybackSpeedViewDelegate>
{
BOOL _controlsHidden;
BOOL _videoFiltersHidden;
......@@ -105,7 +105,6 @@ typedef NS_ENUM(NSInteger, VLCPanType) {
UIView *_sleepTimerContainer;
UIDatePicker *_sleepTimeDatePicker;
NSTimer *_sleepCountDownTimer;
NSInteger _mediaDuration;
NSInteger _numberOfTapSeek;
......@@ -122,6 +121,7 @@ typedef NS_ENUM(NSInteger, VLCPanType) {
@property (nonatomic, strong) VLCMovieViewControlPanelView *controllerPanel;
@property (nonatomic, strong) UIPopoverController *masterPopoverController;
@property (nonatomic, strong) IBOutlet PlayingExternallyView *playingExternalView;
@property (nonatomic, strong) IBOutlet PlaybackSpeedView *playbackSpeedView;
@end
......@@ -161,16 +161,8 @@ typedef NS_ENUM(NSInteger, VLCPanType) {
_saturationSlider.accessibilityLabel = _saturationLabel.text;
_gammaLabel.text = NSLocalizedString(@"VFILTER_GAMMA", nil);
_gammaSlider.accessibilityLabel = _gammaLabel.text;
_playbackSpeedLabel.text = NSLocalizedString(@"PLAYBACK_SPEED", nil);
_playbackSpeedSlider.accessibilityLabel = _playbackSpeedLabel.text;
_audioDelayLabel.text = NSLocalizedString(@"AUDIO_DELAY", nil);
_audioDelaySlider.accessibilityLabel = _audioDelayLabel.text;
_spuDelayLabel.text = NSLocalizedString(@"SPU_DELAY", nil);
_spuDelaySlider.accessibilityLabel = _spuDelayLabel.text;
_resetVideoFilterButton.accessibilityLabel = NSLocalizedString(@"VIDEO_FILTER_RESET_BUTTON", nil);
_sleepTimerButton.accessibilityLabel = NSLocalizedString(@"BUTTON_SLEEP_TIMER", nil);
[_sleepTimerButton setTitle:NSLocalizedString(@"BUTTON_SLEEP_TIMER", nil) forState:UIControlStateNormal];
_multiSelectionView = [[VLCMultiSelectionMenuView alloc] init];
_multiSelectionView.delegate = self;
......@@ -182,6 +174,7 @@ typedef NS_ENUM(NSInteger, VLCPanType) {
self.playbackSpeedView.hidden = YES;
_playbackSpeedViewHidden = YES;
_playbackSpeedView.delegate = self;
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
[center addObserver:self selector:@selector(handleExternalScreenDidConnect:)
name:UIScreenDidConnectNotification object:nil];
......@@ -763,6 +756,9 @@ typedef NS_ENUM(NSInteger, VLCPanType) {
if (_controlsHidden && !_videoFiltersHidden)
_videoFiltersHidden = YES;
if (_controlsHidden && !_playbackSpeedViewHidden)
_playbackSpeedViewHidden = YES;
if (_isTapSeeking)
_numberOfTapSeek = 0;
......@@ -985,22 +981,6 @@ typedef NS_ENUM(NSInteger, VLCPanType) {
[self.timeNavigationTitleView setNeedsLayout];
}
- (void)updateSleepTimerButton
{
NSMutableString *title = [NSMutableString stringWithString:NSLocalizedString(@"BUTTON_SLEEP_TIMER", nil)];
if (_vpc.sleepTimer != nil && _vpc.sleepTimer.valid) {
int remainSeconds = (int)[_vpc.sleepTimer.fireDate timeIntervalSinceNow];
int hour = remainSeconds / 3600;
int minute = (remainSeconds - hour * 3600) / 60;
int second = remainSeconds % 60;
[title appendFormat:@" %02d:%02d:%02d", hour, minute, second];
} else {
[_sleepCountDownTimer invalidate];
}
[_sleepTimerButton setTitle:title forState:UIControlStateNormal];
}
#pragma mark - playback controller delegation
- (void)playbackPositionUpdated:(VLCPlaybackController *)controller
......@@ -1023,17 +1003,7 @@ typedef NS_ENUM(NSInteger, VLCPanType) {
self.timeNavigationTitleView.timeDisplayButton.accessibilityLabel = @"";
[_equalizerView reloadData];
double playbackRate = controller.playbackRate;
self.playbackSpeedSlider.value = log2(playbackRate);
self.playbackSpeedIndicator.text = [NSString stringWithFormat:@"%.2fx", playbackRate];
float audioDelay = controller.audioDelay;
self.audioDelaySlider.value = audioDelay;
self.audioDelayIndicator.text = [NSString stringWithFormat:@"%d ms", (int) audioDelay];
float subtitleDelay = controller.subtitleDelay;
self.spuDelaySlider.value = subtitleDelay;
self.spuDelayIndicator.text = [NSString stringWithFormat:@"%d ms", (int) subtitleDelay];
[_playbackSpeedView prepareForMediaPlaybackWithController:controller];
[self _resetIdleTimer];
}
......@@ -1147,7 +1117,7 @@ currentMediaHasTrackToChooseFrom:(BOOL)currentMediaHasTrackToChooseFrom
[self _resetIdleTimer];
}
- (IBAction)sleepTimer:(id)sender
- (void)showSleepTimer
{
if (!_playbackSpeedViewHidden)
self.playbackSpeedView.hidden = _playbackSpeedViewHidden = YES;
......@@ -1182,13 +1152,7 @@ currentMediaHasTrackToChooseFrom:(BOOL)currentMediaHasTrackToChooseFrom
{
[_vpc scheduleSleepTimerWithInterval:_sleepTimeDatePicker.countDownDuration];
if (_sleepCountDownTimer == nil || _sleepCountDownTimer.valid == NO) {
_sleepCountDownTimer = [NSTimer scheduledTimerWithTimeInterval:1
target:self
selector:@selector(updateSleepTimerButton)
userInfo:nil
repeats:YES];
}
[_playbackSpeedView setupSleepTimerIfNecessary];
[self.statusLabel showStatusMessage:NSLocalizedString(@"SLEEP_TIMER_UPDATED", nil)];
[self setControlsHidden:YES animated:YES];
}
......@@ -1594,26 +1558,6 @@ currentMediaHasTrackToChooseFrom:(BOOL)currentMediaHasTrackToChooseFrom
}
#pragma mark - playback view
- (IBAction)playbackSliderAction:(UISlider *)sender
{
if (sender == _playbackSpeedSlider) {
double speed = exp2(sender.value);
_vpc.playbackRate = speed;
self.playbackSpeedIndicator.text = [NSString stringWithFormat:@"%.2fx", speed];
} else if (sender == _audioDelaySlider) {
int delay = ((int) round(sender.value / 50.)) * 50;
_vpc.audioDelay = delay;
[sender setValue:delay animated:NO];
_audioDelayIndicator.text = [NSString stringWithFormat:@"%d ms", delay];
} else if (sender == _spuDelaySlider) {
int delay = (int) (round(sender.value / 50.)) * 50;
_vpc.subtitleDelay = delay;
[sender setValue:delay animated:NO];
_spuDelayIndicator.text = [NSString stringWithFormat:@"%d ms", delay];
}
[self _resetIdleTimer];
}
- (IBAction)videoDimensionAction:(id)sender
{
......@@ -1724,4 +1668,17 @@ currentMediaHasTrackToChooseFrom:(BOOL)currentMediaHasTrackToChooseFrom
{
[self showOnDisplay:_movieView];
}
#pragma mark - PlaybackSpeedViewDelegate
- (void)playbackSpeedViewShouldResetIdleTimer:(PlaybackSpeedView *)playbackSpeedView
{
[self _resetIdleTimer];
}
- (void)playbackSpeedViewSleepTimerHit:(PlaybackSpeedView *)playbackSpeedView
{
[self showSleepTimer];
}
@end
......@@ -14,6 +14,8 @@
41273A3C1A955C4100A2EF77 /* VLCMigrationViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 41273A3A1A955C4100A2EF77 /* VLCMigrationViewController.m */; };
41273A3D1A955C4100A2EF77 /* VLCMigrationViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 41273A3B1A955C4100A2EF77 /* VLCMigrationViewController.xib */; };
412BE7531FC4947400ACCC42 /* VLCMediaData+VLCDragAndDrop.swift in Sources */ = {isa = PBXBuildFile; fileRef = 412BE7521FC4947400ACCC42 /* VLCMediaData+VLCDragAndDrop.swift */; };
414327A521B6E55700B061F6 /* PlaybackSpeedView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 414327A421B6E55700B061F6 /* PlaybackSpeedView.swift */; };
414327A721B6E66E00B061F6 /* PlaybackSpeedView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 414327A621B6E66E00B061F6 /* PlaybackSpeedView.xib */; };
4144C4661A0ED6C700918C89 /* Reachability.m in Sources */ = {isa = PBXBuildFile; fileRef = 7D3784E6183A99E1009EE944 /* Reachability.m */; };
4152F1621FEF19BD00F1908B /* KeychainCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4152F1611FEF19BD00F1908B /* KeychainCoordinator.swift */; };
416443862048419E00CAC646 /* DeviceMotion.swift in Sources */ = {isa = PBXBuildFile; fileRef = 416443852048419E00CAC646 /* DeviceMotion.swift */; };
......@@ -745,10 +747,14 @@
3C12F87F27BDCE3D0A58354E /* Pods-VLC-iOS-no-watch-Debug.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-VLC-iOS-no-watch-Debug.debug.xcconfig"; path = "Pods/Target Support Files/Pods-VLC-iOS-no-watch-Debug/Pods-VLC-iOS-no-watch-Debug.debug.xcconfig"; sourceTree = "<group>"; };
3DD533B1D45EEA70099433D8 /* libPods-VLC-iOS-no-watch.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-VLC-iOS-no-watch.a"; sourceTree = BUILT_PRODUCTS_DIR; };
402E6F0E5362B530B7909338 /* libPods-VLC-iOS.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-VLC-iOS.a"; sourceTree = BUILT_PRODUCTS_DIR; };
41273A391A955C4100A2EF77 /* VLCMigrationViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = VLCMigrationViewController.h; path = Sources/VLCMigrationViewController.h; sourceTree = SOURCE_ROOT; };
41273A3A1A955C4100A2EF77 /* VLCMigrationViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = VLCMigrationViewController.m; path = Sources/VLCMigrationViewController.m; sourceTree = SOURCE_ROOT; };
41273A3B1A955C4100A2EF77 /* VLCMigrationViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = VLCMigrationViewController.xib; path = Sources/VLCMigrationViewController.xib; sourceTree = SOURCE_ROOT; };
412BE7521FC4947400ACCC42 /* VLCMediaData+VLCDragAndDrop.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = "VLCMediaData+VLCDragAndDrop.swift"; path = "Sources/VLCMediaData+VLCDragAndDrop.swift"; sourceTree = SOURCE_ROOT; };
414327A421B6E55700B061F6 /* PlaybackSpeedView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = PlaybackSpeedView.swift; path = Sources/PlaybackSpeedView.swift; sourceTree = "<group>"; };
414327A621B6E66E00B061F6 /* PlaybackSpeedView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = PlaybackSpeedView.xib; path = Resources/PlaybackSpeedView.xib; sourceTree = "<group>"; };
4152F1611FEF19BD00F1908B /* KeychainCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = KeychainCoordinator.swift; path = Sources/KeychainCoordinator.swift; sourceTree = "<group>"; };
416443852048419E00CAC646 /* DeviceMotion.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = DeviceMotion.swift; path = Sources/DeviceMotion.swift; sourceTree = "<group>"; };
416DACB620B6DB9A001BC75D /* PlayingExternallyView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlayingExternallyView.swift; sourceTree = "<group>"; };
......@@ -1924,6 +1930,7 @@
41F9BC7A1F4F20E400268461 /* VLCTrackSelectorView.h */,
41F9BC7B1F4F20E400268461 /* VLCTrackSelectorView.m */,
8D43712C2056AF1600F36458 /* VLCRendererDiscovererManager.swift */,
414327A421B6E55700B061F6 /* PlaybackSpeedView.swift */,
);
name = Playback;
sourceTree = "<group>";
......@@ -2155,6 +2162,7 @@
7DBBF190183AB4300009A339 /* VLCMovieViewController~ipad.xib */,
7DBBF191183AB4300009A339 /* VLCMovieViewController~iphone.xib */,
418108792142894A0046A931 /* PlayingExternallyView.xib */,
414327A621B6E66E00B061F6 /* PlaybackSpeedView.xib */,
);
name = XIBs;
sourceTree = "<group>";
......@@ -3311,6 +3319,7 @@
7D5DD5C717590ABF001421E3 /* About Contents.html in Resources */,
7DBBF19B183AB4300009A339 /* VLCCloudStorageTableViewCell~iphone.xib in Resources */,
7D92897B1877467E009108FD /* VLCFirstStepsFourthPageViewController~iphone.xib in Resources */,
414327A721B6E66E00B061F6 /* PlaybackSpeedView.xib in Resources */,
7D1516461868D7E0004B18F3 /* VLCFirstStepsSixthPageViewController~iphone.xib in Resources */,
41273A3D1A955C4100A2EF77 /* VLCMigrationViewController.xib in Resources */,
41FE2A932191DD8200F451CD /* Launch Screen.storyboard in Resources */,
......@@ -3930,6 +3939,7 @@
41F9BC7C1F4F20E400268461 /* VLCTrackSelectorView.m in Sources */,
7D378499183A98D1009EE944 /* VLCPlaylistCollectionViewCell.m in Sources */,
DD8F84311B00EB3B0009138A /* VLCPlaybackController+MediaLibrary.m in Sources */,
414327A521B6E55700B061F6 /* PlaybackSpeedView.swift in Sources */,
41EB91DD1F7BFF8500821AA5 /* VLCMetadata.m in Sources */,
41DFC6C62100BAAF00EEC9E3 /* VLCDocumentClass.swift in Sources */,
DD3EFF551BDEBCE500B68579 /* VLCLocalNetworkServiceBrowserDSM.m in Sources */,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment