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

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

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