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

[Question] How to play video with start time? #228

Closed
hezhong0711 opened this issue Jun 8, 2023 · 11 comments · Fixed by #581
Closed

[Question] How to play video with start time? #228

hezhong0711 opened this issue Jun 8, 2023 · 11 comments · Fixed by #581
Labels
enhancement New feature or request has workaround A workaround or alternative solution is available question Further information is requested

Comments

@hezhong0711
Copy link

Is there any way to play video begin from a specific time like this command:
mpv --start=100 loadfile 'http://host/a.mp4' append

@cezres
Copy link

cezres commented Jun 9, 2023

final Future<Duration> duration = player.streams.duration.first;
await player.open(Media(file.path), play: false);
await duration;
await player.seek(targetPosition);
await player.play();

@alexmercerind alexmercerind added enhancement New feature or request question Further information is requested labels Jun 9, 2023
@alexmercerind
Copy link
Member

cc @ethicnology.

There is still not a dedicated solution; but above shall work.

@ethicnology
Copy link

I adapted my UX to solve this need.
The video starts, If the user can resume, a resuming button that trigger the player.seek is displayed for a few seconds

@PurshuRana

This comment was marked as off-topic.

@joodo
Copy link

joodo commented Jul 12, 2023

final Future<Duration> duration = player.streams.duration.first;
await player.open(Media(file.path), play: false);
await duration;
await player.seek(targetPosition);
await player.play();

this doest work always

I've tried this:

await player.stream.buffer.first;
player.seek(targetPosition);

instead of await duration;, it works well for me every time

@alexmercerind
Copy link
Member

@alexmercerind plz include this as a core abilty

We can't just publish a feature if it works for some cases. We want it to work for every case & every backend (native & web) with appropriate unit-tests.

You are free to use the solutions provided here (which hopefully work). But if the package releases something "stable" it becomes our responsibility to ensure its functioning.

@joodo
Copy link

joodo commented Jul 13, 2023

@alexmercerind plz include this as a core abilty

We can't just publish a feature if it works for some cases. We want it to work for every case & every backend (native & web) with appropriate unit-tests.

You are free to use the solutions provided here (which hopefully work). But if the package releases something "stable" it becomes our responsibility to ensure its functioning.

But I think there still should be a stable way to make sure the video is "load finished", means remote video source is available and we can freely do actions like seek. Maybe await controller.waitUntilFirstFrameRendered should do this, but it does not work with seek so far.

@ethicnology
Copy link

this needs to be a core ability because when we do it like this the ui lags behind because first it loads position at 0 and then change it

@alexmercerind plz include this as a core abilty

I recommend adding a initial time in the player.open function

@Prince-of-death Welcome to open source and free softwares where the scarce free time of developers is gifted to us

I recommend you start learning how to contribute to the codebase and implement this feature if it is so crucial for you, if not, you should work around the problem with one of the solutions offered above.

@Prince-of-death

This comment was marked as off-topic.

@alexmercerind alexmercerind added the has workaround A workaround or alternative solution is available label Oct 6, 2023
@Farg0k
Copy link

Farg0k commented Nov 9, 2023

final Future<Duration> duration = player.streams.duration.first;
await player.open(Media(file.path), play: false);
await duration;
await player.seek(targetPosition);
await player.play();

I don't know if it worked before, but now (media_kit: ^1.1.10, media_kit_video: ^1.2.4, media_kit_libs_video: ^1.0.4) it doesn't work.
Because player.streams.duration.first; is always zero before the stream is loaded. And await player.stream.buffer.first; it is also always zero before the stream is loaded

For me, this solution worked

 await player.open(Media(file.path), play: false);
      controller.player.stream.duration.listen((event) async {
        if (event.inSeconds > 0){
          await player.seek(const Duration(seconds: targetPosition));
          await player.play();
        }
      });

@alexmercerind
Copy link
Member

I did implement this in the latest PR:

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request has workaround A workaround or alternative solution is available question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants