befovy / fijkplayer

ijkplayer for flutter. ijkplayer 的 flutter 封装。 Flutter video/audio player. Flutter media player plugin for android/iOS based on ijkplayer. fijkplayer 是基于 ijkplayer 封装的 flutter 媒体播放器,开箱即用,无需编译 ijkplayer
https://fijkplayer.befovy.com
MIT License
1.65k stars 351 forks source link

[BUG] 6002 ANR_EXCEPTION com.befovy.fijkplayer.FijkPlayer.release(FijkPlayer.java:165) #445

Open colbort opened 3 years ago

colbort commented 3 years ago

image image image image image

flutter环境 image

下面是flutter代码

class _VideoTdetailsState extends State { VideoProvider video = VideoProvider(); FijkPlayer player = FijkPlayer();

late VideoData resp; StreamSubscription? onBufferPercentUpdate; StreamSubscription? onBufferPosUpdate; StreamSubscription? onBufferStateUpdate; StreamSubscription? onCurrentPosUpdate;

/// 滑动条 ValueNotifier sliderValue = ValueNotifier(0);

/// 状态监听 ValueChanged? valueChanged;

void _fijkValueListener() { print('打印视频的状态 --- ${player.value.state}'); print( '打印视频的状态 --- ${player.value.duration} ${player.value.duration.inSeconds}'); // player.value.duration valueChanged?.call(player.value.state); onBufferPercentUpdate = player.onBufferPercentUpdate.listen((event) { print('缓存通知 --- > $event'); }); // onBufferPosUpdate = player.onBufferPosUpdate.listen((event) { // print('缓存位置 --- > $event'); // }); onBufferStateUpdate = player.onBufferStateUpdate.listen((event) { if (event) { print('加载 小于 100 --- > $event'); } else { print('加载 大于 100 $event'); } }); onCurrentPosUpdate = player.onCurrentPosUpdate.listen((event) { sliderValue.value = event.inMilliseconds / player.value.duration.inMilliseconds;

  print('当前播放位置 --- >   ${event.inSeconds} ');
});

}

@override void initState() { super.initState(); resp = widget.buildArg['videoTdetails']; setOption(); }

setOption() async { await player.setOption(FijkOption.playerCategory, 'min-frames', 2); await player.setOption(FijkOption.playerCategory, 'framedrop', 5); await player.setOption(FijkOption.playerCategory, 'max-cached-duration', 3); await player.setDataSource(resp.videoUrl, autoPlay: true); player.addListener(_fijkValueListener); }

@override void dispose() { onBufferPercentUpdate?.cancel();

onBufferPosUpdate?.cancel();
onBufferStateUpdate?.cancel();
onCurrentPosUpdate?.cancel();
player.release();
player.removeListener(_fijkValueListener);
video.dispose();
super.dispose();

}

@override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( leading: Container( //color: Colors.red, child: TextButton( onPressed: () { NavigatorUtils.goBack(context); }, style: ButtonStyle( padding: MaterialStateProperty.all(EdgeInsets.zero)), child: Container( width: ds.d7, height: ds.d12, child: LoadImage(R.iconReturn), ), ), ), leadingWidth: ds.d30, title: Text( '${resp.title}', style: textBold17.copyWith(color: Colours.text_tdetails), ), // centerTitle: false, ), backgroundColor: Colors.black, body: Container( child: Center( child: Container( // height: 300, width: double.maxFinite, color: Colors.white, child: Center( child: FijkView( color: Colors.black, player: player, panelBuilder: buildPanel, ), ), ), ), ), ); }

Widget buildPanel(FijkPlayer fijkPlayer, FijkData fijkData, BuildContext context, Size size, Rect rect) { return BuildPanel( player: fijkPlayer, sliderValue: sliderValue, valueChangedfun: (callbackfunc) { valueChanged = callbackfunc; }, ); } }

liqiyin commented 2 years ago

Any updates?