Hello,
I want to play sound on all scenes and define singleton class. In my class there is dynamically instanced AudioStreamPlayer object. But the sound doesn't play on Android devices. There is no problem on iOS devices. I attached my code snippet to below. Can you suggest any idea?
Thank you.
extends Node
var music_player
func _ready():
var music_file = "res://Sounds/BackgroundSound.ogg"
var stream = AudioStream.new()
music_player = AudioStreamPlayer.new()
if File.new().file_exists(music_file):
var music = load(music_file)
music_player.stream = music
music_player.play()
add_child(music_player)
music_player.bus = "MusicBus"
var bus_idx = AudioServer.get_bus_index("MusicBus")
AudioServer.set_bus_mute(bus_idx, true)
pass
func music_play_or_stop():
var bus_idx = AudioServer.get_bus_index("MusicBus")
AudioServer.set_bus_mute(bus_idx, !UserInfo.music_on)
pass
func sounds_play_or_stop():
var bus_idx = AudioServer.get_bus_index("SoundBus")
AudioServer.set_bus_mute(bus_idx, !UserInfo.sound_on)
pass