AudioStream on Android doesn't load

Godot Version

Godot 4.4.1

Question

Hi, I am creating an app that allows the user to chose a sound file that will be played after a timer. Also, to chose the file, I force the filedialog to only be picking ogg or mp3 and use device’s file system.

a. After picking

		Cache.save_file_cache(file_data, file)
		var full_path = Cache.folder_path + file
		var audio_stream: AudioStream
		if file.get_extension().to_lower() == "ogg":
			audio_stream = AudioStreamOggVorbis.load_from_file(full_path)
		elif file.get_extension().to_lower() == "mp3":
			audio_stream = AudioStreamMP3.load_from_file(full_path)
		else:
			print("Error, wrong file format")
			audio_soon.text = "Error, wrong file format, must be mp3 or ogg."
			audio_soon.visible = true
			return
		audio_tester.stream = audio_stream

b. Saving code

func save_file_cache(file_data: FileAccess, file_name: String) -> void:
	create_cache_folder()
	#var dir: DirAccess = DirAccess.open(folder_path)
	var new_file_path: String = folder_path + file_name
	var save_file = FileAccess.open(new_file_path, FileAccess.WRITE)
	if save_file:
		save_file.store_buffer(file_data.get_buffer(file_data.get_length()))
		save_file.close()
		file_data.close()
		print("File saved to cache:", new_file_path)
	else:
		push_error("Failed to save file to cache.")

c. FileSystem, on my laptop only ogg and mp3 are selectable, on Android no filters are applied (I have a if condition to counter it, though, but not great UX)

		else:
			print("Error, wrong file format")
			audio_soon.text = "Error, wrong file format, must be mp3 or ogg."
			audio_soon.visible = true
			return

When

  1. I play the audio_tester sound it on my laptop through Godot Engine, it works perfectly :white_check_mark:
  2. I play the audio_tester sound it on my phone through Godot Engine, it works perfectly :white_check_mark:
  3. When I run the app through an exported apk, no sound is played, and I can’t visualise any error :cross_mark:

Any ideas?

Hi all,

I managed to find the problem in the code.

It was these lines
audio_stream = AudioStreamOggVorbis.load_from_file(full_path)
audio_stream = AudioStreamMP3.load_from_file(full_path)
As Android couldn’t read the user file I use now:
audio_stream = AudioStreamOggVorbis.load_from_buffer(file.get_buffer(file.get_length()))

And it works!