0 votes

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
in Engine by (19 points)

1 Answer

0 votes

I had the opposite problem with a previous version of godot, maybe it can help...
Link to question

by (895 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.