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。更多信息请见 ResourceImporterMP3。
注意:如果引擎编译时使用了 SCons 选项 minimp3_extra_formats=yes,则该类能够可选地支持历史遗留的 MP1 和 MP2 格式。默认不启用此类额外格式。
教程
属性
|
||
|
||
|
||
|
||
|
||
|
方法
load_from_buffer(stream_data: PackedByteArray) static |
|
load_from_file(path: String) static |
属性说明
音轨中单节的拍数。
音轨的长度,单位为节拍。音频文件的实际时长可能长于该属性所指示的值。它定义了音频用于循环播放、AudioStreamPlaylist 和 AudioStreamInteractive 时的结束点。
音轨的拍速,以每分钟节拍数计量。
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,则当音频流播放至音轨末尾,或者根据 beat_count 指定的节拍数播放至最后一个节拍的末尾时,它将从 loop_offset 指定的位置重新开始播放。适用于环境音效和背景音乐。
循环时,流开始的时间,单位为秒。
方法说明
AudioStreamMP3 load_from_buffer(stream_data: PackedByteArray) static 🔗
从给定缓冲区新建 AudioStreamMP3 实例。缓冲区中必须包含 MP3 数据。
AudioStreamMP3 load_from_file(path: String) static 🔗
从给定的文件路径新建 AudioStreamMP3 实例。文件必须为 MP3 格式。