Audio not working in HTML5 exported project

Hi everyone,
I’m working on a small projects in GODOT 3.5.3, during the time i was working on projects and testing it on debug I hadn’t any problems with audio but when i exported my projects in HTML5 I came across many error.

This is my code:

extends Node

var pathMenu = "Art - general/Sound/Stream Loops 2024-02-21_02.ogg"
var pathLvl1Song = "Art - general/Sound/Musiche livelli/Stream Loops 2024-02-14_L03.ogg"
var pathLvl2Song = "res://Art - general/Sound/Musiche livelli/Stream Loops 2024-02-07.ogg"
var pathLvl3Song = "res://Art - general/Sound/Musiche livelli/Stream Loops 2024-02-14_L01.ogg"
var pathLvl4Song = "res://Art - general/Sound/Musiche livelli/Loop-8.ogg"
var pathLvl5Song = "res://Art - general/Sound/Musiche livelli/Stream Loops 2024-02-28_01.ogg"
var flag = false
var tmp = -1

# Called when the node enters the scene tree for the first time.
func _ready():
	Global.volume = $AudioStreamPlayer.volume_db

# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
	$AudioStreamPlayer.volume_db = Global.volume
	if Global.is_in_what_lvl != tmp:
		match Global.is_in_what_lvl:
			1:
				$AudioStreamPlayer.stop()
				if _returnAudioToPlay(pathLvl1Song):
					_returnAudioToPlay(pathLvl1Song).play()
					flag = true
				else: 
					print("else")
			2:
				_returnAudioToPlay(pathLvl2Song).play()
				flag = true
			3:
				_returnAudioToPlay(pathLvl3Song).play()
				flag = true
			4:
				_returnAudioToPlay(pathLvl4Song).play()
				flag = true
			5:
				_returnAudioToPlay(pathLvl5Song).play()
				flag = true
			_:
				_returnAudioToPlay(pathMenu).play()
				flag = true
	tmp = Global.is_in_what_lvl



func _returnAudioToPlay(path):
	var file = File.new()
	if file.file_exists(path):
		file.open(path, file.READ)
		var buffer = file.get_buffer(file.get_len())
		var stream = AudioStreamOGGVorbis.new()
		stream.data = buffer
		var audio = get_node("AudioStreamPlayer")
		
		if audio:
			audio.stream = stream
			return audio
		else:
			push_error("ERRORE! AudioStreamPlayer non trovato")
	else:
		push_error("ERRORE! FILE INESISTENTE")
		return null



func _on_AudioStreamPlayer_finished():
	tmp = -1

Godot Version

Godot 3.5.3 LTS

Question

Would anyone know how to fix the problem

If the audio files are in the res:// folder then you don’t need to use the File API to load them, just use load(): var stream = load(path)

1 Like

Ok now it works, thank you so much for your response.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.