瀏覽代碼

GDrive: added streaming

Carola Nitz 11 年之前
父節點
當前提交
ea17df6a2e
共有 3 個文件被更改,包括 19 次插入3 次删除
  1. 1 0
      Sources/VLCGoogleDriveController.h
  2. 8 0
      Sources/VLCGoogleDriveController.m
  3. 10 3
      Sources/VLCGoogleDriveTableViewController.m

+ 1 - 0
Sources/VLCGoogleDriveController.h

@@ -40,6 +40,7 @@
 - (void)logout;
 - (void)requestDirectoryListingWithFolderId:(NSString *)folderId;
 - (BOOL)hasMoreFiles;
+- (void)streamFile:(GTLDriveFile *)file;
 - (void)downloadFileToDocumentFolder:(GTLDriveFile *)file;
 
 @end

+ 8 - 0
Sources/VLCGoogleDriveController.m

@@ -147,6 +147,14 @@
                           }];
 }
 
+- (void)streamFile:(GTLDriveFile *)file
+{
+    VLCAppDelegate *appDelegate = (VLCAppDelegate *)[UIApplication sharedApplication].delegate;
+    NSString *token = ((GTMOAuth2Authentication *)self.driveService.authorizer).accessToken;
+    NSString *downloadString = [file.downloadUrl stringByAppendingString:[NSString stringWithFormat:@"&access_token=%@",token]];
+    [appDelegate openMovieFromURL:[NSURL URLWithString:downloadString]];
+}
+
 - (void)_triggerNextDownload
 {
     if (_listOfGoogleDriveFilesToDownload.count > 0 && !_downloadInProgress) {

+ 10 - 3
Sources/VLCGoogleDriveTableViewController.m

@@ -214,7 +214,6 @@
         cell = [VLCCloudStorageTableViewCell cellWithReuseIdentifier:CellIdentifier];
 
     cell.driveFile = _googleDriveController.currentListFiles[indexPath.row];
-    cell.downloadButton.hidden = YES;
     cell.delegate = self;
 
     return cell;
@@ -231,8 +230,7 @@
 {
     _selectedFile = _googleDriveController.currentListFiles[indexPath.row];
     if (![_selectedFile.mimeType isEqualToString:@"application/vnd.google-apps.folder"]) {
-        UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"DROPBOX_DOWNLOAD", @"") message:[NSString stringWithFormat:NSLocalizedString(@"DROPBOX_DL_LONG", @""), _selectedFile.title, [[UIDevice currentDevice] model]] delegate:self cancelButtonTitle:NSLocalizedString(@"BUTTON_CANCEL", @"") otherButtonTitles:NSLocalizedString(@"BUTTON_DOWNLOAD", @""), nil];
-        [alert show];
+        [_googleDriveController streamFile:_selectedFile];
     } else {
         /* dive into subdirectory */
         if (![_currentFolderId isEqualToString:@""])
@@ -243,6 +241,15 @@
     [self.tableView deselectRowAtIndexPath:indexPath animated:NO];
 }
 
+- (void)triggerDownloadForCell:(VLCCloudStorageTableViewCell *)cell
+{
+    _selectedFile = _googleDriveController.currentListFiles[[self.tableView indexPathForCell:cell].row];
+
+    /* selected item is a proper file, ask the user if s/he wants to download it */
+    UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"DROPBOX_DOWNLOAD", @"") message:[NSString stringWithFormat:NSLocalizedString(@"DROPBOX_DL_LONG", @""), _selectedFile.title, [[UIDevice currentDevice] model]] delegate:self cancelButtonTitle:NSLocalizedString(@"BUTTON_CANCEL", @"") otherButtonTitles:NSLocalizedString(@"BUTTON_DOWNLOAD", @""), nil];
+    [alert show];
+}
+
 - (void)scrollViewDidScroll:(UIScrollView *)scrollView
 {
     NSInteger currentOffset = scrollView.contentOffset.y;