Get length of Audio/Video (Media) in seconds?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By mrwappa

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?

:bust_in_silhouette: Reply From: jgodfrey

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

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.

mrwappa | 2020-04-08 19:34

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.

jgodfrey | 2020-04-08 22:21