Search code examples
iosobjective-c

Repeating 3 seconds movies for a help view?


We would like to create a short 3-4 seconds movies that repeats, exactly as they do in the Apple Tips app, where you see some example of using the iPhone in a movie that repeats many times.

I guess they are not using animation (and creating many images for it), but using some kind of movie player. My question is, what would be the best player to use - so it would looks like a GIF, without the player tool bar (play/stop/etc) .


Solution

  • Use AVPlayer to play the video continuously, it will look like a gif is playing continuously.

    -(void)startPlaybackForItemWithURL{
        // First create an AVPlayerItem
        // Subscribe to the AVPlayerItem's DidPlayToEndTime notification.
        NSString*thePath=[[NSBundle mainBundle] pathForResource:@"vegas" ofType:@"mov"];
        NSURL*theurl=[NSURL fileURLWithPath:thePath];
        AVPlayerItem* playerItem = [AVPlayerItem playerItemWithURL:theurl];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(itemDidFinishPlaying:) name:AVPlayerItemDidPlayToEndTimeNotification object:playerItem];
    
        player = [[AVPlayer alloc] initWithPlayerItem:playerItem];
    
        AVPlayerLayer *layer = [AVPlayerLayer layer];
    
        [layer setPlayer:player];
        [layer setFrame:CGRectMake(0, 0, 443, 239)];
        [layer setBackgroundColor:[UIColor clearColor].CGColor];
        [layer setVideoGravity:AVLayerVideoGravityResizeAspectFill];
    
        [viewVideo.layer addSublayer:layer];
    
        [player play];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(itemDidFinishPlaying:) name:AVPlayerItemDidPlayToEndTimeNotification object:player];
    }