AudioStreamMP3
MP3 audio stream driver.
MP3 audio stream driver.
MP3 audio stream driver. See AudioStreamMP3.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.
Declarations checked against C# SDK 1.0.0. Expand a name to see declarations and documentation.
Constructors1
AudioStreamMP3Constructor
public AudioStreamMP3();Properties6
BarBeatsProperty
public int BarBeats { get; set; }Number of musical beats per bar, for example 4 for a four-beat bar. This is composition metadata, not bars within one beat or an automatically analyzed audio value.
BeatCountProperty
public int BeatCount { get; set; }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.
BpmProperty
public double Bpm { get; set; }The tempo of the audio track, measured in beats per minute.
DataProperty
public byte[] Data { get; set; }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;
}LoopProperty
public bool Loop { get; set; }If true, the stream will play again from the specified AudioStreamMP3.LoopOffset 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 AudioStreamMP3.BeatCount. Useful for ambient sounds and background music.
LoopOffsetProperty
public double LoopOffset { get; set; }Loop restart position in seconds when Loop is enabled. It is not a WAV frame index and does not specify an independent loop end. Check it against the actual recording.
Methods16
GetBarBeatsint
public int GetBarBeats();intGetBeatCountint
public int GetBeatCount();intGetBpmdouble
public double GetBpm();doubleGetDatabyte[]
public byte[] GetData();byte[]GetLoopOffsetdouble
public double GetLoopOffset();doubleHasLoopbool
public bool HasLoop();boolLoadFromBuffer2 overloads
public static AudioStreamMP3 LoadFromBuffer(byte[] streamData);Creates a new AudioStreamMP3 instance from the given buffer. The buffer must contain MP3 data.
| Name | Type | Default |
|---|---|---|
streamData | byte[] | — |
AudioStreamMP3public static AudioStreamMP3 LoadFromBuffer(ReadOnlySpan<byte> streamData);Creates a new AudioStreamMP3 instance from the given buffer. The buffer must contain MP3 data.
| Name | Type | Default |
|---|---|---|
streamData | ReadOnlySpan<byte> | — |
AudioStreamMP3LoadFromFileAudioStreamMP3
public static AudioStreamMP3 LoadFromFile(string path);Reads a raw audio file directly without applying editor .import settings. Use ResourceLoader.Load for a project asset with its imported settings. Set loop and music metadata on the result explicitly.
| Name | Type | Default |
|---|---|---|
path | string | — |
pathPath to the actual source file. Ensure it is available in the chosen build; an imported resource path does not guarantee the original bytes are shipped.
AudioStreamMP3Loaded audio resource, or null on a reading/format error. Check the result before playback.
SetBarBeatsvoid
public void SetBarBeats(int count);| Name | Type | Default |
|---|---|---|
count | int | — |
SetBeatCountvoid
public void SetBeatCount(int count);| Name | Type | Default |
|---|---|---|
count | int | — |
SetBpmvoid
public void SetBpm(double bpm);| Name | Type | Default |
|---|---|---|
bpm | double | — |
SetData2 overloads
public void SetData(byte[] data);| Name | Type | Default |
|---|---|---|
data | byte[] | — |
public void SetData(ReadOnlySpan<byte> data);| Name | Type | Default |
|---|---|---|
data | ReadOnlySpan<byte> | — |
SetLoopvoid
public void SetLoop(bool enable);| Name | Type | Default |
|---|---|---|
enable | bool | — |
SetLoopOffsetvoid
public void SetLoopOffset(double seconds);| Name | Type | Default |
|---|---|---|
seconds | double | — |