Open colbort opened 3 years ago
flutter环境
下面是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; }, ); } }
Any updates?
flutter环境
下面是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;
}
@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();
}
@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; }, ); } }