提交 c24d98cd authored 作者: jungleiOS's avatar jungleiOS

loading 组件背景设为黑色,挡住亮度组件初始化时闪现问题,退出播放器恢复亮度

上级 2abe3aa0
...@@ -10,19 +10,60 @@ import 'package:gz_video_player/video_style.dart'; ...@@ -10,19 +10,60 @@ import 'package:gz_video_player/video_style.dart';
import 'package:gz_video_player/video_subtitles.dart'; import 'package:gz_video_player/video_subtitles.dart';
import 'package:gz_video_player/video_top_bar_style.dart'; import 'package:gz_video_player/video_top_bar_style.dart';
void main() { void main() {
runApp(const MyApp()); runApp(const MyApp());
} }
class MyApp extends StatefulWidget { class MyApp extends StatelessWidget {
const MyApp({super.key}); const MyApp({super.key});
@override @override
State<MyApp> createState() => _MyAppState(); Widget build(BuildContext context) {
return const MaterialApp(
home: HomePage(),
);
}
}
class HomePage extends StatelessWidget {
const HomePage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('HomePage'),
),
body: Center(
child: GestureDetector(
onTap: () {
Navigator.of(context).push(
MaterialPageRoute(builder: (BuildContext context) {
return const VideoPlayerPage();
}),
);
},
child: Container(
width: 120.0,
height: 30.0,
color: Colors.blue,
alignment: Alignment.center,
child: const Text('to video player'),
),
),
),
);
}
}
class VideoPlayerPage extends StatefulWidget {
const VideoPlayerPage({super.key});
@override
State<VideoPlayerPage> createState() => _VideoPlayerPageState();
} }
class _MyAppState extends State<MyApp> { class _VideoPlayerPageState extends State<VideoPlayerPage> {
// String videoUrl = "https://www.runoob.com/try/demo_source/movie.mp4"; // String videoUrl = "https://www.runoob.com/try/demo_source/movie.mp4";
// String videoUrl = "https://yun.zxziyuan-yun.com/20180221/4C6ivf8O/index.m3u8"; // String videoUrl = "https://yun.zxziyuan-yun.com/20180221/4C6ivf8O/index.m3u8";
...@@ -65,15 +106,14 @@ class _MyAppState extends State<MyApp> { ...@@ -65,15 +106,14 @@ class _MyAppState extends State<MyApp> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return MaterialApp( return Scaffold(
home: Scaffold( appBar: !_isFullscreen ? AppBar(title: const Text('video player')) : null,
appBar:
!_isFullscreen ? AppBar(title: const Text('video player')) : null,
body: Column(children: <Widget>[ body: Column(children: <Widget>[
videoUrl != "" videoUrl != ""
? GZVideoPlayer( ? GZVideoPlayer(
dataSource: videoUrl, dataSource: videoUrl,
sourceType: DataSourceType.network, sourceType: DataSourceType.network,
/// 视频播放配置 /// 视频播放配置
playOptions: VideoPlayOptions( playOptions: VideoPlayOptions(
seekSeconds: 30, seekSeconds: 30,
...@@ -122,8 +162,8 @@ class _MyAppState extends State<MyApp> { ...@@ -122,8 +162,8 @@ class _MyAppState extends State<MyApp> {
show: true, show: true,
//是否显示 //是否显示
height: 60, height: 60,
padding: const EdgeInsets.symmetric( padding:
vertical: 8, horizontal: 10), const EdgeInsets.symmetric(vertical: 8, horizontal: 10),
barBackgroundColor: const Color.fromRGBO(0, 0, 0, 0.5), barBackgroundColor: const Color.fromRGBO(0, 0, 0, 0.5),
popIcon: const Icon( popIcon: const Icon(
Icons.arrow_back, Icons.arrow_back,
...@@ -136,8 +176,7 @@ class _MyAppState extends State<MyApp> { ...@@ -136,8 +176,7 @@ class _MyAppState extends State<MyApp> {
margin: const EdgeInsets.symmetric(horizontal: 10), margin: const EdgeInsets.symmetric(horizontal: 10),
child: const Text( child: const Text(
'123', '123',
style: style: TextStyle(color: Colors.white, fontSize: 14),
TextStyle(color: Colors.white, fontSize: 14),
), ),
), ),
) )
...@@ -194,11 +233,12 @@ class _MyAppState extends State<MyApp> { ...@@ -194,11 +233,12 @@ class _MyAppState extends State<MyApp> {
/// 自定义颜色 /// 自定义颜色
// barBackgroundColor: Colors.blue, // barBackgroundColor: Colors.blue,
/// 自定义时间TextStyle /// 自定义时间TextStyle
timeTextStyle: const TextStyle(fontSize: 14.0, color: Colors.white), timeTextStyle:
const TextStyle(fontSize: 14.0, color: Colors.white),
///添加边距 ///添加边距
padding: const EdgeInsets.symmetric( padding:
vertical: 8, horizontal: 10), const EdgeInsets.symmetric(vertical: 8, horizontal: 10),
///设置控制拦的高度,默认为30,如果图标设置过大但是高度不够就会出现图标被裁剪的现象 ///设置控制拦的高度,默认为30,如果图标设置过大但是高度不够就会出现图标被裁剪的现象
height: 60, height: 60,
...@@ -462,7 +502,6 @@ class _MyAppState extends State<MyApp> { ...@@ -462,7 +502,6 @@ class _MyAppState extends State<MyApp> {
) )
: Container(), : Container(),
]), ]),
),
); );
} }
} }
......
...@@ -121,7 +121,8 @@ class GZVideoPlayerState extends State<GZVideoPlayer> ...@@ -121,7 +121,8 @@ class GZVideoPlayerState extends State<GZVideoPlayer>
bool _initialized = false; bool _initialized = false;
/// 屏幕亮度 /// 屏幕亮度
final ValueNotifier<double> _brightness = ValueNotifier(0.5); final ValueNotifier<double> _brightness = ValueNotifier(0.0);
late double _originBrightness;
/// 视频音量 /// 视频音量
final ValueNotifier<double> _volume = ValueNotifier(0.5); final ValueNotifier<double> _volume = ValueNotifier(0.5);
...@@ -221,14 +222,18 @@ class GZVideoPlayerState extends State<GZVideoPlayer> ...@@ -221,14 +222,18 @@ class GZVideoPlayerState extends State<GZVideoPlayer>
/// 常亮 /// 常亮
Wakelock.toggle(enable: true); Wakelock.toggle(enable: true);
/// 初始化亮度为系统亮度 /// 初始化亮度为系统亮度
ScreenBrightness().current.then((brightness) { initBrightness();
_brightness.value = brightness;
});
/// 倍数按钮标题 /// 倍数按钮标题
_speedTitle = widget.videoStyle.videoSpeedButtonStyle.title; _speedTitle = widget.videoStyle.videoSpeedButtonStyle.title;
_initPlayer(); _initPlayer();
} }
void initBrightness() async {
double brightness = await ScreenBrightness().current;
_brightness.value = brightness;
_originBrightness = brightness;
}
@override @override
void didUpdateWidget(GZVideoPlayer oldWidget) { void didUpdateWidget(GZVideoPlayer oldWidget) {
if (oldWidget.dataSource != widget.dataSource) { if (oldWidget.dataSource != widget.dataSource) {
...@@ -251,6 +256,7 @@ class GZVideoPlayerState extends State<GZVideoPlayer> ...@@ -251,6 +256,7 @@ class GZVideoPlayerState extends State<GZVideoPlayer>
_subscription.cancel(); _subscription.cancel();
_brightness.dispose(); _brightness.dispose();
_volume.dispose(); _volume.dispose();
ScreenBrightness().setScreenBrightness(_originBrightness);
super.dispose(); super.dispose();
} }
......
...@@ -8,7 +8,9 @@ class VideoLoadingView extends StatelessWidget { ...@@ -8,7 +8,9 @@ class VideoLoadingView extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Align( return DecoratedBox(
decoration: const BoxDecoration(color: Colors.black),
child: Align(
alignment: Alignment.center, alignment: Alignment.center,
child: Center( child: Center(
child: Column( child: Column(
...@@ -31,6 +33,7 @@ class VideoLoadingView extends StatelessWidget { ...@@ -31,6 +33,7 @@ class VideoLoadingView extends StatelessWidget {
], ],
), ),
), ),
),
); );
} }
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论