Class

MediaPlayer

MediaPlayer(logs, port, iFormat) → {MediaPlayer}

Constructor

# new MediaPlayer(logs, port, iFormat) → {MediaPlayer}

An advanced version of the Media class. It also includes media controls like pausing.

Parameters:
Name Type Default Description
logs boolean false

Wether or not to print logs to the console or not.

port number 5030

The port this instance should use.

iFormat string ""

Optional arguments that specify the input format that are passed to ffmpeg

Properties:
Name Type Description
seconds number

The amount of seconds passed during playback. Extracted from ffmpeg

currTimestamp string

The current timestamp as given by ffmpeg. "hh:mm:ss"

View Source Media.js, line 129

The new instance.

MediaPlayer

Extends

Methods

# _save(packet) → {void}

Saves a data packet temporarily

Parameters:
Name Type Description
packet object

The packet to store.

View Source Media.js, line 207

void

# _write() → {void}

Start writing the data from the temporal storage to the media track. Recursive, will stop when the storage is empty.

View Source Media.js, line 219

void

# createFfmpegArgs(start) → {Array.<string>}

Returns an array of arguments that can be passed to ffmpeg

Parameters:
Name Type Default Description
start string "00:00:00"

The position in the audio to start the conversion.

Overrides:

View Source Media.js, line 65

The arguments.

Array.<string>

# destroy() → {Promise.<void>}

Destroys all streams and frees the port.

Overrides:

View Source Media.js, line 271

A promise that resolves when everything is finished.

Promise.<void>

# async disconnect(destroy, f) → {void}

Cleans up this instance. Should be called when the bot is leaving.

Parameters:
Name Type Default Description
destroy boolean true

Wether or not to replace the mediatrack

f boolean true

Wether or not to respawn the ffmpeg instance.

View Source Media.js, line 244

void

# finished() → {void}

Function that is called when the ffmpeg stream finishes.

View Source Media.js, line 287

void

# getMediaTrack() → {MediaStreamTrack}

Returns the current mediasoup media track

Overrides:

View Source Media.js, line 73

The mediasoup MediaStreamTrack

MediaStreamTrack

# pause() → {void}

Pause the current playback

View Source Media.js, line 300

void

# playFile(path) → {void}

Load and process an audio file

Parameters:
Name Type Description
path string

The file path of the file

Overrides:

View Source Media.js, line 82

void

# async playStream(stream) → {void}

Play an audio read stream to the media track.

Parameters:
Name Type Description
stream ReadableStream

The stream to play.

Overrides:

View Source Media.js, line 394

void

# resume() → {void}

Resume the current playback.

View Source Media.js, line 311

void

# setReadNative(bool) → {void}

Change if ffmpeg should read the input at its native frame rate (-re flag). Set this to false if your input data is already at native frame rate to prevent packet loss.

Parameters:
Name Type Default Description
bool boolean true

true: read at native frame rate; false: process input as fast as possible

View Source Media.js, line 183

void

# setVolume(v) → {void}

Set the volume of the current playback

Parameters:
Name Type Default Description
v number 1

The new volume. 0 = nothing, 0.5 = half, 1 = default; Stay in between 0 and 1 to prevent bad music quality

View Source Media.js, line 323

void

# stop() → {Promise.<void>}

Stop the playback.

View Source Media.js, line 331

Resolves when all is cleaned up.

Promise.<void>

# writeStreamChunk(chunk) → {void}

Writes a chunk of data into the ffmpeg process.

Parameters:
Name Type Description
chunk object

The datachunk to write.

Overrides:

View Source Media.js, line 93

void