AVPlayer — Key Concepts, Features and Usage

Author: IT Sectr Published: 2026-05-23 Reading time: 9 min

AVPlayer is a media player framework from Apple, part of AVFoundation, providing audio and video playback on iOS, macOS, tvOS and visionOS. AVPlayer supports a wide range of formats — from local MP4 files to adaptive HLS streams — through a unified API with hardware-accelerated decoding on Apple Silicon chips. According to Apple WWDC (2024), AVPlayer is used in 90% of iOS applications working with media, including Apple TV, Music and Photos.

Key Takeaways

  • AVPlayer — Apple’s media player framework from AVFoundation for all Apple platforms.
  • Hardware Acceleration — AVPlayer uses VideoToolbox for GPU decoding, reducing power consumption.
  • HLS — Native HTTP Live Streaming support with automatic adaptive bitrate switching.
  • Picture in Picture — Built-in support for picture-in-picture mode on iPad, iPhone and Mac.
  • DRM — Integration with FairPlay Streaming for premium content protection.

What is AVPlayer?

AVPlayer is the central component of the AVFoundation framework, responsible for multimedia playback on all Apple platforms. Introduced in iOS 4.0 (2010) as a replacement for the deprecated MPMoviePlayerController, AVPlayer provides low-level control over playback with fine-tuning of decoding parameters, audio-video synchronization, and integration with system services such as AirPlay and Picture in Picture.

Unlike third-party players, AVPlayer benefits from hardware acceleration on Apple Silicon chips. Video decoding is performed through VideoToolbox using the dedicated M-series media engines (Media Engine), enabling 8K HDR playback with minimal power consumption. For HEVC (H.265) and ProRes, decoding happens on specialized chip blocks without burdening the CPU.

AVPlayer is tightly integrated with the Apple ecosystem: Handoff support for transferring playback between devices, AirPlay 2 for streaming to Apple TV, spatial audio with dynamic head tracking, and synchronization with system control elements via MPNowPlayingInfoCenter. These integrations make AVPlayer the de facto standard for all media-working applications on Apple platforms.

AVFoundation and Class Hierarchy

The AVFoundation framework provides a three-level hierarchy for playback: AVAsset (metadata and content information), AVPlayerItem (state and management of a specific content instance), and AVPlayer (playback control). This architecture separates metadata loading, playback preparation, and the playback process itself — which is especially important for HLS streams with multiple bitrate alternatives.

AVAsset represents a media content model — a file or stream. AVAsset is not playable by itself; it contains tracks (AVAssetTrack), metadata (commonMetadata), duration information, and other characteristics. An AVPlayerItem is created from AVAsset, which can then be passed to AVPlayer for playback.

Key Features of AVPlayer

AVPlayer provides a set of capabilities covering most playback scenarios — from simple file playback to complex live broadcasts with DRM. Let’s explore the key features with usage examples.

FeatureDescriptionPlatforms
Local FilesMP4, MOV, M4V, AVI, MKV (via extensions)iOS, macOS, tvOS
HLSHTTP Live Streaming with adaptive ABRAll Apple platforms
FairPlay DRMProtected HLS content with streaming licenseiOS, tvOS, macOS
Picture in PictureFloating video window over other appsiPad, iPhone (iOS 14+), Mac
AirPlay 2Wireless streaming to Apple TV and speakersAll platforms
Spatial AudioDolby Atmos and dynamic head trackingiOS 15+, macOS 13+
HDRDolby Vision, HDR10, HLG with display supportiOS 11+, macOS 10.13+

HLS Support and Adaptive Switching

AVPlayer has native HLS support without requiring additional libraries. When playing an HLS stream, AVPlayer automatically handles adaptive bitrate switching using a built-in ABR algorithm optimized for Apple platforms. The algorithm considers not only network bandwidth but also the device’s thermal state — when overheating, AVPlayer may reduce bitrate to lower CPU load.

For HLS streams with FairPlay Streaming, AVPlayer automatically handles license acquisition and renewal through the AVContentKeySession delegate. The developer needs to implement the AVContentKeySessionDelegate protocol, which is called by the player when a decryption key needs to be obtained or renewed. This is the only way to protect HLS content on Apple platforms, as Widevine is not supported on iOS.

Picture in Picture

PiP is a mode that allows users to continue watching video in a floating window when switching between apps. On iPad and iPhone (iOS 14+), AVPlayer integrates with AVPictureInPictureController to enable this mode. On macOS 15+, PiP is also available but activated through the system menu or a button in the player window.

How to Use AVPlayer in iOS Apps

Integrating AVPlayer into an iOS app can be done in two ways: through the high-level AVPlayerViewController (for standard scenarios) or directly via AVPlayer + AVPlayerLayer (for full UI customization). Let’s explore both approaches in Swift.

Integration via AVPlayerViewController

AVPlayerViewController is a ready-to-use UI component providing built-in controls: play/pause, seeking, volume, AirPlay, PiP, and fullscreen mode. Minimal integration requires just a few lines of code: create an AVPlayer instance, pass it to AVPlayerViewController, and display the controller on screen.

swift
import AVKit

let url = URL(string: "https://example.com/video.mp4")!
let asset = AVAsset(url: url)
let playerItem = AVPlayerItem(asset: asset)
let player = AVPlayer(playerItem: playerItem)

let controller = AVPlayerViewController()
controller.player = player
controller.allowsPictureInPicturePlayback = true

present(controller, animated: true) {
    player.play()
}

Direct Integration via AVPlayerLayer

For apps with custom UI, use AVPlayerLayer — a Core Animation layer that renders video inside any UIView. This approach gives full control over the interface: you can add custom controls, animations, and overlay additional layers on top of the video.

swift
class VideoPlayerView: UIView {

    var player: AVPlayer? {
        get { (layer as! AVPlayerLayer).player }
        set { (layer as! AVPlayerLayer).player = newValue }
    }

    override class var layerClass: AnyClass {
        AVPlayerLayer.self
    }
}

// Usage:
let playerView = VideoPlayerView(frame: view.bounds)
playerView.player = AVPlayer(url: url)
view.addSubview(playerView)

AVPlayer Lifecycle Management

Proper player lifecycle management is critical for app stability. AVPlayer should be created when the screen appears and released when it is dismissed. When the app goes into the background, it is recommended to pause playback to conserve resources and avoid App Review penalties for unnecessary background playback.

AVPlayerLayer and Video Display

AVPlayerLayer is a Core Animation layer inheriting from CALayer that renders video on screen. Unlike UIView, AVPlayerLayer works directly with the GPU via Metal or OpenGL, ensuring minimal frame output latency. Understanding AVPlayerLayer is essential for implementing custom playback interfaces.

Configuring videoGravity

The videoGravity property determines how video fits within the layer bounds. AVLayerVideoGravity.resizeAspect (maintaining aspect ratio with black bars) is the default for AVPlayerViewController. resizeAspectFill (filling the entire screen with cropping) is used for fullscreen mode. resize (distorting proportions to fit the layer size) is rarely used, mainly for analytical applications.

Main Thread Synchronization

AVPlayerLayer renders video in real time, but all player operations (start, pause, seek) must be performed on the main thread. Key values for observation — timeControlStatus, rate, status, and error — are tracked via KVO (Key-Value Observing) or the modern async/await API introduced in iOS 16 through AVPlayer methods with Swift Concurrency support.

swift
let player = AVPlayer(url: url)
let statusObservation = player.observe(
    \.status,
    options: [.new, .initial]
) { player, _ in
    switch player.status {
    case .readyToPlay:
        player.play()
    case .failed:
        handleError(player.error)
    default:
        break
    }
}

Subtitle and Alternative Track Support

AVPlayer supports embedded subtitles in VTT, CEA-608, and ITT (iTunes Timed Text) formats. Audio track and subtitle selection is done through AVMediaSelectionGroup and AVMediaSelectionOption. User subtitle settings (font, size, color) are read from system Accessibility settings and automatically applied to AVPlayerLayer unless explicitly specified in code.

Playback Management and Advanced Scenarios

For production applications, basic AVPlayer integration often requires additional configuration: HLS segment caching, FairPlay DRM integration, Now Playing system integration, and custom bitrate selection algorithms.

HLS Caching via AVAssetResourceLoader

AVAssetResourceLoader is the only way to intercept HLS segment loading and implement caching. The AVAssetResourceLoaderDelegate receives loading requests for keys and segments, allowing them to be stored locally and returned from cache on subsequent requests. This is especially useful for applications operating in unstable network conditions.

swift
let asset = AVURLAsset(url: hlsURL)
asset.resourceLoader.setDelegate(
    resourceLoaderDelegate,
    queue: DispatchQueue(label: "com.app.resourceloader")
)
let playerItem = AVPlayerItem(asset: asset)

FairPlay Streaming — DRM Integration

FairPlay Streaming (FPS) is Apple’s standard for protecting HLS content. To integrate FPS, you need to implement the AVContentKeySessionDelegate protocol, which handles requests for decryption keys. The process includes: obtaining SPC (Server Playback Context) from the player, sending it to a license server, receiving CKC (Content Key Context), and passing it back to AVContentKeySession.

swift
class DRMDelegate: NSObject, AVContentKeySessionDelegate {

    func contentKeySession(
        _ session: AVContentKeySession,
        didProvide keyRequest: AVContentKeyRequest
    ) {
        // 1. Get SPC from keyRequest
        // 2. Send SPC to license server
        // 3. Get CKC and pass to keyRequest.processContentKeyResponse
    }
}

Now Playing and System Controls

To display current playback information on the Lock Screen, Control Center, and Apple Watch, use MPNowPlayingInfoCenter from MediaPlayer.framework. AVPlayer does not automatically update Now Playing — the developer must manually set metadata (title, artist, artwork, progress) when playback state changes. A regular timer or observe(\.timeControlStatus) is used for progress updates.

Remote Command Center is another system service that allows controlling playback from the locked screen, AirPods, and CarPlay. MPRemoteCommandCenter registers handlers for play, pause, nextTrack, previousTrack, changePlaybackPosition, and skipForward/skipBackward commands. AVPlayer does not handle these commands automatically — the developer must connect them to player.play(), player.pause(), and player.seek() calls.

Frequently Asked Questions

How is AVPlayer different from AVAudioPlayer?

AVPlayer is a universal player for audio and video with support for streaming, HLS, DRM, and synchronization with system controls. AVAudioPlayer is a simplified audio player for local audio file playback without streaming or hardware video acceleration. For video and HLS, use AVPlayer; for simple audio, use AVAudioPlayer.

Does AVPlayer support YouTube playback?

No, AVPlayer does not support direct YouTube content loading, as YouTube uses its own player based on DASH and proprietary formats. To integrate YouTube into an iOS app, use the YouTube IFrame Player API via WKWebView or the official youtube-ios-player-helper library.

How to implement background audio playback with AVPlayer?

For background audio, add Audio, AirPlay and Picture in Picture to Background Modes in your Xcode project. Configure AVAudioSession with the .playback category: try AVAudioSession.sharedInstance().setCategory(.playback). AVPlayer will continue playing in the background, and the Lock Screen and Control Center will display controls via MPNowPlayingInfoCenter.

Why doesn’t AVPlayer play videos from YouTube, Vimeo, or Twitter?

These services use DRM protection and their own player solutions. AVPlayer can only play content via a direct media file URL or HLS playlist. Videos from YouTube and similar platforms are wrapped in iframe or JavaScript players that are incompatible with AVPlayer. Use their official SDKs or WebView for display.

How to reduce latency in live streaming via AVPlayer?

For Low-Latency HLS, configure AVPlayerItem with preferredForwardBufferDuration = 2.0 (seconds) and automatically manage pause when falling behind the live edge: use player.currentItem?.configuredTimeOffsetFromLive and player.currentItem?.canPlayReverse. Apple recommends LL-HLS with 2-4 second latency when properly configured on both server and client.

Summary

  • AVPlayer — Apple’s universal media player with hardware acceleration on Apple Silicon for iOS, macOS, tvOS and visionOS.
  • HLS — Native support with automatic adaptive bitrate switching without additional libraries.
  • FairPlay Streaming — The only DRM system for protected HLS on Apple platforms.
  • Integration — AVPlayerViewController for quick start or AVPlayerLayer for custom UI.
  • Caching HLS is implemented via AVAssetResourceLoaderDelegate by intercepting segment requests.
  • Now Playing — Manual metadata updates for Control Center and Lock Screen via MPNowPlayingInfoCenter.
  • Recommended to use AVPlayer for all media projects on Apple platforms with HLS requirements.

We will develop a mobile application turnkey

IT Sectr creates iOS and Android applications for startups and businesses since 2017. We will advise you and propose the best solution.

Discuss the project

Read also