0 votes

I am currently running Godot 3.2, using AudioStreamPlayer and VideoPlayer to play Audio and Video.

In the docs for Godot 3.1 there is a section for AudioStream where it describes a get_length() method that returns length of an audio stream in seconds.
Is there any similiar solution for AudioStreamPlayer and VideoPlayer in Godot 3.2 so that I can get the duration of those two media types?

in Engine by (17 points)

1 Answer

+1 vote
Best answer

An AudioStreamPlayer has an stream property, which is an AudioStream object. Using that object, you can access the AudioStream's get_length() method.

Likewise, a VideoStreamPlayer has a stream property, which is a VideoStream object. It also has an underlying get_length() method which can be used to retrieve the stream's length

by (12,475 points)
selected by

So it seems you're half right. AudioStream's get_length() method does indeed exist. However, firstly, VideoStreamPlayer does not exist. VideoPlayer does exists though, and it has a VideoStream but no get_length() method attached.

Thanks, it's good to have AudioStream's get_length at the very least.

So, a couple of pieces of unintentional misinformation here...

  1. Yeah, I meant VideoPlayer, not VideoStreamPlayer.
  2. When I initially looked at the VideoStream object, it looked very underdocumented and I couldn't tell if it had a get_length method or not. Just before posting that response, I looked again and saw a get_length method, so I updated the response. Obviously, that second look must have been back on my open AudioStream browser tab...

Sorry about that.

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.