Bläddra i källkod

remote playback: list cached media as long as its there

Felix Paul Kühne 9 år sedan
förälder
incheckning
59ad38c7b2

+ 2 - 2
Apple-TV/AppleTVAppDelegate.m

@@ -74,8 +74,8 @@
 
     self.window.rootViewController = _mainViewController;
 
-    // Init the HTTP Server and clean its cache
-    [[VLCHTTPUploaderController sharedInstance] cleanCache];
+    // Init the HTTP Server
+    [VLCHTTPUploaderController sharedInstance];
 
     [self.window makeKeyAndVisible];
     return YES;

+ 0 - 6
Apple-TV/Playback/VLCFullscreenMovieTVViewController.m

@@ -155,12 +155,6 @@ typedef NS_ENUM(NSInteger, VLCPlayerScanState)
     [self stopAudioDescriptionAnimation];
 
     [super viewWillDisappear:animated];
-
-    /* clean caches in case remote playback was used
-     * note that if we cancel before the upload is complete
-     * the cache won't be emptied, but on the next launch only (or if the system is under storage pressure)
-     */
-    [[VLCHTTPUploaderController sharedInstance] cleanCache];
 }
 
 - (BOOL)canBecomeFirstResponder

+ 3 - 1
Apple-TV/VLCRemotePlaybackViewController.h

@@ -13,8 +13,10 @@
 
 @interface VLCRemotePlaybackViewController : UIViewController
 
-@property (readwrite, nonatomic, weak) IBOutlet UIButton *toggleHTTPServerButton;
 @property (readwrite, nonatomic, weak) IBOutlet UILabel *httpServerLabel;
+@property (readwrite, nonatomic, weak) IBOutlet UIButton *toggleHTTPServerButton;
+
+@property (readwrite, nonatomic, weak) IBOutlet UILabel *cachedMediaLabel;
 @property (readwrite, nonatomic, weak) IBOutlet UITableView *cachedMediaTableView;
 
 - (IBAction)toggleHTTPServer:(id)sender;

+ 101 - 1
Apple-TV/VLCRemotePlaybackViewController.m

@@ -12,10 +12,14 @@
 #import "VLCRemotePlaybackViewController.h"
 #import "Reachability.h"
 #import "VLCHTTPUploaderController.h"
+#import "VLCMediaFileDiscoverer.h"
 
-@interface VLCRemotePlaybackViewController () <UITableViewDataSource, UITableViewDelegate>
+#define remotePlaybackReuseIdentifer @"remotePlaybackReuseIdentifer"
+
+@interface VLCRemotePlaybackViewController () <UITableViewDataSource, UITableViewDelegate, VLCMediaFileDiscovererDelegate>
 {
     Reachability *_reachability;
+    NSMutableArray *_discoveredFiles;
 }
 @end
 
@@ -38,11 +42,23 @@
                            selector:@selector(reachabilityChanged)
                                name:kReachabilityChangedNotification
                              object:nil];
+
+    VLCMediaFileDiscoverer *discoverer = [VLCMediaFileDiscoverer sharedInstance];
+
+    _discoveredFiles = [NSMutableArray array];
+
+    NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
+    discoverer.directoryPath = [[searchPaths firstObject] stringByAppendingPathComponent:@"Upload"];
+    [discoverer addObserver:self];
+    [discoverer startDiscovering];
 }
 
 - (void)viewWillAppear:(BOOL)animated
 {
     [super viewWillAppear:animated];
+
+    [[VLCMediaFileDiscoverer sharedInstance] updateMediaList];
+
     [_reachability startNotifier];
     [self updateHTTPServerAddress];
 }
@@ -80,5 +96,89 @@
     [[NSUserDefaults standardUserDefaults] synchronize];
 }
 
+#pragma mark - table view data source
+
+- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
+{
+    return 1;
+}
+
+- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
+{
+    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:remotePlaybackReuseIdentifer];
+    if (!cell) {
+        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:remotePlaybackReuseIdentifer];
+    }
+
+    NSString *cellTitle;
+    NSUInteger row = indexPath.row;
+    @synchronized(_discoveredFiles) {
+        if (_discoveredFiles.count > row) {
+            cellTitle = [_discoveredFiles[row] lastPathComponent];
+        }
+    }
+
+    cell.textLabel.text = cellTitle;
+    cell.imageView.image = [UIImage imageNamed:@"blank"];
+    return cell;
+}
+
+- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
+{
+    NSUInteger ret;
+
+    @synchronized(_discoveredFiles) {
+        ret = _discoveredFiles.count;
+    }
+
+    return ret;
+}
+
+#pragma mark - table view delegate
+
+- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
+{
+    [tableView deselectRowAtIndexPath:indexPath animated:NO];
+
+    VLCPlaybackController *vpc = [VLCPlaybackController sharedInstance];
+    NSURL *url;
+    @synchronized(_discoveredFiles) {
+        url = [NSURL fileURLWithPath:_discoveredFiles[indexPath.row]];
+    }
+    [vpc playURL:url subtitlesFilePath:nil];
+    [self presentViewController:[VLCFullscreenMovieTVViewController fullscreenMovieTVViewController]
+                       animated:YES
+                     completion:nil];
+}
+
+#pragma mark - media file discovery
+- (void)mediaFilesFoundRequiringAdditionToStorageBackend:(NSArray<NSString *> *)foundFiles
+{
+    NSLog(@"Found files %@", foundFiles);
+
+    @synchronized(_discoveredFiles) {
+        _discoveredFiles = [NSMutableArray arrayWithArray:foundFiles];
+    }
+    [self.cachedMediaTableView reloadData];
+}
+
+- (void)mediaFileAdded:(NSString *)filePath loading:(BOOL)isLoading
+{
+    @synchronized(_discoveredFiles) {
+        if ([_discoveredFiles indexOfObjectIdenticalTo:filePath] == NSNotFound) {
+            [_discoveredFiles addObject:filePath];
+        }
+    }
+    [self.cachedMediaTableView reloadData];
+}
+
+- (void)mediaFileDeleted:(NSString *)filePath
+{
+    NSLog(@"removed file %@", filePath);
+    @synchronized(_discoveredFiles) {
+        [_discoveredFiles removeObjectIdenticalTo:filePath];
+    }
+    [self.cachedMediaTableView reloadData];
+}
 
 @end

+ 26 - 0
Apple-TV/VLCRemotePlaybackViewController.xib

@@ -6,6 +6,8 @@
     <objects>
         <placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="VLCRemotePlaybackViewController">
             <connections>
+                <outlet property="cachedMediaLabel" destination="77q-qM-GSv" id="gs2-sW-Z17"/>
+                <outlet property="cachedMediaTableView" destination="WfO-PV-wWU" id="eAC-TD-XyD"/>
                 <outlet property="httpServerLabel" destination="mOM-K1-6hX" id="PvM-0r-xq1"/>
                 <outlet property="toggleHTTPServerButton" destination="N4Q-4c-bh0" id="5Je-Lj-ba0"/>
                 <outlet property="view" destination="iN0-l3-epB" id="Eym-vH-oyN"/>
@@ -35,13 +37,37 @@ http://192.168.1.1</string>
                         <action selector="toggleHTTPServer:" destination="-1" eventType="primaryActionTriggered" id="65K-IM-LdJ"/>
                     </connections>
                 </button>
+                <tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" style="plain" separatorStyle="default" rowHeight="66" sectionHeaderHeight="40" sectionFooterHeight="40" translatesAutoresizingMaskIntoConstraints="NO" id="WfO-PV-wWU">
+                    <rect key="frame" x="183" y="660" width="1555" height="350"/>
+                    <animations/>
+                    <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
+                    <constraints>
+                        <constraint firstAttribute="width" constant="1555" id="7ob-FN-Pyb"/>
+                        <constraint firstAttribute="height" constant="350" id="NRR-JN-TcZ"/>
+                    </constraints>
+                    <connections>
+                        <outlet property="dataSource" destination="-1" id="f0f-ZE-xAG"/>
+                        <outlet property="delegate" destination="-1" id="KRu-Hq-2VH"/>
+                    </connections>
+                </tableView>
+                <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Cached Media" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="77q-qM-GSv">
+                    <rect key="frame" x="837" y="544" width="246" height="46"/>
+                    <animations/>
+                    <fontDescription key="fontDescription" style="UICTFontTextStyleHeadline"/>
+                    <color key="textColor" white="0.33333333333333331" alpha="1" colorSpace="calibratedWhite"/>
+                    <nil key="highlightedColor"/>
+                </label>
             </subviews>
             <animations/>
             <constraints>
+                <constraint firstItem="WfO-PV-wWU" firstAttribute="centerX" secondItem="iN0-l3-epB" secondAttribute="centerX" id="CNP-DM-grr"/>
                 <constraint firstItem="N4Q-4c-bh0" firstAttribute="top" secondItem="iN0-l3-epB" secondAttribute="top" constant="193" id="Dsp-yk-pru"/>
                 <constraint firstItem="mOM-K1-6hX" firstAttribute="centerX" secondItem="N4Q-4c-bh0" secondAttribute="centerX" id="ScU-iV-uMa"/>
                 <constraint firstItem="mOM-K1-6hX" firstAttribute="top" secondItem="N4Q-4c-bh0" secondAttribute="bottom" constant="36" id="Szw-br-TIc"/>
                 <constraint firstItem="N4Q-4c-bh0" firstAttribute="centerX" secondItem="iN0-l3-epB" secondAttribute="centerX" id="VFF-HR-rhV"/>
+                <constraint firstAttribute="bottom" secondItem="WfO-PV-wWU" secondAttribute="bottom" constant="70" id="f6B-oF-hIP"/>
+                <constraint firstItem="WfO-PV-wWU" firstAttribute="top" secondItem="77q-qM-GSv" secondAttribute="bottom" constant="70" id="uW6-vD-T7X"/>
+                <constraint firstItem="77q-qM-GSv" firstAttribute="centerX" secondItem="WfO-PV-wWU" secondAttribute="centerX" id="xSw-ba-1ov"/>
             </constraints>
         </view>
     </objects>