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

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

Schedules the playing of an audio file segment with a callback option you specify.

## Declaration

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

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

## Parameters

- `file`: The file to play.
- `startFrame`: The starting frame position in the stream.
- `numberFrames`: The number of frames to play.
- `when`: The time the region plays.
- `callbackType`: The option to specify when the system must call the completion handler.
- `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:completionHandler:)](avfaudio/avaudioplayernode/schedulesegment(_:startingframe:framecount:at: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)
