Q: AVAnimator for movie animations on iOS I'm using the AVAnimator library in order to use movie animations in my iOS app. I have animations working fine, but I need to be able to remove the animation once it's over, and also allow the same animation to play on top of itself even before the prior one is done.
Here's the code I'm using to animate:
    bassView = [AVAnimatorView aVAnimatorViewWithFrame:CGRectMake(322,460,375,224)];
    AVAnimatorMedia *media = [AVAnimatorMedia aVAnimatorMedia];
    AV7zAppResourceLoader *resLoader = [AV7zAppResourceLoader aV7zAppResourceLoader];
    resLoader.archiveFilename = @"Archive.7z";
    resLoader.movieFilename = @"bass_iPad.mvid";
    resLoader.outPath = [AVFileUtil getTmpDirPath:@"bass_iPad.mvid"];
    media.resourceLoader = resLoader;
    AVMvidFrameDecoder *frameDecoder = [AVMvidFrameDecoder aVMvidFrameDecoder];
    media.frameDecoder = frameDecoder;
    media.animatorFrameDuration = AVAnimator10FPS;      // this is a constant I made for the frame rate
    [media prepareToAnimate];
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(animatorDoneNotification:)
                                                 name:AVAnimatorDoneNotification
                                               object:media];
    [mainView addSubview:bassView];
    [bassView attachMedia:media];
    [media startAnimator];

- (void)animatorDoneNotification:(NSNotification*)notification {
    NSLog(@"animation done");
    AVAnimatorMedia *media = notification.object;
   [media stopAnimator];
   [bassView removeFromSuperview];
}


A: When you get the Notification to indicate that an animation loop is complete, you should disconnect the media object from the window/view using [bassView attachMedia:nil]. Just calling stopAnimator will stop sending new frames to the view, but if the animation cycle is really done then disconnecting the media from the view will deallocate resources and free up memory. Also, you do not need to set animatorFrameDuration as it is defined by default when the .mvid file is read. You can set it explicitly if you want to change the playback framerate, but you can just encode the FPS in the movie via "mvidmoviemaker Frame1.png Movie.mvid -fps 10" when creating the movie on the desktop.
If you want to play the same animation with multiple instances on screen at once, you need to create 2 different media objects and then start and stop them at the proper times. You will need to attach these media objects to different view objects on screen, but that it is all there is to it. You would likely code this up using 1 media object, wait for it to load, then once the first one is ready you can assign the same loader to a second media object and have it read from the same already decompressed file in the tmp dir. You could also use a common method to create 2 different loaders for the same input file, but be aware that there is a thread race condition if two different loaders both load the same file at app startup, you can also set the serialLoading flag on your loader objects to avoid the race condition.
