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

Enhancements: Start Time Initialization and Extended Volume Range #451

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

itsSagarBro
Copy link

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

  1. 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.

  2. 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

VlcPlayer(
  controller: VlcPlayerController.network(
    'your_video_url_here',
    startAt: const Duration(seconds: 5), // Start playing the video at 5 seconds.
  ),
)

Extended Volume Range

To set the volume to 150%:

vlcController.setMaxVolume(150);

To get the current volume:

double currentVolume = vlcController.getMaxVolume();

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.

@illia-romanenko
Copy link
Collaborator

Hey @itsSagarBro , thanks for the PR - I'll try to ask somebody to review it sometime soon(-ish).

@ghost
Copy link

ghost commented Dec 5, 2023

@itsSagarBro Thank you for the PR.
I have a few comments:

  • I noticed that if the 'startAt' value is set to a value greater than the video's length, the video won't play.
  • I’m not sure if we need to change '_maxVolume' to 200 because it doesn't seem to affect the volume, which I believe was the intended purpose. This value appears to only add a number of steps.

I've also added some comments in the code, please take a look

if (maxVolume > volumeLimit) {
throw ArgumentError.value(
maxVolume,
'Max volume should be lower than 200.',
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We often use the magic number '200.' Why not use a constant instead? If we ever need to make changes, we would only have to edit it in one place, rather than in multiple locations.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not go back to the value of 100 if 200 doesn't make the video louder? And avoid using magic numbers.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Volume 200, Actually makes videos louder, I have created some OTT apps, which greatly helped me. And I will certainly fix the magic number issue.

@itsSagarBro itsSagarBro requested a review from a user December 9, 2023 18:19
@@ -233,6 +239,10 @@ class VlcPlayerController extends ValueNotifier<VlcPlayerValue> {
);
break;
case VlcMediaEventType.playing:

/// Calling start at
if (startAt != null && !_startAtSet) _setStartAt();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no need for this 'if' condition, as it is already present in the method. Call the method after setting the 'value' so that the code works.
value = value.copyWith(
...
);
_setStartAt();

if (maxVolume > volumeLimit) {
throw ArgumentError.value(
maxVolume,
'Max volume should be lower than 200.',
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not go back to the value of 100 if 200 doesn't make the video louder? And avoid using magic numbers.

@Ahtsham0715
Copy link

Unhandled Exception: Invalid argument (Start At cannot be greater than video duration.): Instance of '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

Successfully merging this pull request may close these issues.

3 participants