You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ERR_FAIL_COND_V_MSG(file_data.is_empty(), Ref<AudioStreamOggVorbis>(), "Cannot open file '" + p_path + "'.");
returnload_from_buffer(file_data);
}
The code functions correctly within the editor:
func play_sample():
var audio_stream = AudioStreamOggVorbis.load_from_file(sample_path)
audio_player.stream = audio_stream
audio_player.play()
However, upon exporting the project, it displays the classic message "Can't open file from path."
I resolved this issue by utilizing ResourceLoader, as suggested in #87494 (comment) The amended code is as follows:
func play_sample():
var audio_stream = \
ResourceLoader.load(sample_path) as AudioStreamOggVorbis
audio_player.stream = audio_stream
audio_player.play()
It took me some time to identify and rectify this issue because the documentation lacks clarification regarding this behavior in the load_from_file method of the AudioStreamOggVorbis class. Perhaps a quick solution could be to add appropriate comments in the documentation to address this discrepancy like in FileAccess and DirAccess docs.
Steps to reproduce
Open a Godot project containing a script that utilizes the AudioStreamOggVorbis.load_from_file method to load an OGG audio file.
Ensure the project functions correctly within the Godot editor environment.
Export the project to an executable file (e.g., Windows, macOS, Linux) using the public export templates
Run the exported executable.
Attempt to execute the script that uses the AudioStreamOggVorbis.load_from_file method to load the OGG audio file.
Observe the error message "Can't open file from path" or any other relevant error prompts indicating the failure to load the audio file.
Found this myself yesterday. If you are dynamically loading audio files you need to change the Import settings in the editor to “No Import”. It will then keep them in the correct folders during Export.
Ignore me. The ResourceLoader method is obviously the intended way. As the reporter mentioned, it would be good to update documentation so this is clear. Alternatively, load_from_file should also not work in un-exported code so that’s it behaviour is consistent once exported.
For imported files, you should keep using preload() or load(). Runtime loading can only be used on non-imported files, as imported files are replaced with their remapped variant in the .godot/imported folder within the PCK.
This is why changing the import type to Keep File (No Import) works.
Tested versions
v4.2.1.stable
System information
Windows 10.0.22631 - GLES3 (Compatibility) - NVIDIA GeForce GTX 1050 (NVIDIA; 31.0.15.5123) - Intel(R) Core(TM) i5-9300H CPU @ 2.40GHz (8 Threads)
Issue description
Similar to #87494 but this issue arises from the use of FileAccess under the hood by AudioStreamOggVorbis.load_from_file.
godot/modules/vorbis/resource_importer_ogg_vorbis.cpp
Lines 245 to 249 in 4e990cd
The code functions correctly within the editor:
However, upon exporting the project, it displays the classic message "Can't open file from path."
I resolved this issue by utilizing ResourceLoader, as suggested in #87494 (comment) The amended code is as follows:
It took me some time to identify and rectify this issue because the documentation lacks clarification regarding this behavior in the load_from_file method of the AudioStreamOggVorbis class. Perhaps a quick solution could be to add appropriate comments in the documentation to address this discrepancy like in FileAccess and DirAccess docs.
Steps to reproduce
AudioStreamOggVorbis.load_from_file
method to load an OGG audio file.AudioStreamOggVorbis.load_from_file
method to load the OGG audio file.Minimal reproduction project (MRP)
Test.zip
The text was updated successfully, but these errors were encountered: