---
title: "scheduleSegment(_:startingFrame:frameCount:at:completionHandler:)"
framework: avfaudio
role: symbol
role_heading: Instance Method
path: "avfaudio/avaudioplayernode/schedulesegment(_:startingframe:framecount:at:completionhandler:)"
---

# scheduleSegment(_:startingFrame:frameCount:at:completionHandler:)

Schedules the playing of an audio file segment.

## Declaration

```swift
func scheduleSegment(_ file: AVAudioFile, startingFrame startFrame: AVAudioFramePosition, frameCount numberFrames: AVAudioFrameCount, at when: AVAudioTime?, completionHandler: (@Sendable () -> Void)? = nil)
```

```swift
func scheduleSegment(_ file: AVAudioFile, startingFrame startFrame: AVAudioFramePosition, frameCount numberFrames: AVAudioFrameCount, at when: AVAudioTime?) async
```

## Parameters

- `file`: The URL of the file to play.
- `startFrame`: The starting frame position in the stream.
- `numberFrames`: The number of frames to play.
- `when`: The time the buffer plays. For more information, see doc://com.apple.avfaudio/documentation/AVFAudio/AVAudioPlayerNode#Scheduling-Playback-Time.
- `completionHandler`: The handler the system calls after the player schedules the segment for playback on the render thread, or the player stops.

## Discussion

Discussion

## See Also

### Scheduling Playback

- [scheduleFile(_:at:completionHandler:)](avfaudio/avaudioplayernode/schedulefile(_:at:completionhandler:).md)
- [scheduleFile(_:at:completionCallbackType:completionHandler:)](avfaudio/avaudioplayernode/schedulefile(_:at:completioncallbacktype:completionhandler:).md)
- [scheduleSegment(_:startingFrame:frameCount:at:completionCallbackType:completionHandler:)](avfaudio/avaudioplayernode/schedulesegment(_:startingframe:framecount:at:completioncallbacktype:completionhandler:).md)
- [scheduleBuffer(_:at:options:completionHandler:)](avfaudio/avaudioplayernode/schedulebuffer(_:at:options:completionhandler:).md)
- [scheduleBuffer(_:completionHandler:)](avfaudio/avaudioplayernode/schedulebuffer(_:completionhandler:).md)
- [scheduleBuffer(_:at:options:completionCallbackType:completionHandler:)](avfaudio/avaudioplayernode/schedulebuffer(_:at:options:completioncallbacktype:completionhandler:).md)
- [scheduleBuffer(_:completionCallbackType:completionHandler:)](avfaudio/avaudioplayernode/schedulebuffer(_:completioncallbacktype:completionhandler:).md)
- [AVAudioPlayerNodeBufferOptions](avfaudio/avaudioplayernodebufferoptions.md)
- [AVAudioPlayerNodeCompletionCallbackType](avfaudio/avaudioplayernodecompletioncallbacktype.md)
- [AVAudioPlayerNodeCompletionHandler](avfaudio/avaudioplayernodecompletionhandler.md)
