<!--
{
  "availability" : [
    "iOS: 2.2.0 -",
    "iPadOS: 2.2.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.7.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 3.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "AVFAudio",
  "identifier" : "/documentation/AVFAudio/AVAudioPlayer/init(contentsOf:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "AVFAudio"
    ],
    "preciseIdentifier" : "c:objc(cs)AVAudioPlayer(im)initWithContentsOfURL:error:"
  },
  "title" : "init(contentsOf:)"
}
-->

# init(contentsOf:)

Creates a player to play audio from a file.

```
init(contentsOf url: URL) throws
```

## Parameters

`url`

A URL that identifies the local audio file to play.

## Return Value

A new audio player instance, or <doc://com.apple.documentation/documentation/ObjectiveC/nil-227m0> if an error occurs.

## Discussion

The audio data must be in a format that Core Audio supports.

---

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)