0 votes

Hello, I want to pause my sound when on pause menu. I couldn't get "get_tree().paused = true" to pause my sounds, so this is what I tried :

in the pause function :

var pauseposition = get_node("myStreamPlayer2D").get_playback_position();
get_node("myStreamPlayer2D").playing = false;

in the resume function :

get_node("myStreamPlayer2D").playing = true;

This resume function always restarts my sound at the beginning.
How should the seek() function be used ?

thanks !

in Engine by (245 points)

1 Answer

+2 votes
Best answer

Also : You can use $myStreamPlayer2D rather than get_node("myStreamPlayer2D")

by (178 points)
selected by

no, it's not working.

It stops and restarts the sound instead of resuming it where it has paused...

do $myStreamPlayer2D.play()
then create a var temp = $myStreamPlayer2D.getplaybackposition( )
then $myStreamPlayer2D.stop()
then $myStreamPlayer2D.play()
then $myStreamPlayer2D.advance(temp)

thanks it's working now ! Except the "advance" command doesn't exist, I used "seek":


var temp = $myStreamPlayer2D.get_playback_position( )


In my case (Godot version v3.2.2.stable.official) it doesn't work with seek(). Actually seek() is no required. The following is enough:

# Pressing F3 will toggle music
if Input.is_action_just_pressed("ui_f3"):
   music_position = $AudioStreamPlayer2D.get_playback_position()

music_position - is a global variable, declared as:

# audio position for pause and resume
var music_position = 0
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 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 webmaster@godotengine.org with your username.