Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AVAssetImageGeneratorCompletionHandler - how to set or return variables?

i´m using the AVAssetImageGenerator to get images from a movieclip without playing it before. Now i´ve got a question how to set up variables in the loop of a handler? Is it possible? I´m getting this error message and have no idea what does that mean. (google> no results).

"Variable is not assignable (missing __block type specifier)"

So i have to ask the pro´s here. Here´s the code. I want to save or return my generated imageData, so i can delete the "setImage" message within that following handler.

UIImage* thumbImg = [[UIImage alloc] init];

AVAssetImageGeneratorCompletionHandler handler = ^(CMTime requestedTime, CGImageRef im, CMTime actualTime, AVAssetImageGeneratorResult result, NSError *error)
{
    if (result != AVAssetImageGeneratorSucceeded) 
    {
        NSLog(@"couldn't generate thumbnail, error:%@", error);
    }
    [button setImage:[UIImage imageWithCGImage:im] forState:UIControlStateNormal];
    thumbImg = [[UIImage  imageWithCGImage:im] retain];
    [generator release];
};

Would be great to learn about that. Thanks for your time.

like image 634
geforce Avatar asked Apr 28 '11 21:04

geforce


1 Answers

1st of all it seems you don't need to init your thumbImg when its declared - UIImage object created in that line will be overwritten in block and will leak. Just init it with nil value.

Actual problem in your code is that variable you're going to change in block should be declared with __block specifier (as error message says). So your 1s line should be

__block UIImage* thumbImg = nil;
like image 136
Vladimir Avatar answered Sep 18 '22 23:09

Vladimir