How to get video attributes in iOS8 share extension

I am trying to create a video sharing extension using the new iOS 8 app extensions. I want to open a photo app and share a video using my extension.

I am getting the video url with the following codes:

NSExtensionItem *inputItem = self.extensionContext.inputItems.firstObject;
    NSItemProvider *provider = inputItem.attachments[0];

    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0), ^{

        if ([provider hasItemConformingToTypeIdentifier:(NSString *)kUTTypeQuickTimeMovie])
        {
            [provider loadItemForTypeIdentifier:@"com.apple.quicktime-movie" options:nil completionHandler:^(NSURL *path,NSError *error){
                if (path)
                {
                    dispatch_async(dispatch_get_main_queue(), ^{
                        _moviePath = path;
                    });
                }
            }];
        }
    });

      

But I only got the url of the video file:

file:///var/mobile/Media/DCIM/100APPLE/IMG_0062.MOV

      

I also want to get more attributes of the video like: size and duration

I used the following codes but didn't work:

NSDictionary *opts = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:NO]                                                   forKey:AVURLAssetPreferPreciseDurationAndTimingKey];
 AVURLAsset *urlAsset = [AVURLAsset URLAssetWithURL:_moviePath options:opts];  
int second = urlAsset.duration.value / urlAsset.duration.timescale; 

      

and this code:

AVPlayerItem *playerItem = [AVPlayerItem playerItemWithURL:_moviePath];
CMTime duration = playerItem.duration;
float seconds = CMTimeGetSeconds(duration);
NSLog(@"duration: %.2f", seconds);

      

they all don't work

and xcode hints:

Error [IRForTarget]: Call to a symbol-only function 'memset' that is not present in the target
error: 0 errors parsing expression
error: The expression could not be prepared to run in the target

      

Can you help me get the video attributes? Many thanks!

+3


source to share


1 answer


The following codes now work:

NSDictionary *opts = [NSDictionary 
    dictionaryWithObject:[NSNumber numberWithBool:NO]
    forKey:AVURLAssetPreferPreciseDurationAndTimingKey];

AVURLAsset *urlAsset = [AVURLAsset URLAssetWithURL:_moviePath options:opts];  
int second = urlAsset.duration.value / urlAsset.duration.timescale; 

      



And I don't know why it doesn't work before!

0


source







All Articles