-
Notifications
You must be signed in to change notification settings - Fork 283
Enhancements: Start Time Initialization and Extended Volume Range #451
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: master
Are you sure you want to change the base?
Conversation
Hey @itsSagarBro , thanks for the PR - I'll try to ask somebody to review it sometime soon(-ish). |
@itsSagarBro Thank you for the PR.
I've also added some comments in the code, please take a look |
Unhandled Exception: Invalid argument (Start At cannot be greater than video duration.): Instance of 'Duration'. |
/gemini review |
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.
Code Review
This pull request introduces valuable enhancements: start time initialization and an extended volume range up to 200%. The changes are generally well-implemented and clearly described.
The addition of startAt
provides useful flexibility for video playback, and the extended volume control is a good feature for users needing audio amplification.
I have one suggestion regarding the _setStartAt
method to improve its robustness, particularly when video duration might initially be reported as zero. The rest of the changes look good.
Summary of Findings
- Robustness of
_setStartAt
duration check: The_setStartAt
method's check againstvalue.duration
might prematurely throw an error if the video duration is initiallyDuration.zero
whilestartAt
is positive. This could prevent thestartAt
feature from working reliably in scenarios where duration information is delayed. A suggestion was made to allow seeking if the duration is unknown, making the check conditional onvalue.duration > Duration.zero
. - Redundant null-check in
_setStartAt
: In_setStartAt
, thestartAt
variable is assigned using?? Duration.zero
after a preceding check already ensures it's non-null. UsingstartAt!
would be slightly cleaner. (This was noted but not created as a separate comment due to review severity settings, but included in the body of the main comment for this section).
Merge Readiness
The pull request introduces significant and useful features: start time initialization and extended volume range. The implementation is largely solid and well-documented.
One medium-severity issue has been identified in the _setStartAt
method concerning its behavior when video duration is initially reported as zero. It's recommended to address this to ensure the startAt
feature is robust across different scenarios, especially for content where duration might not be immediately available.
Once this point is considered and addressed, the PR should be in excellent shape for merging. As an AI, I am not authorized to approve pull requests; please ensure further review and approval by authorized team members before merging.
final Duration startAtDuration = startAt ?? Duration.zero; | ||
|
||
// Checking if startAt is greatet then video's duration then throw error. | ||
if (startAtDuration.inMilliseconds > value.duration.inMilliseconds) { | ||
throw ArgumentError.value( | ||
startAtDuration, | ||
'Start At cannot be greater than video duration.', | ||
); |
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.
There are a couple of points regarding the _setStartAt
method logic here:
-
Nullable
startAt
Assignment (Minor): On line 358,startAtDuration
is assigned usingstartAt ?? Duration.zero
. However, the check on line 356 (if (startAt == null || _startAtSet) return;
) ensures thatstartAt
(which refers tothis.startAt
from the constructor) is not null if the function proceeds to this point. UsingstartAt!
would be more direct and reflect this guarantee:final Duration startAtDuration = startAt!;
. -
Duration Check Robustness (Main Point): The check on lines 361-365 (
if (startAtDuration.inMilliseconds > value.duration.inMilliseconds)
) will throw anArgumentError
. This is problematic ifvalue.duration
isDuration.zero
(e.g., for live streams, or if duration metadata isn't immediately available when theplaying
event fires) whilestartAtDuration
is positive. This could unnecessarily prevent thestartAt
feature from working in these scenarios.To make this more robust, consider only throwing the error if
value.duration
is known (i.e., non-zero) andstartAtDuration
exceeds it. Ifvalue.duration
is zero, it might be better to proceed with theseekTo
call and let the underlying player handle the seek attempt. This would allowstartAt
to function even if the duration is temporarily unknown.Here's a suggested modification incorporating both points:
// In _setStartAt() final Duration startAtDuration = startAt!; // Point 1 addressed // Only perform the check if the video's duration is known (greater than zero) if (value.duration > Duration.zero && startAtDuration.inMilliseconds > value.duration.inMilliseconds) { throw ArgumentError.value( startAtDuration, 'Start At cannot be greater than video duration.', ); } // ... rest of the method ...
This change allows the seek to be attempted if the duration is initially unknown, potentially improving the reliability of the
startAt
feature.
final Duration startAtDuration = startAt!;
// Checking if startAt is greatet then video's duration then throw error.
// Only throw if duration is known (non-zero) and startAt exceeds it.
if (value.duration > Duration.zero &&
startAtDuration.inMilliseconds > value.duration.inMilliseconds) {
throw ArgumentError.value(
startAtDuration,
'Start At cannot be greater than video duration.',
);
}
Pull Request Description
Summary
This pull request introduces several enhancements to the Flutter VLC Player, including the ability to specify a start time when initializing a video and the option to set and get the maximum volume up to 200%. These improvements enhance the player's functionality and provide more flexibility for developers working with video playback in Flutter applications.
Changes Made
Start Time Initialization: Added the
startAt
parameter to the player's initialization, allowing developers to specify a start time in duration when opening a video or setting media. This enables users to jump to a specific point in the video when it starts playing.Extended Volume Range: Enhanced the volume control by allowing volumes up to 200% (2x). This added flexibility in volume control can be useful for scenarios where users want to amplify audio beyond the standard 100% volume.
How to Use the New Features
Start Time Initialization
Extended Volume Range
To set the volume to 150%:
To get the current volume:
Testing
I have thoroughly tested these changes by creating unit tests and running sample Flutter applications to ensure that the new features work as expected. No regressions were identified during testing.