VLCPlaybackInfoPlaybackTVViewController.m 4.47 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/*****************************************************************************
 * VLC for iOS
 *****************************************************************************
 * Copyright (c) 2015 VideoLAN. All rights reserved.
 * $Id$
 *
 * Authors: Tobias Conradi <videolan # tobias-conradi.de>
 *
 * Refer to the COPYING file of the official project for license.
 *****************************************************************************/

#import "VLCPlaybackInfoPlaybackTVViewController.h"
@interface VLCPlaybackInfoPlaybackTVViewController ()
@property (nonatomic) NSArray<NSNumber*> *possibleRates;
@end

@implementation VLCPlaybackInfoPlaybackTVViewController


- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.title = NSLocalizedString(@"PLAYBACK", nil);
    }
    return self;
}

- (CGSize)preferredContentSize
{
    return CGSizeMake(CGRectGetWidth(self.view.bounds), 200);
}

+ (BOOL)shouldBeVisibleForPlaybackController:(VLCPlaybackController *)vpc
{
36
    return [vpc isSeekable];
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
}


- (void)viewDidLoad
{
    [super viewDidLoad];
    self.possibleRates = @[@(0.25),
                           @(0.50),
                           @(0.75),
                           @(1.00),
                           @(1.25),
                           @(1.50),
                           @(2.00),
                           @(4.00),
                           ];

    NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
    formatter.numberStyle = NSNumberFormatterDecimalStyle;
    formatter.maximumFractionDigits = 2;
    formatter.minimumFractionDigits = 2;

    UISegmentedControl *rateControl = self.rateControl;
    [rateControl removeAllSegments];

    [self.possibleRates enumerateObjectsUsingBlock:^(NSNumber * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        NSString *title = [formatter stringFromNumber:obj];
        [rateControl insertSegmentWithTitle:title atIndex:idx animated:NO];
    }];

    self.rateLabel.text = NSLocalizedString(@"PLAYBACK_SPEED", nil);

    UISegmentedControl *repeatControl = self.repeatControl;
    [repeatControl removeAllSegments];
    [repeatControl insertSegmentWithTitle:NSLocalizedString(@"REPEAT_DISABLED", nil)
                                  atIndex:0 animated:NO];
    [repeatControl insertSegmentWithTitle:NSLocalizedString(@"REPEAT_SINGLE", nil)
                                  atIndex:1 animated:NO];
    [repeatControl insertSegmentWithTitle:NSLocalizedString(@"REPEAT_FOLDER", nil)
                                  atIndex:2 animated:NO];

    self.repeatLabel.text = NSLocalizedString(@"REPEAT_MODE", nil);
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self updateRateControl];
    [self updateRepeatControl];
}

- (void)updateRateControl
{
    VLCPlaybackController *vpc = [VLCPlaybackController sharedInstance];
    float currentRate = vpc.playbackRate;

    NSInteger currentIndex = [self.possibleRates indexOfObjectPassingTest:^BOOL(NSNumber * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        return ABS(obj.floatValue-currentRate)<0.2;
    }];
    UISegmentedControl *rateControl = self.rateControl;
    rateControl.selectedSegmentIndex = currentIndex;
97
    rateControl.enabled = [vpc isSeekable];
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
}

- (IBAction)rateControlChanged:(UISegmentedControl *)sender
{
    float newRate = self.possibleRates[sender.selectedSegmentIndex].floatValue;
    [VLCPlaybackController sharedInstance].playbackRate = newRate;
}

- (void)updateRepeatControl
{
    NSUInteger selectedIndex;
    VLCRepeatMode repeatMode = [VLCPlaybackController sharedInstance].repeatMode;
    switch (repeatMode) {
        case VLCRepeatCurrentItem:
            selectedIndex = 1;
            break;
        case VLCRepeatAllItems:
            selectedIndex = 2;
            break;
        case VLCDoNotRepeat:
        default:
            selectedIndex = 0;
            break;
    }

    self.repeatControl.selectedSegmentIndex = selectedIndex;
}

-(IBAction)repeatControlChanged:(UISegmentedControl *)sender
{
    VLCRepeatMode repeatMode;
    switch (sender.selectedSegmentIndex) {
        case 1:
            repeatMode = VLCRepeatCurrentItem;
            break;
        case 2:
            repeatMode = VLCRepeatAllItems;
            break;
        case 0:
        default:
            repeatMode = VLCDoNotRepeat;
            break;
    }

    [VLCPlaybackController sharedInstance].repeatMode = repeatMode;
}

@end