---
title: "withMusicSequence(_:)"
framework: avfaudio
role: symbol
role_heading: Instance Method
path: "avfaudio/avaudioengine/withmusicsequence(_:)"
---

# withMusicSequence(_:)

Provides scoped access to the AVAudioEngine’s MusicSequence

## Declaration

```swift
func withMusicSequence<R, E>(_ body: (borrowing MusicSequence?) throws(E) -> R) throws(E) -> R where E : Error
```

## Parameters

- `body`: A closure that receives a MusicSequence

## Return Value

Return Value The value returned by the closure

## Discussion

Discussion This method provides thread-safe, scoped access to the MusicSequence. The MusicSequence reference is only valid within the closure and must not be retained or accessed outside of it. note: Rethrows any error thrown by the closure

## See Also

### Playing Audio

- [prepare()](avfaudio/avaudioengine/prepare().md)
- [start()](avfaudio/avaudioengine/start().md)
- [isRunning](avfaudio/avaudioengine/isrunning.md)
- [pause()](avfaudio/avaudioengine/pause().md)
- [stop()](avfaudio/avaudioengine/stop().md)
- [reset()](avfaudio/avaudioengine/reset().md)
