-
Notifications
You must be signed in to change notification settings - Fork 202
feat: enhance waveform animation, extraction flexibility and state management #424
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
base: main
Are you sure you want to change the base?
Conversation
…directly - Added `WaveformExtractionType` to choose between different waveform extraction modes (no extraction, asynchronous extraction, and synchronous extraction). - Fixed waveformData mutation issue by exposing the internal `_waveformData` list directly instead of a copy (`toList()`), enabling in-place modifications. - Updated `preparePlayer` method to integrate these changes with improved waveform extraction handling.
Implement didUpdateWidget method in _AudioFileWaveformsState to detect changes in waveformData and other important properties. This modification allows the widget to update correctly when its properties are modified without having to completely rebuild it.
…troller This commit fixes an issue where waveforms would only display in the fixed color when a controller was paused before the widget was destroyed and then recreated. The fix adds a new _initializeAudioProgress method that properly initializes the audio progress value based on the current position of a paused controller, ensuring that the waveform colors (live vs fixed) are correctly applied when the widget is recreated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will need to test this locally but from the surface this PR looks good with these changes. BTW thank you so much for your PR. This is a great improvement.
| if (widget.animationDuration != Duration.zero) { | ||
| _growingWaveController.dispose(); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please explain why you're only disposing when animation duration isn't zero?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because the controller is not instantiated over the duration is set to zero
| } | ||
| } | ||
|
|
||
| // Vérifier si d'autres propriétés importantes ont changé |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add comment in english
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I forgot.
| if (mounted) setState(() {}); | ||
| } | ||
|
|
||
| // Mettre à jour les variables si nécessaire |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here as well, add comment in english
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I forgot.
| if (waveformExtractionType != WaveformExtractionType.noExtraction) { | ||
| var extraction = waveformExtraction.extractWaveformData( | ||
| path: path, | ||
| noOfSamples: noOfSamples, | ||
| ) | ||
| .then( | ||
| (value) { | ||
| )..then((values) { | ||
| waveformExtraction.waveformData | ||
| ..clear() | ||
| ..addAll(value); | ||
| notifyListeners(); | ||
| }, | ||
| ); | ||
| ..addAll(values); | ||
| }); | ||
| if (waveformExtractionType == WaveformExtractionType.extractSync) { | ||
| await extraction; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add some comment above this to explain the logic here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've changed the verifiable shouldExtractWaveform to enum, to allow for different cases. Don't extract waveforms, extract but don't wait for extraction to finish and finally extract and wait for extraction to finish.
| /// This returns waveform data which can be used by [AudioFileWaveforms] | ||
| /// to display waveforms. | ||
| List<double> get waveformData => _waveformData.toList(); | ||
| List<double> get waveformData => _waveformData; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we don't want to allow users to modify the list but if you had any reason to remove it then can please mention it here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've changed it because this part of the code you've written isn't working properly any more.
if (shouldExtractWaveform) { waveformExtraction .extractWaveformData( path: path, noOfSamples: noOfSamples, ) .then( (value) { waveformExtraction.waveformData ..clear() ..addAll(value); notifyListeners(); }, ); }
Since you return a newly created list every time you call waveformData, what you do in the PlayerController cannot work and be made persistent.
|
What's the status of the review for the changes I proposed? |
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:
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.