Commit c128d88d authored by Shenghan Chen's avatar Shenghan Chen Committed by Felix Paul Kühne

SleepTimer: Add sleep timer countdown (Closes #14154)

Signed-off-by: Felix Paul Kühne's avatarFelix Paul Kühne <fkuehne@videolan.org>
parent 9fabea7a
......@@ -90,6 +90,7 @@ typedef NS_ENUM(NSInteger, VLCPanType) {
UIView *_sleepTimerContainer;
UIDatePicker *_sleepTimeDatePicker;
NSTimer *_sleepCountDownTimer;
NSInteger _mediaDuration;
}
......@@ -806,6 +807,23 @@ typedef NS_ENUM(NSInteger, VLCPanType) {
[self.timeNavigationTitleView setNeedsLayout];
}
- (void)updateSleepTimerButton
{
NSMutableString *title = [NSMutableString stringWithString:NSLocalizedString(@"BUTTON_SLEEP_TIMER", nil)];
VLCPlaybackController *vpc = [VLCPlaybackController sharedInstance];
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
- (VLCPlaybackController *)playbackController
......@@ -1008,6 +1026,14 @@ currentMediaHasTrackToChooseFrom:(BOOL)currentMediaHasTrackToChooseFrom
{
VLCPlaybackController *vpc = [VLCPlaybackController sharedInstance];
[vpc scheduleSleepTimerWithInterval:_sleepTimeDatePicker.countDownDuration];
if (_sleepCountDownTimer == nil || _sleepCountDownTimer.valid == NO) {
_sleepCountDownTimer = [NSTimer scheduledTimerWithTimeInterval:1
target:self
selector:@selector(updateSleepTimerButton)
userInfo:nil
repeats:YES];
}
}
- (void)moreActions:(id)sender
......
......@@ -76,6 +76,7 @@ currentMediaHasTrackToChooseFrom:(BOOL)currentMediaHasTrackToChooseFrom
@property (nonatomic, readonly) BOOL audioOnlyPlaybackSession;
@property (nonatomic, readwrite) BOOL fullscreenSessionRequested;
@property (nonatomic, readonly) NSDictionary *mediaOptionsDictionary;
@property (nonatomic, readonly) NSTimer* sleepTimer;
+ (VLCPlaybackController *)sharedInstance;
......
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