Discord Player
Guides

Crossfade

Blend the end of one track into the start of the next.

You are reading the v8 docsDev

Crossfade overlaps the end of the playing track with the start of the next one. It is off by default.

Enable it

Turn it on for every queue when you create the Player:

import { Player } from 'discord-player';

const player = new Player({
  crossfade: { enabled: true, durationMs: 5000 },
  send,
});

Or for one queue:

const queue = await player.createQueue(guildId, {
  crossfade: { enabled: true, durationMs: 8000, prepareBeforeMs: 30_000 },
});

A queue setting replaces the Player setting. Use crossfade: false to disable it for one queue.

OptionDefaultMeaning
enablednoneMust be true to opt in
durationMs5000Length of the overlap
prepareBeforeMs30000How long before the fade starts the next track is prepared
curve'equalPower'The only supported curve

The settings apply when a voice session is created. To change them for a guild, delete and recreate its queue.

Crossfade costs CPU

Crossfade decodes both tracks to PCM and mixes them. This uses more CPU than playing a single track.

What you will observe

Queue tracks as usual. The queue prepares the next track shortly before the fade, using the same source plugins as normal playback.

During the overlap:

  • playerStart for the incoming track can fire before playerFinish for the outgoing track.
  • queue.currentTrack is the incoming track as soon as it is audible.
  • The incoming track stays in queue.tracks until it becomes audible.

Staging a track for a fade does not fire playerStart.

How repeat modes behave

Repeat modeNext track
OFFThe next upcoming track
TRACKA new copy of the current track
QUEUEThe next upcoming track, and the finished track moves to the end
AUTOPLAYAn already chosen upcoming track. Otherwise autoplay runs as usual

With shuffle on, the next track is chosen once when it is prepared, and that same track is used when the fade happens.

Controls during a fade

ActionResult
Skip, seek, stop, history navigationCancels the prepared track
Pause and resumeThe prepared track is kept
Removing or moving the prepared trackCancels it and chooses again
queue.clear()Cancels preparation. The current track keeps playing

Use queue methods to change upcoming tracks. Changing queue.tracks.store directly resets preparation.

If preparing the next track fails, you receive playerError and the queue continues normally.

Embedded and remote nodes

An embedded node supports crossfade directly.

A remote node must also have crossfade enabled and report it as available. In remedia.config.json on the server:

{
  "audio": {
    "crossfade": { "enabled": true }
  }
}

If the selected node does not support crossfade, playback continues without it and the Player emits a debug message. Guilds are never moved to another node to enable crossfade.

Crossfade needs tracks long enough for the configured overlap.

Continue reading

Handle events

On this page