[SOLVED]Problem Setting Volume Of Music: music_player.set_volume_db(MusicVolume) # Not working ?

JeZxLeeJeZxLee Posts: 67Member
edited August 1 in Audio

Hi,

We are trying to modify the volume of music playing in an AudioStreamPlayer.
Please look at below script code.
Music volume is set to 0.0 but the music is still playing in the game?
Any help would be appreciate, thanks!

Jesse
www.FallenAngelSoftware.com

# "AudioCore.gd"
extends Node


var MusicVolume
var EffectsVolume


func _ready():

    MusicVolume = 0.0
    EffectsVolume = 1.0

    var music_player = AudioStreamPlayer.new()
    music_player.stream = load("res://media/music/TitleBGM.ogg")
    add_child(music_player)
    music_player.set_volume_db(MusicVolume) # Not working ?
    music_player.play()


    pass


func _process(delta):


    pass

Best Answer

  • SIsilicon28SIsilicon28 Posts: 749
    edited July 26 Accepted Answer

    set_volume_db takes an input that's in decibels, but you are using a number between 0 and 1. In decibels, 0 means audio at full power. You need to convert the parameter first.

    music_player.set_volume_db(linear2db(Music volume))
    

Answers

  • SIsilicon28SIsilicon28 Posts: 749Moderator
    edited July 26 Accepted Answer

    set_volume_db takes an input that's in decibels, but you are using a number between 0 and 1. In decibels, 0 means audio at full power. You need to convert the parameter first.

    music_player.set_volume_db(linear2db(Music volume))
    
  • JeZxLeeJeZxLee Posts: 67Member

    Ok, thanks - that worked!

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file