Skip to content

AudioStreamMP3

Inherits: AudioStream < Resource < RefCounted < Object

MP3 audio stream driver.

MP3 audio stream driver. See data if you want to load an MP3 file at run-time. More info can be found in ResourceImporterMP3.

Note: This class can optionally support legacy MP1 and MP2 formats, provided that the engine is compiled with the minimp3_extra_formats=yes SCons option. These extra formats are not enabled by default.

Type Name Default
int bar_beats 4
int beat_count 0
float bpm 0.0
PackedByteArray data PackedByteArray()
bool loop false
float loop_offset 0.0
Returns Method
AudioStreamMP3 load_from_buffer(stream_data: PackedByteArray) static
AudioStreamMP3 load_from_file(path: String) static

bar_beats

int bar_beats = 4

The number of beats within a single bar in the audio track.

beat_count

int beat_count = 0

The length of the audio track, in beats. The actual duration of the audio file might be longer than what is indicated by this property. It defines the end of the audio for looping, AudioStreamPlaylist, and AudioStreamInteractive.

bpm

float bpm = 0.0

The tempo of the audio track, measured in beats per minute.

data

PackedByteArray data = PackedByteArray()

Contains the audio data in bytes.

You can load a file without having to import it beforehand using the code snippet below. Keep in mind that this snippet loads the whole file into memory and may not be ideal for huge files (hundreds of megabytes or more).

public AudioStreamMP3 LoadMP3(string path)
{
using var file = FileAccess.Open(path, FileAccess.ModeFlags.Read);
var sound = new AudioStreamMP3();
sound.Data = file.GetBuffer(file.GetLength());
return sound;
}

loop

bool loop = false

If true, the stream will play again from the specified loop_offset once it reaches the end of the audio track, or once it reaches the end of the last beat according to the amount specified in beat_count. Useful for ambient sounds and background music.

loop_offset

float loop_offset = 0.0

Time in seconds at which the stream starts after being looped.

load_from_buffer

AudioStreamMP3 load_from_buffer(stream_data: PackedByteArray) static

Creates a new AudioStreamMP3 instance from the given buffer. The buffer must contain MP3 data.

load_from_file

AudioStreamMP3 load_from_file(path: String) static

Creates a new AudioStreamMP3 instance from the given file path. The file must be in MP3 format.