Add AudioStreamMP3 load_from_file/load_from_buffer and harmonize other audio streams
Move OggVorbis and MP3 loading code to their AudioStream class, matching how it's done for WAV. The duplicate functions in ResourceImporterOggVorbis are now deprecated. Co-authored-by: MaxIsJoe <34368774+MaxIsJoe@users.noreply.github.com>
This commit is contained in:
@ -312,7 +312,24 @@ Ref<AudioSample> AudioStreamMP3::generate_sample() const {
|
||||
return sample;
|
||||
}
|
||||
|
||||
Ref<AudioStreamMP3> AudioStreamMP3::load_from_buffer(const Vector<uint8_t> &p_stream_data) {
|
||||
Ref<AudioStreamMP3> mp3_stream;
|
||||
mp3_stream.instantiate();
|
||||
mp3_stream->set_data(p_stream_data);
|
||||
ERR_FAIL_COND_V_MSG(mp3_stream->get_data().is_empty(), Ref<AudioStreamMP3>(), "MP3 decoding failed. Check that your data is a valid MP3 audio stream.");
|
||||
return mp3_stream;
|
||||
}
|
||||
|
||||
Ref<AudioStreamMP3> AudioStreamMP3::load_from_file(const String &p_path) {
|
||||
const Vector<uint8_t> stream_data = FileAccess::get_file_as_bytes(p_path);
|
||||
ERR_FAIL_COND_V_MSG(stream_data.is_empty(), Ref<AudioStreamMP3>(), vformat("Cannot open file '%s'.", p_path));
|
||||
return load_from_buffer(stream_data);
|
||||
}
|
||||
|
||||
void AudioStreamMP3::_bind_methods() {
|
||||
ClassDB::bind_static_method("AudioStreamMP3", D_METHOD("load_from_buffer", "stream_data"), &AudioStreamMP3::load_from_buffer);
|
||||
ClassDB::bind_static_method("AudioStreamMP3", D_METHOD("load_from_file", "path"), &AudioStreamMP3::load_from_file);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_data", "data"), &AudioStreamMP3::set_data);
|
||||
ClassDB::bind_method(D_METHOD("get_data"), &AudioStreamMP3::get_data);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user