From 5df3f1bbe010828ac998464dd64291c599b3d23d Mon Sep 17 00:00:00 2001 From: w-R <953969641@qq.com> Date: Mon, 25 Oct 2021 11:14:33 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A4=BE=E7=BE=A4=E6=9B=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/community/community_child_page.dart | 4 +- lib/community/community_details.dart | 4 +- .../community_view/community_dynamic.dart | 76 +++++++++++++++++-- lib/mine/release_page.dart | 4 +- 4 files changed, 78 insertions(+), 10 deletions(-) diff --git a/lib/community/community_child_page.dart b/lib/community/community_child_page.dart index 31d832ec..00152673 100644 --- a/lib/community/community_child_page.dart +++ b/lib/community/community_child_page.dart @@ -100,7 +100,9 @@ class _CommunityChildPage extends State { physics: NeverScrollableScrollPhysics(), itemBuilder: (context, position) { return InkWell( - child: CommunityDynamic(comments[position],0), + child: CommunityDynamic(comments[position],0,exitFull: (){setState(() { + + });},), onTap: () { Navigator.of(context).pushNamed( '/router/community_details', diff --git a/lib/community/community_details.dart b/lib/community/community_details.dart index fb99eef5..d657e54b 100644 --- a/lib/community/community_details.dart +++ b/lib/community/community_details.dart @@ -142,7 +142,9 @@ class _CommunityDetails extends State ), color: Colors.white, child: CommunityDynamic( - comunity,0, + comunity,0,exitFull: (){setState(() { + + });}, itemCount: 3, isDetails: true, heightFun: (height) { diff --git a/lib/community/community_view/community_dynamic.dart b/lib/community/community_view/community_dynamic.dart index 0c7e9c06..bfca430e 100644 --- a/lib/community/community_view/community_dynamic.dart +++ b/lib/community/community_view/community_dynamic.dart @@ -1,8 +1,10 @@ +import 'package:chewie/chewie.dart'; import 'package:dio/dio.dart'; import 'package:flutter/material.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:huixiang/retrofit/data/base_data.dart'; import 'package:huixiang/retrofit/data/comunity_comment.dart'; +import 'package:chewie/src/chewie_progress_colors.dart' as chewie; import 'package:huixiang/retrofit/retrofit_api.dart'; import 'package:huixiang/utils/font_weight.dart'; import 'package:huixiang/view_widget/border_text.dart'; @@ -11,6 +13,7 @@ import 'package:huixiang/view_widget/icon_text.dart'; import 'package:huixiang/view_widget/round_button.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:shared_preferences/shared_preferences.dart'; +import 'package:video_player/video_player.dart'; class CommunityDynamic extends StatefulWidget { final int itemCount; @@ -18,6 +21,7 @@ class CommunityDynamic extends StatefulWidget { final bool isDetails; final int commentType; final Function removalDynamic; + final Function exitFull; final ComunityComment comment; @@ -29,6 +33,7 @@ class CommunityDynamic extends StatefulWidget { this.heightFun, this.isDetails = false, this.removalDynamic, + this.exitFull }) : super(key: key); @override @@ -291,13 +296,11 @@ class _CommunityDynamic extends State { ); } } else if (subjectInfo.type == "video" && - subjectInfo.video != null && - subjectInfo.video != "") { - widget = Container( - width: MediaQuery.of(context).size.width - 32, - height: MediaQuery.of(context).size.width /2, - color: Colors.blue.withAlpha(123), - ); + subjectInfo.video.isNotEmpty) { + widget = videoWidget( + MediaQuery.of(context).size.width - 32, + MediaQuery.of(context).size.width /2, + subjectInfo.video); } return Column( @@ -313,6 +316,65 @@ class _CommunityDynamic extends State { ); } + VideoPlayerController videoPlayerController; + ChewieController chewieAudioController; + Chewie chewies; + + Widget videoWidget(double width, double height, src) { + print("src : $src"); + chewieAudioController = ChewieController( + videoPlayerController: videoPlayerController = + VideoPlayerController.network( + src, + ), + aspectRatio: width / height, + //宽高比 + autoPlay: false, + //自动播放 + looping: false, + //循环播放 + allowFullScreen: true, + // systemOverlaysAfterFullScreen: [], + // systemOverlaysOnEnterFullScreen: [], + // deviceOrientationsAfterFullScreen: [], + // deviceOrientationsOnEnterFullScreen: [], + // 拖动条样式颜色 + materialProgressColors: chewie.ChewieProgressColors( + playedColor: Colors.white, + handleColor: Colors.white, + backgroundColor: Colors.grey, + bufferedColor: Colors.transparent, + ), + autoInitialize: true, + ); + + chewieAudioController.addListener(_fullScreenListener); + + return MediaQuery( + data: MediaQuery.of(context).copyWith( + textScaleFactor: 0.9, + ), + child: Container( + width: MediaQuery.of(context).size.width - 17, + height: (MediaQuery.of(context).size.width) / (width / height), + child: chewies = Chewie( + controller: chewieAudioController, + ), + ), + ); + } + + Future _fullScreenListener() async { + print("object: isPlaying: ${videoPlayerController.value.isPlaying}"); + print("object: isFullScreen: ${chewieAudioController.isFullScreen}"); + + if (!chewieAudioController.isFullScreen) { + Future.delayed(Duration(seconds: 1), () { + widget.exitFull(); + }); + } + } + ///删除动态弹窗 showDeleteDialog() { showDialog( diff --git a/lib/mine/release_page.dart b/lib/mine/release_page.dart index 2923e642..1e3e809a 100644 --- a/lib/mine/release_page.dart +++ b/lib/mine/release_page.dart @@ -108,7 +108,9 @@ class _ReleasePage extends State { return InkWell( child: CommunityDynamic( comments[position], - 1, + 1,exitFull: (){setState(() { + + });}, removalDynamic: () { _onRefresh(); },