Sfoglia il codice sorgente

Add basic Remote Playback UI

Felix Paul Kühne 9 anni fa
parent
commit
793139136c

BIN
Resources/en.lproj/Localizable.strings


+ 4 - 0
VLC for Apple TV/AppleTVAppDelegate.m

@@ -14,6 +14,7 @@
 #import "VLCOpenNetworkStreamTVViewController.h"
 #import "VLCSettingsTableViewController.h"
 #import "VLCCloudServicesTVViewController.h"
+#import "VLCHTTPUploaderController.h"
 
 @interface AppleTVAppDelegate ()
 {
@@ -69,6 +70,9 @@
 
     self.window.rootViewController = _mainViewController;
 
+    // Init the HTTP Server and clean its cache
+    [[VLCHTTPUploaderController sharedInstance] cleanCache];
+
     [self.window makeKeyAndVisible];
     return YES;
 }

+ 3 - 1
VLC for Apple TV/VLCOpenNetworkStreamTVViewController.h

@@ -13,10 +13,12 @@
 
 @interface VLCOpenNetworkStreamTVViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>
 
-@property (readwrite, nonatomic, weak) IBOutlet UILabel *titleLabel;
 @property (readwrite, nonatomic, weak) IBOutlet UITextField *playURLField;
 @property (readwrite, nonatomic, weak) IBOutlet UITableView *previouslyPlayedStreamsTableView;
+@property (readwrite, nonatomic, weak) IBOutlet UIButton *toggleHTTPServerButton;
+@property (readwrite, nonatomic, weak) IBOutlet UILabel *httpServerLabel;
 
 - (IBAction)URLEnteredInField:(id)sender;
+- (IBAction)toggleHTTPServer:(id)sender;
 
 @end

+ 45 - 0
VLC for Apple TV/VLCOpenNetworkStreamTVViewController.m

@@ -13,11 +13,14 @@
 #import "VLCPlaybackController.h"
 #import "VLCPlayerDisplayController.h"
 #import "VLCFullscreenMovieTVViewController.h"
+#import "Reachability.h"
+#import "VLCHTTPUploaderController.h"
 
 @interface VLCOpenNetworkStreamTVViewController ()
 {
     NSMutableArray *_recentURLs;
     UILabel *_noURLsToShowLabel;
+    Reachability *_reachability;
 }
 @end
 
@@ -31,6 +34,9 @@
 - (void)viewDidLoad {
     [super viewDidLoad];
 
+    _reachability = [Reachability reachabilityForLocalWiFi];
+    self.httpServerLabel.textColor = [UIColor VLCDarkBackgroundColor];
+
     _noURLsToShowLabel = [[UILabel alloc] init];
     _noURLsToShowLabel.text = NSLocalizedString(@"NO_RECENT_STREAMS", nil);
     _noURLsToShowLabel.textAlignment = NSTextAlignmentCenter;
@@ -62,6 +68,10 @@
                            selector:@selector(ubiquitousKeyValueStoreDidChange:)
                                name:NSUbiquitousKeyValueStoreDidChangeExternallyNotification
                              object:[NSUbiquitousKeyValueStore defaultStore]];
+    [notificationCenter addObserver:self
+                           selector:@selector(reachabilityChanged)
+                               name:kReachabilityChangedNotification
+                             object:nil];
 
     /* force store update */
     NSUbiquitousKeyValueStore *ubiquitousKeyValueStore = [NSUbiquitousKeyValueStore defaultStore];
@@ -88,10 +98,45 @@
     _noURLsToShowLabel.hidden = _recentURLs.count != 0;
 }
 
+- (void)reachabilityChanged
+{
+    [self updateHTTPServerAddress];
+}
+
+- (void)updateHTTPServerAddress
+{
+    BOOL connectedViaWifi = _reachability.currentReachabilityStatus == ReachableViaWiFi;
+    self.toggleHTTPServerButton.enabled = connectedViaWifi;
+    NSString *uploadText = connectedViaWifi ? [[VLCHTTPUploaderController sharedInstance] httpStatus] : NSLocalizedString(@"HTTP_UPLOAD_NO_CONNECTIVITY", nil);
+    self.httpServerLabel.text = uploadText;
+    if (connectedViaWifi && [VLCHTTPUploaderController sharedInstance].isServerRunning)
+        [self.toggleHTTPServerButton setTitle:NSLocalizedString(@"HTTP_SERVER_ON", nil) forState:UIControlStateNormal];
+    else
+        [self.toggleHTTPServerButton setTitle:NSLocalizedString(@"HTTP_SERVER_OFF", nil) forState:UIControlStateNormal];
+}
+
+- (void)toggleHTTPServer:(id)sender
+{
+    BOOL futureHTTPServerState = ![VLCHTTPUploaderController sharedInstance].isServerRunning ;
+    [[NSUserDefaults standardUserDefaults] setBool:futureHTTPServerState forKey:kVLCSettingSaveHTTPUploadServerStatus];
+    [[VLCHTTPUploaderController sharedInstance] changeHTTPServerState:futureHTTPServerState];
+    [self updateHTTPServerAddress];
+    [[NSUserDefaults standardUserDefaults] synchronize];
+}
+
+- (void)viewWillAppear:(BOOL)animated
+{
+    [super viewWillAppear:animated];
+    [_reachability startNotifier];
+    [self updateHTTPServerAddress];
+}
+
 - (void)viewWillDisappear:(BOOL)animated
 {
     [super viewWillDisappear:animated];
 
+    [_reachability stopNotifier];
+
     /* force update before we leave */
     [[NSUbiquitousKeyValueStore defaultStore] synchronize];
 }

+ 26 - 3
VLC for Apple TV/VLCOpenNetworkStreamTVViewController.xib

@@ -6,9 +6,11 @@
     <objects>
         <placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="VLCOpenNetworkStreamTVViewController">
             <connections>
+                <outlet property="httpServerLabel" destination="Nb1-SP-5iY" id="jwT-VV-Uf9"/>
                 <outlet property="playURLField" destination="dWa-3n-YCa" id="Eoe-vT-AuM"/>
                 <outlet property="preferredFocusedView" destination="dWa-3n-YCa" id="0Ez-4Z-KFF"/>
                 <outlet property="previouslyPlayedStreamsTableView" destination="v0o-s0-Xaz" id="I1r-ie-lFf"/>
+                <outlet property="toggleHTTPServerButton" destination="zWl-AV-9Ga" id="WC7-Uc-lxA"/>
                 <outlet property="view" destination="iN0-l3-epB" id="Eym-vH-oyN"/>
             </connections>
         </placeholder>
@@ -18,7 +20,7 @@
             <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
             <subviews>
                 <textField opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" placeholder="Enter URL to play" textAlignment="center" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="dWa-3n-YCa">
-                    <rect key="frame" x="710" y="174" width="500" height="66"/>
+                    <rect key="frame" x="710" y="524" width="500" height="66"/>
                     <constraints>
                         <constraint firstAttribute="width" constant="500" id="3fz-h4-cGU"/>
                         <constraint firstAttribute="height" constant="66" id="hDw-hW-ont"/>
@@ -30,22 +32,43 @@
                     </connections>
                 </textField>
                 <tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" style="plain" separatorStyle="default" rowHeight="66" sectionHeaderHeight="40" sectionFooterHeight="40" translatesAutoresizingMaskIntoConstraints="NO" id="v0o-s0-Xaz">
-                    <rect key="frame" x="183" y="310" width="1555" height="700"/>
+                    <rect key="frame" x="183" y="660" width="1555" height="350"/>
                     <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
                     <constraints>
                         <constraint firstAttribute="width" constant="1555" id="ELC-Ea-jpC"/>
-                        <constraint firstAttribute="height" constant="700" id="gQs-hK-0At"/>
+                        <constraint firstAttribute="height" constant="350" id="gQs-hK-0At"/>
                     </constraints>
                     <connections>
                         <outlet property="dataSource" destination="-1" id="5xO-BE-h5Q"/>
                         <outlet property="delegate" destination="-1" id="osW-Kv-1VK"/>
                     </connections>
                 </tableView>
+                <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="3" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Nb1-SP-5iY">
+                    <rect key="frame" x="533" y="302" width="855" height="113"/>
+                    <string key="text">Open either of these URLs in a web browser on your network:
+http://bonjour.local
+http://192.168.1.1</string>
+                    <fontDescription key="fontDescription" style="UICTFontTextStyleCallout"/>
+                    <color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
+                    <nil key="highlightedColor"/>
+                </label>
+                <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="zWl-AV-9Ga">
+                    <rect key="frame" x="710" y="180" width="501" height="86"/>
+                    <inset key="contentEdgeInsets" minX="40" minY="20" maxX="40" maxY="20"/>
+                    <state key="normal" title="Enable Remote Playback"/>
+                    <connections>
+                        <action selector="toggleHTTPServer:" destination="-1" eventType="primaryActionTriggered" id="vhQ-WP-o1L"/>
+                    </connections>
+                </button>
             </subviews>
             <constraints>
+                <constraint firstItem="dWa-3n-YCa" firstAttribute="top" secondItem="zWl-AV-9Ga" secondAttribute="bottom" constant="258" id="0dj-Io-wvg"/>
                 <constraint firstItem="v0o-s0-Xaz" firstAttribute="centerX" secondItem="iN0-l3-epB" secondAttribute="centerX" id="elq-bO-Tb3"/>
+                <constraint firstItem="zWl-AV-9Ga" firstAttribute="centerX" secondItem="iN0-l3-epB" secondAttribute="centerX" id="jB3-Df-sFO"/>
                 <constraint firstItem="v0o-s0-Xaz" firstAttribute="top" secondItem="dWa-3n-YCa" secondAttribute="bottom" constant="70" id="jCe-Gz-82c"/>
+                <constraint firstItem="Nb1-SP-5iY" firstAttribute="top" secondItem="zWl-AV-9Ga" secondAttribute="bottom" constant="36" id="jDR-XJ-Feh"/>
                 <constraint firstItem="dWa-3n-YCa" firstAttribute="centerX" secondItem="iN0-l3-epB" secondAttribute="centerX" id="oFS-xp-QJo"/>
+                <constraint firstItem="Nb1-SP-5iY" firstAttribute="centerX" secondItem="iN0-l3-epB" secondAttribute="centerX" id="rag-MH-SLa"/>
                 <constraint firstAttribute="bottom" secondItem="v0o-s0-Xaz" secondAttribute="bottom" constant="70" id="ydf-eT-5UK"/>
             </constraints>
         </view>

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

@@ -1695,12 +1695,12 @@
 				DDDEA6AE1BE027FA000BB7A2 /* VLCServerBrowsingTVTableViewController.m */,
 				7DC71D231BC830A5001FACAA /* VLCLocalNetworkTVViewController.h */,
 				7DC71D241BC830A5001FACAA /* VLCLocalNetworkTVViewController.m */,
-				7D7EF3D71BD56B5900CD4CEE /* VLCOpenNetworkStreamTVViewController.h */,
-				7D7EF3D81BD56B5900CD4CEE /* VLCOpenNetworkStreamTVViewController.m */,
 				DDEAECF21BDFEAE300756C83 /* VLCLocalNetworkServerTVCell.h */,
 				DDEAECF31BDFEAE300756C83 /* VLCLocalNetworkServerTVCell.m */,
 				DD3EABE71BE13D5B003668DA /* VLCServerBrowsingTVCell.h */,
 				DD3EABE81BE13D5B003668DA /* VLCServerBrowsingTVCell.m */,
+				7D7EF3D71BD56B5900CD4CEE /* VLCOpenNetworkStreamTVViewController.h */,
+				7D7EF3D81BD56B5900CD4CEE /* VLCOpenNetworkStreamTVViewController.m */,
 			);
 			name = "Network UI";
 			sourceTree = "<group>";