浏览代码

Implement playback rate info TV view controller

Tobias Conradi 9 年之前
父节点
当前提交
fea04eddf7

+ 3 - 2
VLC for Apple TV/Playback/Playback Info/VLCPlaybackInfoSpeedTVViewController.h

@@ -11,6 +11,7 @@
 
 #import "VLCPlaybackInfoPanelTVViewController.h"
 
-@interface VLCPlaybackInfoSpeedTVViewController : VLCPlaybackInfoPanelTVViewController
-@property (nonatomic) IBOutlet UISegmentedControl *speedSegementedControl;
+@interface VLCPlaybackInfoRateTVViewController : VLCPlaybackInfoPanelTVViewController
+@property (nonatomic, weak) IBOutlet UISegmentedControl *segmentedControl;
+- (IBAction)segmentedControlChanged:(UISegmentedControl *)sender;
 @end

+ 81 - 0
VLC for Apple TV/Playback/Playback Info/VLCPlaybackInfoRateTVViewController.m

@@ -0,0 +1,81 @@
+/*****************************************************************************
+ * 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 "VLCPlaybackInfoRateTVViewController.h"
+@interface VLCPlaybackInfoRateTVViewController ()
+@property (nonatomic) NSArray<NSNumber*> *possibleRates;
+@end
+
+@implementation VLCPlaybackInfoRateTVViewController
+
+
+- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
+{
+    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
+    if (self) {
+        self.title = NSLocalizedString(@"PLAYBACK_RATE_INFO_VC_TITLE", nil);
+    }
+    return self;
+}
+- (CGSize)preferredContentSize
+{
+    return CGSizeMake(CGRectGetWidth(self.view.bounds), 100);
+}
+
+- (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 *segmentedControl = self.segmentedControl;
+    [segmentedControl removeAllSegments];
+
+    [self.possibleRates enumerateObjectsUsingBlock:^(NSNumber * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
+        NSString *title = [formatter stringFromNumber:obj];
+        [segmentedControl insertSegmentWithTitle:title atIndex:idx animated:NO];
+    }];
+}
+
+- (void)viewWillAppear:(BOOL)animated
+{
+    [super viewWillAppear:animated];
+    [self updateSegmentedControl];
+}
+
+- (void)updateSegmentedControl
+{
+    float currentRate = [VLCPlaybackController sharedInstance].playbackRate;
+
+    NSInteger currentIndex = [self.possibleRates indexOfObjectPassingTest:^BOOL(NSNumber * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
+        return ABS(obj.floatValue-currentRate)<0.2;
+    }];
+    self.segmentedControl.selectedSegmentIndex = currentIndex;
+}
+
+- (IBAction)segmentedControlChanged:(UISegmentedControl *)sender
+{
+    float newRate = self.possibleRates[sender.selectedSegmentIndex].floatValue;
+    [VLCPlaybackController sharedInstance].playbackRate = newRate;
+}
+@end

+ 0 - 32
VLC for Apple TV/Playback/Playback Info/VLCPlaybackInfoSpeedTVViewController.m

@@ -1,32 +0,0 @@
-/*****************************************************************************
- * 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 "VLCPlaybackInfoSpeedTVViewController.h"
-
-@interface VLCPlaybackInfoSpeedTVViewController ()
-
-@end
-
-@implementation VLCPlaybackInfoSpeedTVViewController
-- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
-{
-    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
-    if (self) {
-        self.title = NSLocalizedString(@"PLAYBACK_SPEED_INFO_VC_TITLE", nil);
-    }
-    return self;
-}
-
-- (CGSize)preferredContentSize
-{
-    return CGSizeMake(CGRectGetWidth(self.view.bounds), 100);
-}
-@end

+ 2 - 2
VLC for Apple TV/Playback/Playback Info/VLCPlaybackInfoTVViewController.m

@@ -10,7 +10,7 @@
  *****************************************************************************/
 
 #import "VLCPlaybackInfoTVViewController.h"
-#import "VLCPlaybackInfoSpeedTVViewController.h"
+#import "VLCPlaybackInfoRateTVViewController.h"
 #import "VLCPlaybackInfoAudioTVViewController.h"
 #import "VLCPlaybackInfoTVAnimators.h"
 
@@ -25,7 +25,7 @@
 - (NSArray<UIViewController*>*)tabViewControllers
 {
     return @[
-             [[VLCPlaybackInfoSpeedTVViewController alloc] initWithNibName:nil bundle:nil],
+             [[VLCPlaybackInfoRateTVViewController alloc] initWithNibName:nil bundle:nil],
              [[VLCPlaybackInfoAudioTVViewController alloc] initWithNibName:nil bundle:nil],
              ];
 }

+ 6 - 1
VLC for Apple TV/VLCPlaybackInfoSpeedTVViewController.xib

@@ -4,8 +4,10 @@
         <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9049"/>
     </dependencies>
     <objects>
-        <placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="VLCPlaybackInfoSpeedTVViewController">
+        <placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="VLCPlaybackInfoRateTVViewController">
             <connections>
+                <outlet property="preferredFocusedView" destination="a34-9y-ZcI" id="Xa7-Zq-uyz"/>
+                <outlet property="segmentedControl" destination="a34-9y-ZcI" id="ob8-jh-Cvo"/>
                 <outlet property="view" destination="vgW-9U-IlZ" id="527-h1-jOO"/>
             </connections>
         </placeholder>
@@ -22,6 +24,9 @@
                         <segment title="First"/>
                         <segment title="Second"/>
                     </segments>
+                    <connections>
+                        <action selector="segmentedControlChanged:" destination="-1" eventType="valueChanged" id="rh8-Qo-MRd"/>
+                    </connections>
                 </segmentedControl>
             </subviews>
             <animations/>

+ 10 - 10
VLC for iOS.xcodeproj/project.pbxproj

@@ -325,8 +325,8 @@
 		DD8095DB1BE3C42F0065D8E1 /* VLCBufferingBar.m in Sources */ = {isa = PBXBuildFile; fileRef = DD8095DA1BE3C42F0065D8E1 /* VLCBufferingBar.m */; };
 		DD8095E01BE3EFC20065D8E1 /* VLCPlaybackInfoTVViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = DD8095DE1BE3EFC20065D8E1 /* VLCPlaybackInfoTVViewController.m */; };
 		DD8095E51BE3F4240065D8E1 /* VLCPlaybackInfoTVViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = DD8095E41BE3F4240065D8E1 /* VLCPlaybackInfoTVViewController.xib */; };
-		DD8095EB1BE4F04E0065D8E1 /* VLCPlaybackInfoSpeedTVViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = DD8095E91BE4F04E0065D8E1 /* VLCPlaybackInfoSpeedTVViewController.m */; };
-		DD8095EC1BE4F04E0065D8E1 /* VLCPlaybackInfoSpeedTVViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = DD8095EA1BE4F04E0065D8E1 /* VLCPlaybackInfoSpeedTVViewController.xib */; };
+		DD8095EB1BE4F04E0065D8E1 /* VLCPlaybackInfoRateTVViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = DD8095E91BE4F04E0065D8E1 /* VLCPlaybackInfoRateTVViewController.m */; };
+		DD8095EC1BE4F04E0065D8E1 /* VLCPlaybackInfoRateTVViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = DD8095EA1BE4F04E0065D8E1 /* VLCPlaybackInfoRateTVViewController.xib */; };
 		DD8095F21BE510770065D8E1 /* VLCPlaybackInfoAudioTVViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = DD8095F01BE510770065D8E1 /* VLCPlaybackInfoAudioTVViewController.m */; };
 		DD8095F31BE510770065D8E1 /* VLCPlaybackInfoAudioTVViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = DD8095F11BE510770065D8E1 /* VLCPlaybackInfoAudioTVViewController.xib */; };
 		DD8095F61BE624C00065D8E1 /* VLCPlaybackInfoTVAnimators.m in Sources */ = {isa = PBXBuildFile; fileRef = DD8095F51BE624C00065D8E1 /* VLCPlaybackInfoTVAnimators.m */; };
@@ -993,9 +993,9 @@
 		DD8095DD1BE3EFC20065D8E1 /* VLCPlaybackInfoTVViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VLCPlaybackInfoTVViewController.h; sourceTree = "<group>"; };
 		DD8095DE1BE3EFC20065D8E1 /* VLCPlaybackInfoTVViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VLCPlaybackInfoTVViewController.m; sourceTree = "<group>"; };
 		DD8095E41BE3F4240065D8E1 /* VLCPlaybackInfoTVViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = VLCPlaybackInfoTVViewController.xib; sourceTree = "<group>"; };
-		DD8095E81BE4F04E0065D8E1 /* VLCPlaybackInfoSpeedTVViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VLCPlaybackInfoSpeedTVViewController.h; sourceTree = "<group>"; };
-		DD8095E91BE4F04E0065D8E1 /* VLCPlaybackInfoSpeedTVViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VLCPlaybackInfoSpeedTVViewController.m; sourceTree = "<group>"; };
-		DD8095EA1BE4F04E0065D8E1 /* VLCPlaybackInfoSpeedTVViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = VLCPlaybackInfoSpeedTVViewController.xib; sourceTree = "<group>"; };
+		DD8095E81BE4F04E0065D8E1 /* VLCPlaybackInfoRateTVViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VLCPlaybackInfoRateTVViewController.h; sourceTree = "<group>"; };
+		DD8095E91BE4F04E0065D8E1 /* VLCPlaybackInfoRateTVViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VLCPlaybackInfoRateTVViewController.m; sourceTree = "<group>"; };
+		DD8095EA1BE4F04E0065D8E1 /* VLCPlaybackInfoRateTVViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = VLCPlaybackInfoRateTVViewController.xib; sourceTree = "<group>"; };
 		DD8095EF1BE510770065D8E1 /* VLCPlaybackInfoAudioTVViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VLCPlaybackInfoAudioTVViewController.h; sourceTree = "<group>"; };
 		DD8095F01BE510770065D8E1 /* VLCPlaybackInfoAudioTVViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VLCPlaybackInfoAudioTVViewController.m; sourceTree = "<group>"; };
 		DD8095F11BE510770065D8E1 /* VLCPlaybackInfoAudioTVViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = VLCPlaybackInfoAudioTVViewController.xib; sourceTree = "<group>"; };
@@ -1799,7 +1799,7 @@
 				7DEC8BDD1BD67899006E1093 /* VLCFullscreenMovieTVViewController.xib */,
 				DD8095E41BE3F4240065D8E1 /* VLCPlaybackInfoTVViewController.xib */,
 				DD8095F11BE510770065D8E1 /* VLCPlaybackInfoAudioTVViewController.xib */,
-				DD8095EA1BE4F04E0065D8E1 /* VLCPlaybackInfoSpeedTVViewController.xib */,
+				DD8095EA1BE4F04E0065D8E1 /* VLCPlaybackInfoRateTVViewController.xib */,
 				7D7EF3D91BD56B5900CD4CEE /* VLCOpenNetworkStreamTVViewController.xib */,
 				DDEAECF51BDFEAFA00756C83 /* VLCLocalNetworkServerTVCell.xib */,
 			);
@@ -2235,8 +2235,8 @@
 				DD8095F51BE624C00065D8E1 /* VLCPlaybackInfoTVAnimators.m */,
 				DD8095F71BE6268A0065D8E1 /* VLCPlaybackInfoPanelTVViewController.h */,
 				DD8095F81BE6268A0065D8E1 /* VLCPlaybackInfoPanelTVViewController.m */,
-				DD8095E81BE4F04E0065D8E1 /* VLCPlaybackInfoSpeedTVViewController.h */,
-				DD8095E91BE4F04E0065D8E1 /* VLCPlaybackInfoSpeedTVViewController.m */,
+				DD8095E81BE4F04E0065D8E1 /* VLCPlaybackInfoRateTVViewController.h */,
+				DD8095E91BE4F04E0065D8E1 /* VLCPlaybackInfoRateTVViewController.m */,
 				DD8095EF1BE510770065D8E1 /* VLCPlaybackInfoAudioTVViewController.h */,
 				DD8095F01BE510770065D8E1 /* VLCPlaybackInfoAudioTVViewController.m */,
 			);
@@ -2512,7 +2512,7 @@
 				7DEC8C1E1BD69710006E1093 /* About Contents.html in Resources */,
 				DDEAECF61BDFEAFA00756C83 /* VLCLocalNetworkServerTVCell.xib in Resources */,
 				7D13294F1BA1F10100BE647E /* Assets.xcassets in Resources */,
-				DD8095EC1BE4F04E0065D8E1 /* VLCPlaybackInfoSpeedTVViewController.xib in Resources */,
+				DD8095EC1BE4F04E0065D8E1 /* VLCPlaybackInfoRateTVViewController.xib in Resources */,
 				7DEC8BE91BD68BC9006E1093 /* Settings.bundle in Resources */,
 				DD3EAC131BE26166003668DA /* VLCServerBrowsingTVCell.xib in Resources */,
 				7D3E528C1BD7B5E100309D15 /* VLCCloudServicesTVViewController.xib in Resources */,
@@ -2747,7 +2747,7 @@
 				7DEC8BD91BD670EB006E1093 /* VLCPlaybackNavigationController.m in Sources */,
 				7DEC8BDA1BD67112006E1093 /* VLCFrostedGlasView.m in Sources */,
 				DD8095F21BE510770065D8E1 /* VLCPlaybackInfoAudioTVViewController.m in Sources */,
-				DD8095EB1BE4F04E0065D8E1 /* VLCPlaybackInfoSpeedTVViewController.m in Sources */,
+				DD8095EB1BE4F04E0065D8E1 /* VLCPlaybackInfoRateTVViewController.m in Sources */,
 				DD3EAC051BE153B4003668DA /* VLCNetworkImageView.m in Sources */,
 				7D0C35341BD97C7B0058CD19 /* VLCOneDriveObject.m in Sources */,
 				7D0C35331BD97C100058CD19 /* VLCOneDriveController.m in Sources */,