Feature Request: provide length information of the sound
Opened this issue · 1 comments
tmdag commented
I am adding my own sounds from sounds I have purchased online. Would be great to be aware how long are sounds.
Currently I did a small work around:
sound.py:
def _load_duration(self):
# Create a GStreamer pipeline to load the file and retrieve duration
player = Gst.ElementFactory.make("playbin", "player")
player.set_property("uri", self.uri if self.uri.startswith("file://") else f"file://{self.uri}")
player.set_state(Gst.State.PAUSED)
Gst.Element.get_state(player, Gst.CLOCK_TIME_NONE) # Force pipeline to preroll and get duration
self.duration = player.query_duration(Gst.Format.TIME)[1] // Gst.SECOND
player.set_state(Gst.State.NULL) # Stop the player
window.py:
def _create_sound_item(self, sound):
[...]
if isinstance(sound, Sound):
# Set tooltip with duration
formatted_duration = self.format_duration(sound.duration)
item.set_tooltip_text(f"Sound Duration: {formatted_duration}")
rafaelmardojai commented
It should be possible to get the duration from the Player
object.
def _create_sound_item(self, sound):
...
if isinstance(sound, Sound):
# Set tooltip with duration
formatted_duration = self.format_duration(sound.player.props.duration)
item.set_tooltip_text(f"Sound Duration: {formatted_duration}")