Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AudioStreamPlayer doesn't seek() if set_stream() is used unless seeking after play() #53449

Open
elvisish opened this issue Oct 5, 2021 · 2 comments

Comments

@elvisish
Copy link

elvisish commented Oct 5, 2021

Godot version

3.3.3 stable

System information

Windows 7 64-bit

Issue description

When using AudioStreamPlayer and setting the stream playback in code, you must use play() to begin playing the file before you seek to a position, or else you'll always play at the beginning. If you set the stream in the AudioStreamPlayer inspector, you may seek() before using play() and it'll work fine.

Steps to reproduce

onready var audiostream = $AudioStreamPlayer
var filelong
export (AudioStreamOGGVorbis) var soundfile

func _ready():
	var rng = RandomNumberGenerator.new()
	rng.randomize()
	audiostream.set_stream(soundfile)
	filelong = soundfile.get_length()
	audiostream.seek(rng.randf_range(0, filelong))
	audiostream.play()
	print(audiostream.get_playback_position())

This will print 0 every time, however:

	audiostream.play()
	audiostream.seek(rng.randf_range(0, filelong))
	print(audiostream.get_playback_position())

This will print the playback position at a random time.

Minimal reproduction project

No response

@Calinou
Copy link
Member

Calinou commented Oct 5, 2021

See also #48982.

PS: GitHub supports gdscript syntax highlighting for code blocks. I edited your post accordingly 🙂

@Klowner
Copy link
Contributor

Klowner commented Oct 8, 2021

Looks like you can pass the seek position as an optional argument to play(pos), eg:

audiostream.play(rng.randf_range(0, filelong))

Maybe add adding a note to the documentation for seek() might be helpful, or emitting a warning when seek() is called on a stopped audio stream?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants