0 votes

I have a project with a background audiostream playing, & I would like to add the feature where a player can pause the music & then start it back up at the point it was paused (not from the beginning).
How would I do that?
I have tried selecting stream paused in the Inspector, but all that does is stop the music from playing at all.
I would like to have it where a player can tap a button on the computer keyboard to pause the music.
Can someone show me how that is to be done - please step by step as I am new to Godot?
Thank you.

Godot version 3.2.3 - latest stable version
in Engine by (16 points)

1 Answer

+1 vote

Hi, again!

First, selecting the "Stream Paused" option in the inspector will stop the music because... well, the stream is paused. The values in the inspector are the initial values for the node and will not change.

Anyway, I'll just go through this step by step.

  1. Click on "Project", "Project Settings", and then "Input Map". Add a new action by typing in a name (like "pause") and clicking the "Add" button.

  2. Click the "+" next to the action and then select the option that you want to correspond to the action. Since you want the player to hit a key on their keyboard, select "Key" and hit the key on the keyboard that you choose. Click "OK".

  3. In the scene docker, click on your AudioStreamPlayer. Press the scroll with the green plus sign to add a script to the player.

  4. Replace the auto-created script with this:

-

extends AudioStreamPlayer

func _input(event):
    if event.is_action_pressed("pause"):
        stream_paused = !stream_paused

That's all the steps! You do not have to follow these steps exactly, and I encourage you to look up more information about the nodes you're using so that you can understand this better. If you need more help, I can send you an example project.

by (8,546 points)
edited by

Hello,
I copied & pasted the code you put in the email, & I tried manipulating it every which way, but it wouldn't work.
I finally just copied & pasted the code you have here & it worked perfectly.
Thanks for the help.

Yeah sorry I edited the comment afterwards

Thank you exuin, It worked for me.

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.