---
title: VideoPlayer
framework: avkit
role: symbol
role_heading: Structure
path: avkit/videoplayer
---

# VideoPlayer

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

## Declaration

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

## Overview

Overview 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:)](avkit/videoplayer/init(player:).md)
- [init(player:videoOverlay:)](avkit/videoplayer/init(player:videooverlay:).md)

## Relationships

### Conforms To

- [Sendable](swift/sendable.md)
- [SendableMetatype](swift/sendablemetatype.md)
- [View](swiftui/view.md)
