2013-01-02 6 views
5

मैं का उपयोग कर एसेट पुस्तकालय में वीडियो लिख रहा हूँ [पुस्तकालय writeVideoAtPathToSavedPhotosAlbum करने का सही तरीका क्या है वीडियो से पहले यूआरएल पूरी तरह से संपत्ति पुस्तकालय को लिखते हैं। और जब मैं वीडियो के गुण प्राप्त करने के लिए ब्लॉक के अंदर लाइब्रेरी की गणना करता हूं तो मुझे उपरोक्त ब्लॉक द्वारा दिए गए यूआरएल के खिलाफ कोई वीडियो नहीं मिला। यदि मैं उसी यूआरएल के साथ संपत्ति लाइब्रेरी 3 या 4 बार मैन्युअल रूप से दोहराता हूं तो मुझे वीडियो एट्रिबर्स मिलते हैं। यह समस्या ज्यादातर तब होता है जब मैं अवधि से अधिक 5 मिनट के वीडियो बनाने मेरे कोड है:संपदा लाइब्रेरी की वीडियो लिखना और फिर उनकी विशेषताओं मिल

library = [[ALAssetsLibrary alloc] init]; 
    [library writeVideoAtPathToSavedPhotosAlbum:movieUrl completionBlock:^(NSURL *assetURL, NSError *error) 
    { 
     savedAssetURL = assetURL; 
     [self assetsEmumeration:assetURL]; 
     NSLog(@"asset url %@",assetURL); 
     if(error) 
     { 
      UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Failed" message:[error localizedDescription] delegate:self cancelButtonTitle:@"OK" otherButtonTitles:Nil]; 
      [alertView show]; 
     } 
    }]; 

    -(void) assetsEmumeration:(NSURL *)_url 
    { 
    NSLog(@"assets enumeration "); 
    ALAssetsLibrary *al;  
    void (^assetGroupEnumerator)(ALAssetsGroup *, BOOL *) = ^(ALAssetsGroup *group, BOOL *stop) 
    { 
     [group setAssetsFilter:[ALAssetsFilter allVideos]] ; 
     [group enumerateAssetsUsingBlock:^(ALAsset *asset, NSUInteger index, BOOL *stop) 
     { 
      if (asset) 
      { 
       ALAssetRepresentation *representation = [asset defaultRepresentation]; 
       NSURL *url = [representation url]; 
       if([[url absoluteString] isEqualToString:[_url absoluteString]]) 
       { 
        found = TRUE; 
        NSDictionary *asset_options = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES] forKey:AVURLAssetPreferPreciseDurationAndTimingKey]; 
        AVAsset *avAsset = [[AVURLAsset alloc] initWithURL:url options:asset_options]; 
        Float64 dur = CMTimeGetSeconds(avAsset.duration); 
        NSString *fileName = [representation filename]; 

        appDelegate.videoLength = [NSString stringWithFormat:@"%f seconds",dur]; 
        appDelegate.videoSize = [NSString stringWithFormat:@"%lld bytes",[representation size]]; 
        appDelegate.originalFileName = [NSString stringWithFormat:@"%@",fileName]; 
        [MBProgressHUD hideHUDForView:self.view animated:YES]; 
        ExtraInfoViewController *extraInfoViewObj = [[ExtraInfoViewController alloc] init]; 
        [self.navigationController pushViewController:extraInfoViewObj animated:YES]; 
        NSLog(@"duration:%f,fileName:%@",dur,fileName); 
       } 
       else 
       { 
        found = FALSE; 
       }  
      } 
     }]; 
     if(found == FALSE) 
     { 
      NSLog(@"video not found"); 
     } 
    };  
    void (^assetFailureBlock)(NSError *) = ^(NSError *error) 
    { 
     NSLog(@"failure"); 
     if(ALAssetsLibraryAccessGloballyDeniedError) 
     { 
      UIAlertView *alerview = [[UIAlertView alloc] initWithTitle:@"Denied" message:@"Failed to get the meta data. Access to assets library is denied" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:Nil]; 
      [alerview show]; 
     } 
    }; 
    al=[RecordVideoViewController defaultAssetsLibrary]; 
    [al enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:assetGroupEnumerator failureBlock:assetFailureBlock]; 
} 

उत्तर

6
// find out alAsset for that url and then do whatever you want with alAsset. 
library = [[ALAssetsLibrary alloc] init]; 
[library writeVideoAtPathToSavedPhotosAlbum:movieUrl completionBlock:^(NSURL *assetURL, NSError *error) 
{ 
    savedAssetURL = assetURL; 
    NSLog(@"asset url %@",assetURL); 
    if(error) 
    { 
     UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Failed" message:[error localizedDescription] delegate:self cancelButtonTitle:@"OK" otherButtonTitles:Nil]; 
     [alertView show]; 
    } 
    else 
    { 
     [library assetForURL:assetURL 
          resultBlock:^(ALAsset* alAsset) { 
          // do whatever you want with alAsset 
          }]; 
    } 
}]; 
संबंधित मुद्दे