abdelaziz-mahdy / flutter_meedu_videoplayer

Cross-Platform Video Player for flutter
https://abdelaziz-mahdy.github.io/flutter_meedu_videoplayer/
MIT License
132 stars 69 forks source link

Slider value position failed cause network Video Freeze #95

Closed BrunoC96 closed 1 year ago

BrunoC96 commented 1 year ago

Hi, I'm currently using flutter_video_player, but I have the same issue with a network m3u8 file's. The video player freeze after some time and I see in the error log that the slider value goes negative, and so causing other error which cause video freeze. I find out when I track the position of the video controller _currentPosition I see that is value slowly decrease, because for what I can see, buffer more frame and faster than he can actually reproduce, so the position of the slider get reposition on the new frame which tend to go negative, and after some time cause the issue.

This is my Code

`class VideoPlayer extends StatefulWidget { static const routeName = '/video_player'; //final M3u8Handler m3u8handler; final String m3u8Url; const VideoPlayer({required this.m3u8Url, Key? key}) : super(key: key); @override State createState() => _VideoPlayerState(); }

class _VideoPlayerState extends State { late M3u8Handler m3u8handler; late MeeduPlayerController _meeduPlayerController; final FocusNode focusNode = FocusNode(); Duration _currentPosition = Duration.zero;

Future _setDataSource() async { await _meeduPlayerController.setDataSource( DataSource( type: DataSourceType.network, //DataSourceType.file, source: widget.m3u8Url, ), autoplay: true, ); }

@override void initState() { super.initState(); _meeduPlayerController = MeeduPlayerController( enabledControls: const EnabledControls(doubleTapToSeek: false), loadingWidget: const Center(child: CircularProgressIndicator()), ); _meeduPlayerController.onPositionChanged.listen( (Duration position) { _currentPosition = position; // save the video position print(_currentPosition); }, ); _setDataSource(); }

@override void dispose() { _meeduPlayerController.dispose(); super.dispose(); }

@override Widget build(BuildContext context) { //final size = MediaQuery.of(context).size; final w = getw(context); final h = getw(context); //var controller = Get.put(M3u8Controller()); return Scaffold( backgroundColor: tColorBlack, //appBar: AppBar(), body: SafeArea( child: SizedBox( width: w, height: h, child: Center( child: AspectRatio( aspectRatio: 16 / 9, child: MeeduVideoPlayer(controller: _meeduPlayerController), ), ), ), ), ); } } `

The console Log

`D/EGL_emulation(29536): app_time_stats: avg=33.76ms min=8.99ms max=71.98ms count=30 I/flutter (29536): 0:00:01.625000 I/flutter (29536): 0:00:02.127000 D/EGL_emulation(29536): app_time_stats: avg=35.00ms min=13.24ms max=52.86ms count=30 I/flutter (29536): 0:00:02.621000 I/flutter (29536): 0:00:03.127000 D/EGL_emulation(29536): app_time_stats: avg=34.41ms min=14.12ms max=68.39ms count=30 I/flutter (29536): 0:00:03.622000 I/flutter (29536): 0:00:04.142000 D/EGL_emulation(29536): app_time_stats: avg=34.49ms min=10.37ms max=68.88ms count=29 I/flutter (29536): 0:00:04.641000 I/flutter (29536): 0:00:05.135000 D/EGL_emulation(29536): app_time_stats: avg=25.88ms min=4.04ms max=67.47ms count=40 D/BufferPoolAccessor2.0(29536): bufferpool2 0xb400007667b11178 : 5(10485760 size) total buffers - 4(8388608 size) used buffers - 4802/4807 (recycle/alloc) - 7/4806 (fetch/transfer) I/flutter (29536): -0:00:00.360000 I/flutter (29536): 0:00:00.141000 D/BufferPoolAccessor2.0(29536): bufferpool2 0xb400007667b190a8 : 5(40960 size) total buffers - 1(8192 size) used buffers - 9026/9031 (recycle/alloc) - 9/9030 (fetch/transfer) D/EGL_emulation(29536): app_time_stats: avg=28.33ms min=14.34ms max=66.25ms count=37 I/flutter (29536): 0:00:00.647000 I/flutter (29536): 0:00:01.143000 D/EGL_emulation(29536): app_time_stats: avg=35.71ms min=13.71ms max=56.84ms count=28 I/flutter (29536): 0:00:01.637000 I/flutter (29536): 0:00:02.152000 D/EGL_emulation(29536): app_time_stats: avg=35.02ms min=14.43ms max=85.88ms count=30 I/flutter (29536): 0:00:02.639000 I/flutter (29536): 0:00:03.144000 D/EGL_emulation(29536): app_time_stats: avg=34.42ms min=7.15ms max=77.85ms count=30 I/flutter (29536): 0:00:03.648000 I/flutter (29536): 0:00:04.147000 D/EGL_emulation(29536): app_time_stats: avg=35.73ms min=11.06ms max=57.33ms count=28 I/flutter (29536): 0:00:04.641000 D/BufferPoolAccessor2.0(29536): bufferpool2 0xb400007667b11178 : 5(10485760 size) total buffers - 1(2097152 size) used buffers - 4927/4932 (recycle/alloc) - 7/4931 (fetch/transfer) I/flutter (29536): 0:00:05.146000 D/BufferPoolAccessor2.0(29536): bufferpool2 0xb400007667b190a8 : 5(40960 size) total buffers - 1(8192 size) used buffers - 9278/9283 (recycle/alloc) - 9/9282 (fetch/transfer) D/EGL_emulation(29536): app_time_stats: avg=25.78ms min=4.07ms max=67.24ms count=40 I/flutter (29536): 0:00:05.638000 I/flutter (29536): 0:00:00.146000 D/EGL_emulation(29536): app_time_stats: avg=23.94ms min=2.65ms max=59.75ms count=37 I/flutter (29536): 0:00:00.639000 I/flutter (29536): 0:00:01.140000 I/flutter (29536): 0:00:01.637000 D/EGL_emulation(29536): app_time_stats: avg=34.00ms min=14.12ms max=66.54ms count=30 I/flutter (29536): 0:00:02.146000 I/flutter (29536): 0:00:02.644000 D/EGL_emulation(29536): app_time_stats: avg=33.77ms min=13.28ms max=51.57ms count=30 I/flutter (29536): 0:00:03.143000 I/flutter (29536): 0:00:03.647000 D/EGL_emulation(29536): app_time_stats: avg=36.54ms min=14.44ms max=63.58ms count=28 I/flutter (29536): 0:00:04.147000 D/BufferPoolAccessor2.0(29536): bufferpool2 0xb400007667b11178 : 5(10485760 size) total buffers - 1(2097152 size) used buffers - 5066/5071 (recycle/alloc) - 7/5070 (fetch/transfer) I/flutter (29536): 0:00:04.645000 D/EGL_emulation(29536): app_time_stats: avg=32.54ms min=14.01ms max=53.02ms count=31 D/BufferPoolAccessor2.0(29536): bufferpool2 0xb400007667b190a8 : 5(40960 size) total buffers - 1(8192 size) used buffers - 9526/9531 (recycle/alloc) - 9/9530 (fetch/transfer) I/flutter (29536): 0:00:05.146000 I/flutter (29536): 0:00:05.638000 D/EGL_emulation(29536): app_time_stats: avg=25.86ms min=11.78ms max=54.28ms count=39 I/flutter (29536): 0:00:00.137000 I/flutter (29536): 0:00:00.647000 D/EGL_emulation(29536): app_time_stats: avg=27.08ms min=4.73ms max=63.57ms count=37 I/flutter (29536): 0:00:01.145000 I/flutter (29536): 0:00:01.641000 D/EGL_emulation(29536): app_time_stats: avg=34.57ms min=13.90ms max=54.77ms count=29 I/flutter (29536): 0:00:02.137000 I/flutter (29536): 0:00:02.640000 D/EGL_emulation(29536): app_time_stats: avg=35.49ms min=9.19ms max=73.61ms count=29 I/flutter (29536): 0:00:03.142000 D/BufferPoolAccessor2.0(29536): bufferpool2 0xb400007667b11178 : 5(10485760 size) total buffers - 1(2097152 size) used buffers - 5195/5200 (recycle/alloc) - 7/5199 (fetch/transfer) I/flutter (29536): 0:00:03.645000 D/EGL_emulation(29536): app_time_stats: avg=34.96ms min=6.64ms max=71.51ms count=30 I/flutter (29536): 0:00:04.142000 D/BufferPoolAccessor2.0(29536): bufferpool2 0xb400007667b190a8 : 5(40960 size) total buffers - 1(8192 size) used buffers - 9779/9784 (recycle/alloc) - 9/9783 (fetch/transfer) I/flutter (29536): 0:00:04.641000 D/EGL_emulation(29536): app_time_stats: avg=29.77ms min=14.27ms max=65.64ms count=34 I/flutter (29536): 0:00:05.136000 I/flutter (29536): 0:00:05.639000 D/EGL_emulation(29536): app_time_stats: avg=28.36ms min=7.72ms max=62.15ms count=36 I/flutter (29536): -0:00:05.874000

══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════ The following assertion was thrown building RxBuilder(dirty, state: _RxBuilderState#0a472): Value -5.0 is not between minimum 0.0 and maximum 60.0 'package:flutter/src/material/slider.dart':`

I think, with some actually delay, between the buffering in relation to the current position could solve the problem.

The issue happen across all the platform except web that I don't have support for.

Thanks in advance for the response.

abdelaziz-mahdy commented 1 year ago

Can you provide the url for the m3u8 file? And does it happen on windows? I think it may be related to Playing a live stream

BrunoC96 commented 1 year ago

I can't give you the URL link of the m3u8, but I can show you, how it is laid out:

`#EXTM3U

EXT-X-TARGETDURATION:6

EXT-X-MEDIA-SEQUENCE:608459

X-IPLA-LIVE-START: 20230525T201248Z

X-IPLA-LIVE-LAST: 20230526T081752Z

X-IPLA-SEEKABLE-TO: 20230526T081706Z

X-IPLA-TIMESTAMP: 20230526T081706Z

EXTINF:6

http://live-ipla.pluscdn.pl/t12/11633/0/tv/14608/tv/f2e7cf63-9c4c-491f-8a69-f3fd3f668b44_1127427.ts

X-IPLA-TIMESTAMP: 20230526T081711Z

EXTINF:6

http://live-ipla.pluscdn.pl/t12/11633/0/tv/14608/tv/0782e745-b780-44ca-bc8e-1a4423b19c74_1127428.ts

X-IPLA-TIMESTAMP: 20230526T081716Z

EXTINF:6

http://live-ipla.pluscdn.pl/t12/11633/0/tv/14608/tv/a36ab6e0-b0a9-49aa-83f1-92906810085a_1127429.ts

X-IPLA-TIMESTAMP: 20230526T081722Z

EXTINF:6

http://live-ipla.pluscdn.pl/t12/11633/0/tv/14608/tv/a178ace4-3073-491e-9445-c29a82fab38d_1127430.ts

X-IPLA-TIMESTAMP: 20230526T081727Z

EXTINF:6

http://live-ipla.pluscdn.pl/t12/11633/0/tv/14608/tv/8903eb5a-0b99-46e6-a2d6-e58b6def58af_1127431.ts

X-IPLA-TIMESTAMP: 20230526T081732Z

EXTINF:6

http://live-ipla.pluscdn.pl/t12/11633/0/tv/14608/tv/53618321-c1b2-48cf-a59d-c6835191710f_1127432.ts

X-IPLA-TIMESTAMP: 20230526T081737Z

EXTINF:6

http://live-ipla.pluscdn.pl/t12/11633/0/tv/14608/tv/27a45b0b-8abf-4a16-9f75-51ccbcb09749_1127433.ts

X-IPLA-TIMESTAMP: 20230526T081742Z

EXTINF:6

http://live-ipla.pluscdn.pl/t12/11633/0/tv/14608/tv/0932792b-709c-4ea5-a578-2ed3603b83b5_1127434.ts

X-IPLA-TIMESTAMP: 20230526T081747Z

EXTINF:6

http://live-ipla.pluscdn.pl/t12/11633/0/tv/14608/tv/ff502c4e-aeef-4ee5-8eb1-0e8d1f4dc417_1127435.ts

X-IPLA-TIMESTAMP: 20230526T081752Z

EXTINF:6

http://live-ipla.pluscdn.pl/t12/11633/0/tv/14608/tv/d3d1877b-66cc-4fc4-b86e-ea5d5d9c57d8_1127436.ts `

They are a 10 frames divided by 6 second each.

I try on macOS, android, iPhone a fire stick, don't try already on Windows, but i can also try there.

abdelaziz-mahdy commented 1 year ago

The problem most probably that it's live and live support still has some problems

Are you using media_kit for all platforms?

The problem is weird since YouTube live works correctly.

abdelaziz-mahdy commented 1 year ago

I would like to ask a question can you test on release mode, it should not freeze (since the debugger is the one that freezes the ui on errors )

BrunoC96 commented 1 year ago

Sure, I try with release mode and check if the problem persist or not. Also in the meantime i try to find a solution for slowing down the fast download of the file.

abdelaziz-mahdy commented 1 year ago

I think I can add a condition to limit the slider range to be 0 to max only

But I would rather fix the main cause

BrunoC96 commented 1 year ago

I test it on release mode, but the problem persists.

It seems like the problem is not the value range of the slider, which also make unusable the slider. But the fact that when arrive to certain negative amount of the slide range the video freeze, because doesn't know which frame need to be rendered, and it freezes.

And if i exit the video player going back he give red screen, whit this error: Another exception was thrown: 'package:flutter/src/widgets/framework.dart': Failed assertion: line 5518 pos 14: '_dependents.isEmpty': is not true.

this message i see in debug mode, on release the app crush.

In Debug Mode, the debug continues to get new frame after also the red screen.

BrunoC96 commented 1 year ago

Also give me another exception after that, that is: Another exception was thrown: LateInitializationError: Field '_children@128042623' has not been initialized.

abdelaziz-mahdy commented 1 year ago

I guess I can't do much without knowing the url so I can test on my own

Can you provide it on discord privately?

BrunoC96 commented 1 year ago

Yes

BrunoC96 commented 1 year ago

Yes

Iperman#1035

abdelaziz-mahdy commented 1 year ago

Yes

Iperman#1035

Sent

abdelaziz-mahdy commented 1 year ago

https://pub.dev/packages/flutter_meedu_media_kit you can use this package which is the same as this one

but live support is working there since its using only media_kit, not video_player interface

BrunoC96 commented 1 year ago

https://pub.dev/packages/flutter_meedu_media_kit you can use this package which is the same as this one

but live support is working there since its using only media_kit, not video_player interface

Now works just fine.