# 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" |
The new instance.
Extends
Methods
# _save(packet) → {void}
Saves a data packet temporarily
Parameters:
Name | Type | Description |
---|---|---|
packet |
object
|
The packet to store. |
void
# _write() → {void}
Start writing the data from the temporal storage to the media track. Recursive, will stop when the storage is empty.
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:
The arguments.
Array.<string>
# destroy() → {Promise.<void>}
Destroys all streams and frees the port.
- Overrides:
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. |
void
# getMediaTrack() → {MediaStreamTrack}
Returns the current mediasoup media track
- Overrides:
The mediasoup MediaStreamTrack
MediaStreamTrack
# playFile(path) → {void}
Load and process an audio file
Parameters:
Name | Type | Description |
---|---|---|
path |
string
|
The file path of the file |
- Overrides:
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:
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 |
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 |
void
# writeStreamChunk(chunk) → {void}
Writes a chunk of data into the ffmpeg process.
Parameters:
Name | Type | Description |
---|---|---|
chunk |
object
|
The datachunk to write. |
- Overrides:
void