Looping a video with AVFoundation AVPlayer?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
Looping a video with AVPlayer is a common iOS task for splash screens, onboarding backgrounds, and ambient media. The most important design choice is whether you want a modern seamless loop using AVPlayerLooper or a manual restart approach for older or more customized playback logic.
The Best Modern Approach: AVQueuePlayer Plus AVPlayerLooper
For most current iOS code, the cleanest solution is AVPlayerLooper working with an AVQueuePlayer. It handles repetition for you and avoids the awkward "seek to start after finish" pattern.
This setup is usually what you want for a smooth loop with minimal custom code.
Manual Looping with End-of-Playback Notification
If you only have an AVPlayer and want full control, you can observe the end of the item and seek back to .zero.
This works, but it can be slightly less seamless than AVPlayerLooper, especially for short clips.
Choosing Between the Two
Use AVPlayerLooper when:
- you want a simple repeating clip
- seamless playback matters
- you are already comfortable using
AVQueuePlayer
Use manual notification-based restarting when:
- you need custom logic at each loop boundary
- you want to update UI or analytics every time the clip completes
- the playback flow is more than just endless looping
Both are valid, but AVPlayerLooper is the cleaner default.
Playing in a Reusable View
If the video is just a background element, it is often cleaner to wrap the player layer in a dedicated UIView subclass instead of putting all playback logic in a view controller.
That pattern is easier to reuse across screens.
Common Pitfalls
- Forgetting to retain the
AVPlayerLooper, which can stop the loop when the looper is deallocated. - Leaving the
AVPlayerLayerframe stale instead of updating it during layout changes. - Using notification-based looping without removing observers in more complex view lifecycles.
- Picking manual restart when you really wanted the smoother behavior of
AVPlayerLooper. - Looping large high-bitrate assets for decorative UI, which wastes battery and memory on mobile devices.
Summary
- '
AVPlayerLooperwithAVQueuePlayeris usually the cleanest way to loop video on iOS' - Manual restart with
AVPlayerItemDidPlayToEndTimestill works when you need custom loop-boundary logic - Retain both the player and the looper as properties
- Keep the player layer frame in sync with the view layout
- Optimize looped videos for UI usage so playback stays smooth and efficient

