Attention: Here be dragons
This is the latest
(unstable) version of this documentation, which may document features
not available in or compatible with released stable versions of Godot.
Checking the stable version of the documentation...
AudioStreamMP3
继承: AudioStream < Resource < RefCounted < Object
MP3 音频流驱动程序。
描述
MP3 音频流驱动。如果你想要在运行时加载 MP3 文件,请参阅 data。
注意:如果引擎编译时使用了 SCons 选项 minimp3_extra_formats=yes
,则该类能够可选地支持历史遗留的 MP1 和 MP2 格式。默认不启用此类额外格式。
属性
|
||
|
||
|
||
|
||
|
||
|
方法
load_from_buffer(stream_data: PackedByteArray) static |
|
load_from_file(path: String) static |
属性说明
该属性目前没有描述,请帮我们贡献一个吧!
该属性目前没有描述,请帮我们贡献一个吧!
该属性目前没有描述,请帮我们贡献一个吧!
PackedByteArray data = PackedByteArray()
🔗
void set_data(value: PackedByteArray)
PackedByteArray get_data()
包含以字节为单位的音频数据。
你可以使用下面的代码片段,加载文件而无需事先导入它。请记住,此代码段将整个文件加载到内存中,对于大文件(数百兆字节或更多)可能并不理想。
func load_mp3(path):
var file = FileAccess.open(path, FileAccess.READ)
var sound = AudioStreamMP3.new()
sound.data = file.get_buffer(file.get_length())
return sound
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;
}
Note: The returned array is copied and any changes to it will not update the original property value. See PackedByteArray for more details.
如果为 true
,当流到达末尾时将自动循环。
循环时,流开始的时间,单位为秒。
方法说明
AudioStreamMP3 load_from_buffer(stream_data: PackedByteArray) static 🔗
从给定缓冲区新建 AudioStreamMP3 实例。缓冲区中必须包含 MP3 数据。
AudioStreamMP3 load_from_file(path: String) static 🔗
从给定的文件路径新建 AudioStreamMP3 实例。文件必须为 MP3 格式。