Skip to content

Instantly share code, notes, and snippets.

@jawngee
Created August 11, 2018 15:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jawngee/f618d39ddc428e4492813865c7c02789 to your computer and use it in GitHub Desktop.
Save jawngee/f618d39ddc428e4492813865c7c02789 to your computer and use it in GitHub Desktop.
Background Looping Video
@import AVFoundation;
@import AVKit;
AVQueuePlayer *player = [[AVQueuePlayer alloc] init];
AVPlayerLayer *playerLayer = [AVPlayerLayer playerLayerWithPlayer:player];
playerLayer.frame = self.bounds;
playerLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
[self.layer addSublayer:playerLayer];
[player pause];
AVPlayerItem* playerItem = [AVPlayerItem playerItemWithURL:[NSBundle.mainBundle URLForResource:@"movie" withExtension:@"mov"]];
AVPlayerLooper* looper = [AVPlayerLooper playerLooperWithPlayer:player templateItem:playerItem];
[player play];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment