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

Feature Request: provide length information of the sound #344

Open
tmdag opened this issue Apr 18, 2024 · 1 comment
Open

Feature Request: provide length information of the sound #344

tmdag opened this issue Apr 18, 2024 · 1 comment

Comments

@tmdag
Copy link

tmdag commented Apr 18, 2024

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
Copy link
Owner

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}")

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

No branches or pull requests

2 participants