audio_waveforms icon indicating copy to clipboard operation
audio_waveforms copied to clipboard

feat: enhance waveform animation, extraction flexibility and state management

Open benco8186 opened this issue 1 year ago • 2 comments

This pull request introduces key improvements to both waveform animation behavior, waveform extraction configuration, and state management in AudioFileWaveforms:

🎨 Animation Behavior

  • Made grow animation conditional The waveform grow animation is now disabled if animationDuration is set to Duration.zero. This allows fully static rendering when animations are not desired.

  • Improved documentation Updated the comment for animationDuration to clearly state that Duration.zero disables animations.

⚙️ Waveform Extraction Flexibility

  • Introduced WaveformExtractionType enum Enables developers to choose from:

    • none: disable waveform extraction completely.
    • async: extract waveform data asynchronously.
    • sync: extract waveform data immediately during preparePlayer.
  • Exposed internal waveformData list Removed the .toList() wrapping to allow direct, in-place modification of _waveformData, which is useful for dynamic updates or streaming use cases.

  • Updated preparePlayer Modified the player setup logic to respect the new extraction mode and ensure correct handling of waveform data.

🔄 State Management Improvements

  • Added didUpdateWidget implementation Implemented the didUpdateWidget method to properly detect and handle changes in widget properties, particularly waveformData. This ensures the widget updates correctly when its properties change without requiring a complete rebuild.

  • Enhanced property change detection Added checks for other important properties (playerWaveStyle, size, waveformType) that require a UI refresh when changed.

  • Improved UI variable updates Added update logic for UI-related variables (margin, padding, decoration, etc.) to ensure consistent rendering when these properties change.

  • Fixed waveform color restoration Added a mechanism to properly initialize audio progress when recreating a widget with a paused controller, ensuring that waveform colors (live vs fixed) are correctly applied. This fixes an issue where waveforms would display only in the fixed color when a controller was paused before widget destruction and recreation.

These changes improve performance, customization, control, and reactivity for developers working with audio waveform rendering in Flutter.

benco8186 avatar Apr 30 '25 16:04 benco8186

What's the status of the review for the changes I proposed?

benco8186 avatar Jun 17 '25 17:06 benco8186

Hi @benco8186, thanks for the PR and for your patience on the review.

I went through the changes in detail. The direction is useful, but a few things need addressing before this can move forward:

  • Needs a rebase - The branch is currently conflicting with main. Could you rebase on the latest main and resolve the conflicts?

  • Breaking change to preparePlayer - Replacing shouldExtractWaveform with waveformExtractionType is a breaking API change, and the default also flips from extracting to noExtraction — so existing callers relying on the default will silently stop getting waveforms, and anyone passing shouldExtractWaveform: won't compile. If we go this route, it needs a CHANGELOG entry, a README/dartdoc update (the dartdoc still refers to shouldExtractWaveform), and a note in the PR description calling out the break.

  • A couple of correctness issues - I've left inline comments on them.

  • Open review comments - Some earlier comments are still not fixed. Could you look into them?

  • Scope - This bundles three separate enhancements plus an unrelated iOS extraction fix. It would be easier to review and land if the iOS fix (and ideally each concern) were split out. Heads-up too that it overlaps with a few open PRs on player_controller.dart, so whichever lands first, the others will need to reconcile.

Thanks again for the contribution.

lavigarg-simform avatar Jun 29 '26 09:06 lavigarg-simform