<!--
{
  "availability" : [
    "iOS: 14.0.0 -",
    "iPadOS: 14.0.0 -",
    "macCatalyst: 14.0.0 -",
    "macOS: 11.0.0 -",
    "tvOS: 26.0.0 -",
    "visionOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "RealityKit",
  "identifier" : "/documentation/RealityKit/VideoMaterial/init(avPlayer:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "RealityKit"
    ],
    "preciseIdentifier" : "s:17RealityFoundation13VideoMaterialV8avPlayerACSo8AVPlayerC_tcfc"
  },
  "title" : "init(avPlayer:)"
}
-->

# init(avPlayer:)

Creates a new video material.

```
@MainActor @preconcurrency init(avPlayer: AVPlayer)
```

## Parameters

`avPlayer`

An
<doc://com.apple.documentation/documentation/AVFoundation/AVPlayer>
instance.

## Discussion

To create a video material, first create an
<doc://com.apple.documentation/documentation/AVFoundation/AVPlayer>
instance initialized with a URL that points to the movie file you want
the video material to play, then pass that to this initializer. The
following code demonstrates this process.

```swift
// Create a URL that points to the movie file.
if let url = Bundle.main.url(forResource: "MyMovie", withExtension: "mp4") {

    // Create an AVPlayer instance to control playback of that movie.
    let player = AVPlayer(url: url)

    // Instantiate and configure the video material.
    let material = VideoMaterial(avPlayer: player)

    // Configure audio playback mode. This is optional for movie
    // files that contain sound.
    material.controller.audioInputMode = .spatial

    // Create a new model entity using the video material.
    let modelEntity = ModelEntity(mesh: cube, materials: [material])

    // Start playing the video.
    player.play()
}
```

---

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)