<!--
{
  "availability" : [
    "macOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSSound",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSSound"
  },
  "title" : "NSSound"
}
-->

# NSSound

A simple interface for loading and playing audio files.

```
class NSSound
```

## Overview

You create a sound object with an audio file or data, which can be in any format that Core Audio supports. Customize the sound by configuring its properties, such as setting its playback volume and looping behavior. Call the sound’s [`play()`](/documentation/AppKit/NSSound/play()) method to begin playback. The system executes this call asynchronously so that it doesn’t interrupt the functioning of your app.

If you want to play the system beep sound, use the [`beep()`](/documentation/AppKit/NSSound/beep()) (Swift) or [`NSBeep`](/documentation/AppKit/NSBeep) (Objective-C) function.

## Topics

### Detecting When a Sound Finishes Playing

[`delegate`](/documentation/AppKit/NSSound/delegate)

The sound’s delegate.

[`NSSoundDelegate`](/documentation/AppKit/NSSoundDelegate)

A set of optional methods implemented by delegates of [`NSSound`](/documentation/AppKit/NSSound) objects.

### Creating Sounds

[`canInit(with:)`](/documentation/AppKit/NSSound/canInit(with:))

Indicates whether the receiver can create an instance of itself from the data in a pasteboard.

[`init(contentsOfFile:byReference:)`](/documentation/AppKit/NSSound/init(contentsOfFile:byReference:))

Initializes the receiver with the audio data located at a given filepath.

[`init(contentsOf:byReference:)`](/documentation/AppKit/NSSound/init(contentsOf:byReference:))

Initializes the receiver with the audio data located at a given URL.

[`init(data:)`](/documentation/AppKit/NSSound/init(data:))

Initializes the receiver with a given audio data.

[`init(pasteboard:)`](/documentation/AppKit/NSSound/init(pasteboard:))

Initializes the receiver with data from a pasteboard. The pasteboard should contain a type returned by [`NSSound`](/documentation/AppKit/NSSound). `NSSound` expects the data to have a proper magic number, sound header, and data for the formats it supports.

### Configuring Sounds

[`name`](/documentation/AppKit/NSSound/name-swift.property)

The name assigned to the sound.

[`NSSound.Name`](/documentation/AppKit/NSSound/Name-swift.typealias)

[`setName(_:)`](/documentation/AppKit/NSSound/setName(_:))

[`volume`](/documentation/AppKit/NSSound/volume)

The volume of the sound.

[`currentTime`](/documentation/AppKit/NSSound/currentTime)

The sound’s playback progress, in seconds.

[`loops`](/documentation/AppKit/NSSound/loops)

A Boolean that indicates whether the sound restarts playback when it reaches the end of its content.

[`playbackDeviceIdentifier`](/documentation/AppKit/NSSound/playbackDeviceIdentifier-swift.property)

Identifies the sound’s output device

[`NSSound.PlaybackDeviceIdentifier`](/documentation/AppKit/NSSound/PlaybackDeviceIdentifier-swift.typealias)

### Getting Sound Information

[`soundUnfilteredTypes`](/documentation/AppKit/NSSound/soundUnfilteredTypes)

Provides the file types the `NSSound` class understands.

[`init(named:)`](/documentation/AppKit/NSSound/init(named:))

Returns the `NSSound` instance associated with a given name.

[`duration`](/documentation/AppKit/NSSound/duration)

The duration of the sound, in seconds.

### Playing Sounds

[`beep()`](/documentation/AppKit/NSSound/beep())

Plays the system beep.

[`isPlaying`](/documentation/AppKit/NSSound/isPlaying)

A Boolean that indicates whether the sound is playing its audio data.

[`pause()`](/documentation/AppKit/NSSound/pause())

Pauses audio playback.

[`play()`](/documentation/AppKit/NSSound/play())

Initiates audio playback.

[`resume()`](/documentation/AppKit/NSSound/resume())

Resumes audio playback.

[`stop()`](/documentation/AppKit/NSSound/stop())

Concludes audio playback.

### Writing Sounds

[`write(to:)`](/documentation/AppKit/NSSound/write(to:))

Writes the receiver’s data to a pasteboard.

### Deprecated

[`channelMapping`](/documentation/AppKit/NSSound/channelMapping)

Provides the receiver’s channel map.

[`setChannelMapping:`](/documentation/AppKit/NSSound/setChannelMapping:)

Specifies the receiver’s channel map.

[`soundUnfilteredFileTypes`](/documentation/AppKit/NSSound/soundUnfilteredFileTypes)

Provides the list of file types the [`NSSound`](/documentation/AppKit/NSSound) class understands.

[`soundUnfilteredPasteboardTypes`](/documentation/AppKit/NSSound/soundUnfilteredPasteboardTypes)

Provides a list of the pasteboard types that the `NSSound` class can accept.

### Constants

[NSPasteboard Type for Sound Data](/documentation/AppKit/nspasteboard-type-for-sound-data)

The `NSSound` class defines this common pasteboard data type.



---

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)