alexmercerind / dart_vlc

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

Feature request: Ability to set state frequency #153

Closed jonasborggren closed 3 years ago

jonasborggren commented 3 years ago

The positionStream is updated a bit slow. It would be great if the frequency could be changed! Listening to the positionStream shows it updates maybe every ~250ms!

AudioManager.player.positionStream.listen((positionState) {
  onCurrentPositionTimerUpdated(positionState);
});

Starting a timer separately to get the current position has the same result. Example:

if (playbackState.isPlaying) {
  currentPositionTimer = Timer.periodic(Duration(milliseconds: 5), (timer) {
    onCurrentPositionTimerUpdated(AudioManager.player.position);
  });
} else {
  currentPositionTimer?.cancel();
}

Printing DateTime.now() every update gives this result:

flutter: 2021-09-11 03:09:33.074898
flutter: 2021-09-11 03:09:33.325125
flutter: 2021-09-11 03:09:33.575353
flutter: 2021-09-11 03:09:33.875625
alexmercerind commented 3 years ago

This is completely normal. What do you mean? ~250 ms is normal. I have used C++/WinRT MediaPlayer, HTML5 video timeupdate event... All send position updates in similar intervals. If you feel, VLC is more capable & you know some CLI flag, we have already given a way to do it.

jonasborggren commented 3 years ago

Please explain further. If this functionality is available I'd love to use it. I'm not super familiar with CLI flags 🤔 What I mean by "a bit slow" is that ~250ms is in my case too slow! I'm looking for a smooth update of the UI element showing the progress. Thanks

YeungKC commented 3 years ago

If we play music or videos for a long time, 250 millisecond delays can be accepted, but I need to play a 2-second audio message, I hope there is a shorter delay.

YeungKC commented 3 years ago

@alexmercerind

Sometimes PositionState.position is 0, is this relationship with delay?

alexmercerind commented 3 years ago

@YeungKC

If we play music or videos for a long time, 250 millisecond delays can be accepted, but I need to play a 2-second audio message, I hope there is a shorter delay.

The bar will move accordingly. Tell me an app or any other Flutter plugin which makes callback every millisecond or so. Its very expensive to make callbacks to DartVM.

Think it like this, a chunk of file is read from internet or filesystem, it is then decoded into PCM audio & raw frame, then it is sent to be played. And, in the middle of this the position callback is made by libVLC. And, its completely normal, even ExoPlayer does the same.

jonasborggren commented 3 years ago

The bar will move accordingly. Tell me an app or any other Flutter plugin which makes callback every millisecond or so. Its very expensive to make callbacks to DartVM.

Ive tried many other recommended audio flutter libraries and they all call their listeners with less than 25ms between. This one is alone doing it this way.

Let the developer decide what is best for them, please.

jonasborggren commented 3 years ago

The bar will move accordingly

No it won’t. play any audio files less than 0.5s and the listener barely gets called once.