Explorar el Código

Implement sleep timer (close #8640)

Felix Paul Kühne hace 10 años
padre
commit
ca26e9e674

+ 23 - 10
Resources/VLCMovieViewController~ipad.xib

@@ -48,6 +48,7 @@
                 <outlet property="saturationSlider" destination="149" id="168"/>
                 <outlet property="scrubHelpLabel" destination="243" id="247"/>
                 <outlet property="scrubIndicatorView" destination="242" id="245"/>
+                <outlet property="sleepTimerButton" destination="aXd-S6-sb9" id="g5b-DC-APw"/>
                 <outlet property="spuDelayIndicator" destination="cTE-tb-Z89" id="Ll9-wY-xca"/>
                 <outlet property="spuDelayLabel" destination="NX8-Zc-K6Y" id="WLd-cA-fUn"/>
                 <outlet property="spuDelaySlider" destination="juX-HR-PqD" id="x4D-ki-Lwk"/>
@@ -194,72 +195,84 @@
                     <color key="backgroundColor" white="0.0" alpha="0.60999999999999999" colorSpace="custom" customColorSpace="calibratedWhite"/>
                 </view>
                 <view contentMode="scaleToFill" id="176" userLabel="Delays &amp; Speed" customClass="VLCFrostedGlasView">
-                    <rect key="frame" x="123" y="849" width="320" height="122"/>
+                    <rect key="frame" x="123" y="814" width="320" height="157"/>
                     <autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMinY="YES"/>
                     <subviews>
                         <label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" text="Audio delay" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="bQc-dz-mB8">
-                            <rect key="frame" x="20" y="6" width="280" height="21"/>
+                            <rect key="frame" x="20" y="7" width="280" height="21"/>
                             <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
                             <fontDescription key="fontDescription" type="system" pointSize="13"/>
                             <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
                             <nil key="highlightedColor"/>
                         </label>
                         <slider opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" minValue="-30" maxValue="30" id="ahb-li-nqH" customClass="VLCSlider">
-                            <rect key="frame" x="18" y="20" width="284" height="29"/>
+                            <rect key="frame" x="18" y="21" width="284" height="29"/>
                             <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
                             <connections>
                                 <action selector="playbackSliderAction:" destination="-1" eventType="valueChanged" id="MB1-sB-W8m"/>
                             </connections>
                         </slider>
                         <label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" text="1.00x" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="FYO-Rd-Vjg">
-                            <rect key="frame" x="20" y="6" width="280" height="21"/>
+                            <rect key="frame" x="20" y="7" width="280" height="21"/>
                             <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
                             <fontDescription key="fontDescription" type="system" pointSize="13"/>
                             <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
                             <nil key="highlightedColor"/>
                         </label>
                         <label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" text="Subtitles delay" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="NX8-Zc-K6Y">
-                            <rect key="frame" x="20" y="43" width="280" height="21"/>
+                            <rect key="frame" x="20" y="44" width="280" height="21"/>
                             <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
                             <fontDescription key="fontDescription" type="system" pointSize="13"/>
                             <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
                             <nil key="highlightedColor"/>
                         </label>
                         <slider opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" minValue="-30" maxValue="30" id="juX-HR-PqD" customClass="VLCSlider">
-                            <rect key="frame" x="18" y="57" width="284" height="29"/>
+                            <rect key="frame" x="18" y="58" width="284" height="29"/>
                             <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
                             <connections>
                                 <action selector="playbackSliderAction:" destination="-1" eventType="valueChanged" id="acG-8w-Mgd"/>
                             </connections>
                         </slider>
                         <label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" text="1.00x" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="cTE-tb-Z89">
-                            <rect key="frame" x="20" y="43" width="280" height="21"/>
+                            <rect key="frame" x="20" y="44" width="280" height="21"/>
                             <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
                             <fontDescription key="fontDescription" type="system" pointSize="13"/>
                             <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
                             <nil key="highlightedColor"/>
                         </label>
                         <label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" text="Playback speed" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="181">
-                            <rect key="frame" x="20" y="81" width="280" height="21"/>
+                            <rect key="frame" x="20" y="82" width="280" height="21"/>
                             <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
                             <fontDescription key="fontDescription" type="system" pointSize="13"/>
                             <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
                             <nil key="highlightedColor"/>
                         </label>
                         <slider opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" minValue="-34" maxValue="34" id="180" customClass="VLCSlider">
-                            <rect key="frame" x="18" y="95" width="284" height="29"/>
+                            <rect key="frame" x="18" y="96" width="284" height="29"/>
                             <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
                             <connections>
                                 <action selector="playbackSliderAction:" destination="-1" eventType="valueChanged" id="4Xo-T4-hPJ"/>
                             </connections>
                         </slider>
                         <label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" text="1.00x" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="179">
-                            <rect key="frame" x="20" y="81" width="280" height="21"/>
+                            <rect key="frame" x="20" y="82" width="280" height="21"/>
                             <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
                             <fontDescription key="fontDescription" type="system" pointSize="13"/>
                             <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
                             <nil key="highlightedColor"/>
                         </label>
+                        <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" id="aXd-S6-sb9">
+                            <rect key="frame" x="20" y="119" width="280" height="30"/>
+                            <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
+                            <fontDescription key="fontDescription" type="system" pointSize="15"/>
+                            <state key="normal" title="Sleep Timer">
+                                <color key="titleColor" cocoaTouchSystemColor="lightTextColor"/>
+                                <color key="titleShadowColor" cocoaTouchSystemColor="scrollViewTexturedBackgroundColor"/>
+                            </state>
+                            <connections>
+                                <action selector="sleepTimer:" destination="-1" eventType="touchUpInside" id="2s3-Kx-4uh"/>
+                            </connections>
+                        </button>
                     </subviews>
                 </view>
                 <view hidden="YES" userInteractionEnabled="NO" contentMode="scaleToFill" id="123" userLabel="Playing Externally View">

+ 18 - 5
Resources/VLCMovieViewController~iphone.xib

@@ -55,6 +55,7 @@
                 <outlet property="saturationSlider" destination="135" id="152"/>
                 <outlet property="scrubHelpLabel" destination="246" id="249"/>
                 <outlet property="scrubIndicatorView" destination="241" id="247"/>
+                <outlet property="sleepTimerButton" destination="ime-8n-VJ9" id="n2P-yu-8en"/>
                 <outlet property="spuDelayIndicator" destination="IzS-81-KII" id="IXf-sX-Ier"/>
                 <outlet property="spuDelayLabel" destination="KeW-Xp-9I6" id="LMS-pz-Ajj"/>
                 <outlet property="spuDelaySlider" destination="JRI-0m-C0M" id="f8j-Iq-sH3"/>
@@ -170,8 +171,8 @@
                         <bool key="isElement" value="YES"/>
                     </accessibility>
                 </view>
-                <view contentMode="scaleToFill" id="165" userLabel="Controls panel" customClass="VLCFrostedGlasView">
-                    <rect key="frame" x="0.0" y="340" width="320" height="131"/>
+                <view hidden="YES" contentMode="scaleToFill" id="165" userLabel="Controls panel" customClass="VLCFrostedGlasView">
+                    <rect key="frame" x="0.0" y="314" width="320" height="163"/>
                     <autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMinY="YES"/>
                     <subviews>
                         <label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" text="Audio delay" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="8cb-fw-YeF">
@@ -237,9 +238,21 @@
                                 <action selector="playbackSliderAction:" destination="-1" eventType="valueChanged" id="6n6-9i-WXd"/>
                             </connections>
                         </slider>
+                        <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" id="ime-8n-VJ9">
+                            <rect key="frame" x="20" y="133" width="280" height="30"/>
+                            <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
+                            <fontDescription key="fontDescription" type="system" pointSize="15"/>
+                            <state key="normal" title="Sleep Timer">
+                                <color key="titleColor" cocoaTouchSystemColor="lightTextColor"/>
+                                <color key="titleShadowColor" cocoaTouchSystemColor="scrollViewTexturedBackgroundColor"/>
+                            </state>
+                            <connections>
+                                <action selector="sleepTimer:" destination="-1" eventType="touchUpInside" id="3DL-TN-OVO"/>
+                            </connections>
+                        </button>
                     </subviews>
                 </view>
-                <view contentMode="scaleToFill" id="117" userLabel="Controls panel" customClass="VLCFrostedGlasView">
+                <view hidden="YES" contentMode="scaleToFill" id="117" userLabel="Controls panel" customClass="VLCFrostedGlasView">
                     <rect key="frame" x="0.0" y="342" width="320" height="198"/>
                     <autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMinY="YES"/>
                     <subviews>
@@ -330,7 +343,7 @@
                         </button>
                     </subviews>
                 </view>
-                <view contentMode="scaleToFill" id="92" userLabel="Controls panel" customClass="VLCFrostedGlasView">
+                <view hidden="YES" contentMode="scaleToFill" id="92" userLabel="Controls panel" customClass="VLCFrostedGlasView">
                     <rect key="frame" x="0.0" y="478" width="320" height="90"/>
                     <autoresizingMask key="autoresizingMask" flexibleMinX="YES" widthSizable="YES" flexibleMaxX="YES" flexibleMinY="YES"/>
                     <subviews>
@@ -488,7 +501,7 @@
                         </navigationItem>
                     </items>
                 </navigationBar>
-                <view hidden="YES" contentMode="scaleToFill" id="241" userLabel="Controls panel" customClass="VLCFrostedGlasView">
+                <view contentMode="scaleToFill" id="241" userLabel="Controls panel" customClass="VLCFrostedGlasView">
                     <rect key="frame" x="0.0" y="63" width="320" height="46"/>
                     <autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxY="YES"/>
                     <subviews>

BIN
Resources/en.lproj/Localizable.strings


+ 2 - 0
Sources/VLCMovieViewController.h

@@ -40,6 +40,7 @@
 @property (nonatomic, strong) IBOutlet UIButton *chapterButton;
 @property (nonatomic, strong) IBOutlet UIButton *chapterButtonLandscape;
 @property (nonatomic, strong) IBOutlet UIButton *equalizerButton;
+@property (nonatomic, strong) IBOutlet UIButton *sleepTimerButton;
 @property (nonatomic, strong) IBOutlet UINavigationBar *toolbar;
 @property (nonatomic, strong) IBOutlet VLCFrostedGlasView *controllerPanel;
 @property (nonatomic, strong) IBOutlet VLCFrostedGlasView *controllerPanelLandscape;
@@ -112,6 +113,7 @@
 - (IBAction)lock:(id)sender;
 - (IBAction)switchChapter:(id)sender;
 - (IBAction)equalizer:(id)sender;
+- (IBAction)sleepTimer:(id)sender;
 
 - (IBAction)videoFilterToggle:(id)sender;
 - (IBAction)videoFilterSliderAction:(id)sender;

+ 86 - 0
Sources/VLCMovieViewController.m

@@ -64,6 +64,7 @@ typedef NS_ENUM(NSInteger, VLCPanType) {
     NSUInteger _currentAspectRatioMask;
 
     NSTimer *_idleTimer;
+    NSTimer *_sleepTimer;
 
     BOOL _shouldResumePlaying;
     BOOL _viewAppeared;
@@ -87,6 +88,10 @@ typedef NS_ENUM(NSInteger, VLCPanType) {
     UITableView *_trackSelectorTableView;
 
     VLCEqualizerView *_equalizerView;
+
+    UIView *_sleepTimerContainer;
+    UIDatePicker *_sleepTimeDatePicker;
+
     NSInteger _mediaDuration;
 }
 
@@ -236,6 +241,9 @@ typedef NS_ENUM(NSInteger, VLCPanType) {
     _repeatButton.isAccessibilityElement = YES;
     _equalizerButton.accessibilityLabel = NSLocalizedString(@"BUTTON_EQUALIZER", nil);
     _equalizerButton.isAccessibilityElement = YES;
+    _sleepTimerButton.accessibilityLabel = NSLocalizedString(@"BUTTON_SLEEP_TIMER", nil);
+    _sleepTimerButton.isAccessibilityElement = YES;
+    [_sleepTimerButton setTitle:NSLocalizedString(@"BUTTON_SLEEP_TIMER", nil) forState:UIControlStateNormal];
 
     _scrubHelpLabel.text = NSLocalizedString(@"PLAYBACK_SCRUB_HELP", nil);
 
@@ -940,6 +948,10 @@ typedef NS_ENUM(NSInteger, VLCPanType) {
         _trackSelectorContainer.hidden = YES;
         _equalizerView.alpha = 0.0f;
         _equalizerView.hidden = YES;
+        if (_sleepTimerContainer) {
+            _sleepTimerContainer.alpha = 0.0f;
+            _sleepTimerContainer.hidden = YES;
+        }
     }
 
     void (^animationBlock)() = ^() {
@@ -950,6 +962,8 @@ typedef NS_ENUM(NSInteger, VLCPanType) {
         _playbackSpeedView.alpha = alpha;
         _trackSelectorContainer.alpha = alpha;
         _equalizerView.alpha = alpha;
+        if (_sleepTimerContainer)
+            _sleepTimerContainer.alpha = alpha;
     };
 
     void (^completionBlock)(BOOL finished) = ^(BOOL finished) {
@@ -960,6 +974,8 @@ typedef NS_ENUM(NSInteger, VLCPanType) {
         _playbackSpeedView.hidden = _playbackSpeedViewHidden;
         _trackSelectorContainer.hidden = YES;
         _equalizerView.hidden = YES;
+        if (_sleepTimerContainer)
+            _sleepTimerContainer.hidden = YES;
     };
 
     UIStatusBarAnimation animationType = animated? UIStatusBarAnimationFade: UIStatusBarAnimationNone;
@@ -1295,6 +1311,76 @@ typedef NS_ENUM(NSInteger, VLCPanType) {
         _equalizerView.hidden = YES;
 }
 
+- (IBAction)sleepTimer:(id)sender
+{
+    if (!_sleepTimerContainer) {
+        self.playbackSpeedView.hidden = YES;
+        _sleepTimerContainer = [[VLCFrostedGlasView alloc] initWithFrame:CGRectMake(0., 0., 300., 162.)];
+        _sleepTimerContainer.center = self.view.center;
+        _sleepTimerContainer.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleTopMargin;
+
+        _sleepTimeDatePicker = [[UIDatePicker alloc] init];
+        if ([[UIDevice currentDevice] speedCategory] >= 3) {
+            _sleepTimeDatePicker.opaque = NO;
+            _sleepTimeDatePicker.backgroundColor = [UIColor clearColor];
+        } else
+            _sleepTimeDatePicker.backgroundColor = [UIColor blackColor];
+        _sleepTimeDatePicker.tintColor = [UIColor VLCLightTextColor];
+        [_sleepTimerContainer addSubview:_sleepTimeDatePicker];
+
+        /* adapt the date picker style to suit our needs */
+        [_sleepTimeDatePicker setValue:[UIColor whiteColor] forKeyPath:@"textColor"];
+        SEL selector = NSSelectorFromString(@"setHighlightsToday:");
+        NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[UIDatePicker instanceMethodSignatureForSelector:selector]];
+        BOOL no = NO;
+        [invocation setSelector:selector];
+        [invocation setArgument:&no atIndex:2];
+        [invocation invokeWithTarget:_sleepTimeDatePicker];
+
+        if (_sleepTimerContainer.subviews.count > 0) {
+            NSArray *subviewsOfSubview = [_sleepTimeDatePicker.subviews[0] subviews];
+            NSUInteger subviewCount = subviewsOfSubview.count;
+            for (NSUInteger x = 0; x < subviewCount; x++) {
+                if ([subviewsOfSubview[x] isKindOfClass:[UILabel class]])
+                    [subviewsOfSubview[x] setTextColor:[UIColor VLCLightTextColor]];
+            }
+        }
+        _sleepTimeDatePicker.datePickerMode = UIDatePickerModeCountDownTimer;
+        _sleepTimeDatePicker.minuteInterval = 5;
+        _sleepTimeDatePicker.minimumDate = [NSDate date];
+        _sleepTimeDatePicker.countDownDuration = 1200.;
+        [_sleepTimeDatePicker addTarget:self action:@selector(sleepTimerAction:) forControlEvents:UIControlEventValueChanged];
+
+        [self.view addSubview:_sleepTimerContainer];
+    }
+
+    if (!_playbackSpeedViewHidden)
+        self.playbackSpeedView.hidden = _playbackSpeedViewHidden = YES;
+
+    if (_equalizerView.hidden == NO)
+        _equalizerView.hidden = YES;
+
+    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
+        if (!_controlsHidden) {
+            self.controllerPanel.hidden = _controlsHidden = YES;
+            self.controllerPanelLandscape.hidden = YES;
+        }
+    }
+
+    self.videoFilterView.hidden = _videoFiltersHidden = YES;
+    _sleepTimerContainer.alpha = 1.;
+    _sleepTimerContainer.hidden = NO;
+}
+
+- (IBAction)sleepTimerAction:(id)sender
+{
+    if (_sleepTimer) {
+        [_sleepTimer invalidate];
+        _sleepTimer = nil;
+    }
+    _sleepTimer = [NSTimer scheduledTimerWithTimeInterval:_sleepTimeDatePicker.countDownDuration target:self selector:@selector(closePlayback:) userInfo:nil repeats:NO];
+}
+
 #pragma mark - track selector table view
 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
 {