无法从网址中将视频保存到库中,无法从库中播放视频

时间:2014-05-27 12:54:17

标签: ios

假设我有一个像

这样的视频网址

http://example.com/1901728349.mp4

我通过以下程序从链接下载:

 -(void)DownloadVideo
 {
    //download the file in a seperate thread.
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        NSLog(@"Downloading Started");
        NSString *urlToDownload = VIDEO_LINK;
        // NSString *urlToDownload =@"http:\/\/example.com\/1901728349.mp4";
        NSURL  *url = [NSURL URLWithString:urlToDownload];
        NSData *urlData = [NSData dataWithContentsOfURL:url];
        if ( urlData )
        {
            NSArray       *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
            NSString  *documentsDirectory = [paths objectAtIndex:0];

            NSString  *filePath = [NSString stringWithFormat:@"%@/%@", documentsDirectory,@"1901728349.mp4"];
            NSLog(@"filePath %@",filePath);
            filepathURL=filePath;   // getting the video path

            //saving is done on main thread
            dispatch_async(dispatch_get_main_queue(), ^{
                [urlData writeToFile:filePath atomically:YES];
                NSLog(@"File Saved in document directory !");


            });
        }

    });
  }

之后我想将视频保存到我的库中:

 - (void)saveVideoToLibrary{

  NSString *albumName=@"DemoAlbum";
  self.library = [[ALAssetsLibrary alloc] init];
  [self.library addAssetsGroupAlbumWithName:albumName
                               resultBlock:^(ALAssetsGroup *group) {
                                  NSLog(@"added album:%@", albumName);
                              }
                             failureBlock:^(NSError *error) {
                                 NSLog(@"error adding album");
                             }];
  [library writeVideoAtPathToSavedPhotosAlbum:
  [NSURL fileURLWithPath:filepathURL]     // here file path is the source path previously we got
  completionBlock:^(NSURL *assetURL, NSError *error)
   {
     if (error)
         NSLog(@"error %@",error);
     else
         NSLog(@"Success  Your video clip is saved");
    }];


 }

请告诉我我的问题在哪里。请在这方面帮助我。

谢谢&问候 Tapash Mollick

0 个答案:

没有答案