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?

asked Apr 8 in Engine by mrwappa (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

answered Apr 8 by jgodfrey (5,742 points)
selected Apr 11 by mrwappa

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.