<!--
{
  "availability" : [
    "iOS: 14.0.0 -",
    "iPadOS: 14.0.0 -",
    "macCatalyst: 14.0.0 -",
    "macOS: 11.0.0 -",
    "tvOS: 14.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 7.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "AVKit",
  "identifier" : "/documentation/AVKit/VideoPlayer",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "AVKit",
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:14_AVKit_SwiftUI11VideoPlayerV"
  },
  "title" : "VideoPlayer"
}
-->

# VideoPlayer

A view that displays content from a player and a native user interface to control playback.

```
@MainActor @preconcurrency struct VideoPlayer<VideoOverlay> where VideoOverlay : View
```

## Overview

```swift
import SwiftUI
import AVKit

struct ContentView: View {

    /// An optional player the view creates in a task modifier.
    ///
    /// Creating the player instance indirectly helps to avoid 
    /// performance issues and other side effects.
    @State private var player: AVPlayer?
    @State private var isPlaying = false

    var body: some View {
        VStack {
            if let player {
                VideoPlayer(player: player)
                    .frame(width: 320, height: 180, alignment: .center)

                Button {
                    isPlaying ? player.pause() : player.play()
                    isPlaying.toggle()
                    player.seek(to: .zero)
                } label: {
                    Image(systemName: isPlaying ? "stop" : "play")
                        .padding()
                }
            }
        }
        .task {
            // Use the task modifier to defer creating the player to ensure
            // SwiftUI creates it only once when it first presents the view.
            let url = // URL to local or remote media.
            player = AVPlayer(url: url)
        }
    }
}
```

## Topics

### Creating a video player

[`init(player:)`](/documentation/AVKit/VideoPlayer/init(player:))

Creates a video-player user interface for the player object.

[`init(player:videoOverlay:)`](/documentation/AVKit/VideoPlayer/init(player:videoOverlay:))

Creates a video-player user interface for the player object.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)