alexmercerind / dart_vlc

Flutter bindings to libVLC.
GNU Lesser General Public License v2.1
510 stars 136 forks source link

Player: Add a new option to the open method #126

Closed DomingoMG closed 3 years ago

DomingoMG commented 3 years ago

It would be interesting to incorporate a variable called start at.

player.open(
  Media.file(File('C:/music0.mp3')),
  autoStart: true, // default,
  startAt: Duration(minutes: 1, seconds: 30) // optional
);
jnschulze commented 3 years ago

What’s wrong with using a timer?

alexmercerind commented 3 years ago

This is really beyond the scope of project. You can yourself handle this within dart. Our wrapper is already a good high-level abstraction upon libVLC API.

DomingoMG commented 3 years ago

Using the existing methods does not allow me to fast-forward the audio without playing it back. I feel compelled to play the music to use player.seek (Duration ()); From my point of view, using a timer does not seem correct, I am just trying to provide new tools that various users would need.

It does not work to fast-forward the audio without actually playing it.

  Player player = Player(id: 1);
  @override
  void initState() {
    player.open( 
      Media.file(File('C:\\audios\\Pop\\music1.mp3')),
      autoStart: false
    );
    player.seek(Duration(seconds: 30));
    super.initState();
  }
jnschulze commented 3 years ago

Sry, I didn’t get it yet. You want to open a file, seek to a certain position without playing it and once you invoke play, it should play from the previously seeked position?

DomingoMG commented 3 years ago

@jnschulze Exactly.

jnschulze commented 3 years ago

And what happens upon invoking play then? Does it play from the beginning?

DomingoMG commented 3 years ago

@jnschulze After instantiating the open and seek () play is not working.

jnschulze commented 3 years ago

@DomingoMG I was able to reproduce this and have the same issue. It only works when adding a small delay after opening the video and before invoking seek. Probably because the player API pretends that it's synchronous, however, this doesn't mean that VLC has completed an internal operation when a Player method like seek, pause etc. returns.

So you'll need to wait for a media item to be loaded before seeking.

@alexmercerind, I guess we should expose libvlc_MediaPlayerBuffering to the dart side.

alexmercerind commented 3 years ago

@DomingoMG so, I have added this to Media itself. Since, thats how libVLC API also has it. @zezo357 you might be also interested in the same.

// Clip the media.
Media media2 = Media.network(
  'https://www.example.com/music.aac',
  startTime: Duration(seconds: 20), // Start media from 20 seconds from the beginning.
  stopTime: Duration(seconds: 60), // End media at 60 seconds from the beginning. 
);

Another change is that minimum required Flutter version is now 2.2. However, latest texture update for Linux will only work on master channel as of now.

abdelaziz-mahdy commented 3 years ago

@DomingoMG so, I have added this to Media itself. Since, thats how libVLC API also has it. @zezo357 you might be also interested in the same.

// Clip the media.
Media media2 = Media.network(
  'https://www.example.com/music.aac',
  startTime: Duration(seconds: 20), // Start media from 20 seconds from the beginning.
  stopTime: Duration(seconds: 60), // End media at 60 seconds from the beginning. 
);

Another change is that minimum required Flutter version is now 2.2. However, latest texture update for Linux will only work on master channel as of now.

Does the video player works If seek is called before it's loaded?

In my case the code checks the database to seek to the last watched time when the video is loading to make it faster since the video loading and database checking takes some time

For my fix When seek is called and duration is zero in seconds

I made a timer that will check each 500 millisecond that the video duration is not zero if it's not zero will seek and cancel the timer

That works well in my case I hope it can help

abdelaziz-mahdy commented 3 years ago

my code

if(duration.value.inSeconds!=0){
  _videoPlayerControllerWindows?.seek(position);
  }else {
  _timerForSeek?.cancel();
  _timerForSeek =Timer.periodic(Duration(milliseconds: 500), (Timer t) async {
  if (duration.value.inSeconds != 0) {
  _videoPlayerControllerWindows?.seek(position);
  t.cancel();
  _timerForSeek = null;
  }
  });
  }
alexmercerind commented 3 years ago

@DomingoMG so, I have added this to Media itself. Since, thats how libVLC API also has it. @zezo357 you might be also interested in the same.

// Clip the media.
Media media2 = Media.network(
  'https://www.example.com/music.aac',
  startTime: Duration(seconds: 20), // Start media from 20 seconds from the beginning.
  stopTime: Duration(seconds: 60), // End media at 60 seconds from the beginning. 
);

Another change is that minimum required Flutter version is now 2.2. However, latest texture update for Linux will only work on master channel as of now.

Does the video player works If seek is called before it's loaded?

In my case the code checks the database to seek to the last watched time when the video is loading to make it faster since the video loading and database checking takes some time

For my fix When seek is called and duration is zero in seconds

I made a timer that will check each 500 millisecond that the video duration is not zero if it's not zero will seek and cancel the timer

That works well in my case I hope it can help

@zezo357 , for resuming your Media from the last watched time, you should pass the startTime when creating the Media. You cannot unfortunately seek before playing the Media & that's a constraint of how libVLC API is made. I tried to add seek call after isPlaying event in libVLC++, but it didn't work either. So, these :start-time & :stop-time arguments are something that are part of libVLC itself & work well (and officially supported).

abdelaziz-mahdy commented 3 years ago

@DomingoMG so, I have added this to Media itself. Since, thats how libVLC API also has it. @zezo357 you might be also interested in the same.

// Clip the media.
Media media2 = Media.network(
  'https://www.example.com/music.aac',
  startTime: Duration(seconds: 20), // Start media from 20 seconds from the beginning.
  stopTime: Duration(seconds: 60), // End media at 60 seconds from the beginning. 
);

Another change is that minimum required Flutter version is now 2.2. However, latest texture update for Linux will only work on master channel as of now.

Does the video player works If seek is called before it's loaded?

In my case the code checks the database to seek to the last watched time when the video is loading to make it faster since the video loading and database checking takes some time

For my fix When seek is called and duration is zero in seconds

I made a timer that will check each 500 millisecond that the video duration is not zero if it's not zero will seek and cancel the timer

That works well in my case I hope it can help

@zezo357 , for resuming your Media from the last watched time, you should pass the startTime.

But that will require me to check database before running the open function which will increase the time of waiting for the user watching

abdelaziz-mahdy commented 3 years ago

For me the timer solution is good enough I just wanted to share it if anyone wanted it

alexmercerind commented 3 years ago

For me the timer solution is good enough I just wanted to share it if anyone wanted it

It's fine. However, event polling isn't the best option that I can include "officially" within the plugin. I don't know how it is any better compared to startTime.

abdelaziz-mahdy commented 3 years ago

For me the timer solution is good enough I just wanted to share it if anyone wanted it

It's fine. However, event polling isn't the best option that I can include "officially" within the plugin. I don't know how it is any better compared to startTime.

Will test it,Since you know better

Thanks for your work, sorry for taking your time

abdelaziz-mahdy commented 3 years ago

@alexmercerind I tested the start time

but sometimes the video player gets black screen while sound and position works and sometimes the old bug happens that the video doesn't load

I cant find the cause of the problem sadly

trapeye commented 2 years ago

@zezo357 I'm using CarouselSlider when it slide.. it go black screen.. but i hear sound

abdelaziz-mahdy commented 2 years ago

@zezo357 I'm using CarouselSlider when it slide.. it go black screen.. but i hear sound

For me it was black screen and no sound

So I did use my timer code and it never happened again for me.