Drawing Waveform with AVAssetReader and with ARC

落花浮王杯 提交于 2019-12-24 00:17:18

问题


I'm trying to apply Unsynchronized's answer (Drawing waveform with AVAssetReader) while using ARC. There were only a few modifications required, mostly release statements. Many thanks for a great answer! I'm using Xcode 4.2 targeting iOS5 device.

But I'm getting stuck on one statement at the end while trying to invoke the whole thing.

Method shown here:

-(void) importMediaItem {

    MPMediaItem* item = [self mediaItem];

    waveFormImage = [[UIImage alloc ] initWithMPMediaItem:item completionBlock:^(UIImage* delayedImagePreparation){

        [self displayWaveFormImage];
    }];

    if (waveFormImage) {
       [self displayWaveFormImage];
    }
}

On the call to initWithMPMediaItem I get the following error:

Automatic Reference Counting Issue.  Receiver type 'UIImage' for instance message 
does not declare a method with selector 'initWithMPMediaItem:completionBlock:'

Since I do have the method initWithMPMediaItem declared in the class header, I really don't understand why I'm getting this error.

- (id) initWithMPMediaItem:(MPMediaItem*)item
       completionBlock:(void (^)(UIImage* delayedImagePreparation))completionBlock;

Been trying to wrap my head around this for several hours now but to no avail. Is my method declaration wrong for this type of method? Thanks!


回答1:


It looks like initWithMPMediaItem should be declared as an initializer for UIImage. So you should declare it inside a UIImage category in your header file:

@interface UIImage (MPMedia)

- (id) initWithMPMediaItem:(MPMediaItem*)item
   completionBlock:(void (^)(UIImage* delayedImagePreparation))completionBlock;

@end


来源:https://stackoverflow.com/questions/9509020/drawing-waveform-with-avassetreader-and-with-arc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!