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

切换视频源 刷新清晰度

上级 43674456
...@@ -559,6 +559,30 @@ class _VideoPlayerPageState extends State<VideoPlayerPage> { ...@@ -559,6 +559,30 @@ class _VideoPlayerPageState extends State<VideoPlayerPage> {
), ),
), ),
), ),
SliverToBoxAdapter(
child: Center(
child: CustomBtn(
title: '切换视频source',
onTap: () {
definitionList = [
VideoDefinitionItem(
dataSource:
'https://mpv.videocc.net/8f38fa3352/0/8f38fa33525a64b20de46bb5271f5ba0_1.mp4',
title: 'LD',
),
VideoDefinitionItem(
dataSource:
'https://mpv.videocc.net/8f38fa3352/0/8f38fa33525a64b20de46bb5271f5ba0_2.mp4',
title: 'SD',
),
];
videoUrl =
'https://mpv.videocc.net/8f38fa3352/0/8f38fa33525a64b20de46bb5271f5ba0_1.mp4';
setState(() {});
},
),
),
),
], ],
), ),
) )
......
...@@ -3,6 +3,7 @@ import 'dart:io'; ...@@ -3,6 +3,7 @@ import 'dart:io';
import 'package:connectivity/connectivity.dart'; import 'package:connectivity/connectivity.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:gz_orientation/gz_orientation.dart'; import 'package:gz_orientation/gz_orientation.dart';
import 'package:gz_video_player/video_definition.dart'; import 'package:gz_video_player/video_definition.dart';
...@@ -224,17 +225,11 @@ class GZVideoPlayerState extends State<GZVideoPlayer> ...@@ -224,17 +225,11 @@ class GZVideoPlayerState extends State<GZVideoPlayer>
/// 清晰度按钮标题 /// 清晰度按钮标题
_definitionTitle = widget.videoStyle.videoDefinitionButtonStyle.title; _definitionTitle = widget.videoStyle.videoDefinitionButtonStyle.title;
if (widget.playOptions.definitionList.isNotEmpty) { _resetDefinitionTitle();
for (VideoDefinitionItem item in widget.playOptions.definitionList) {
if (widget.dataSource == item.dataSource) {
_definitionTitle = item.title;
break;
}
}
}
_initPlayer(); _initPlayer();
} }
Future<void> initBrightness() async { Future<void> initBrightness() async {
double brightness = await ScreenBrightness().current; double brightness = await ScreenBrightness().current;
_brightness.value = brightness; _brightness.value = brightness;
...@@ -245,6 +240,7 @@ class GZVideoPlayerState extends State<GZVideoPlayer> ...@@ -245,6 +240,7 @@ class GZVideoPlayerState extends State<GZVideoPlayer>
void didUpdateWidget(GZVideoPlayer oldWidget) { void didUpdateWidget(GZVideoPlayer oldWidget) {
if (oldWidget.dataSource != widget.dataSource || if (oldWidget.dataSource != widget.dataSource ||
oldWidget.sourceType != widget.sourceType) { oldWidget.sourceType != widget.sourceType) {
_resetDefinitionTitle();
_updateDataSource(type: widget.sourceType, source: widget.dataSource); _updateDataSource(type: widget.sourceType, source: widget.dataSource);
} }
super.didUpdateWidget(oldWidget); super.didUpdateWidget(oldWidget);
...@@ -336,13 +332,24 @@ class GZVideoPlayerState extends State<GZVideoPlayer> ...@@ -336,13 +332,24 @@ class GZVideoPlayerState extends State<GZVideoPlayer>
void resetVideoPlayer() { void resetVideoPlayer() {
setState(() { setState(() {
_isEnded = true; _isEnded = true;
// _position = "--:--"; _position = _duration;
// _duration = "--:--"; // _duration = "--:--";
_controller.value = _controller.value =
const VideoPlayerValue(duration: Duration(seconds: 0)); const VideoPlayerValue(duration: Duration(seconds: 0));
}); });
} }
void _resetDefinitionTitle() {
if (widget.playOptions.definitionList.isNotEmpty) {
for (VideoDefinitionItem item in widget.playOptions.definitionList) {
if (widget.dataSource == item.dataSource) {
_definitionTitle = item.title;
break;
}
}
}
}
void _listener() { void _listener() {
if (!mounted) { if (!mounted) {
return; return;
......
...@@ -74,6 +74,7 @@ class _VideoDefinitionSideBarState extends State<VideoDefinitionSideBar> ...@@ -74,6 +74,7 @@ class _VideoDefinitionSideBarState extends State<VideoDefinitionSideBar>
VideoDefinitionItem item = itemList[i]; VideoDefinitionItem item = itemList[i];
if (defaultSource == item.dataSource) { if (defaultSource == item.dataSource) {
_selectedIndex = i; _selectedIndex = i;
break;
} }
} }
} }
...@@ -83,6 +84,7 @@ class _VideoDefinitionSideBarState extends State<VideoDefinitionSideBar> ...@@ -83,6 +84,7 @@ class _VideoDefinitionSideBarState extends State<VideoDefinitionSideBar>
super.didUpdateWidget(oldWidget); super.didUpdateWidget(oldWidget);
if (oldWidget.defaultSource != defaultSource || if (oldWidget.defaultSource != defaultSource ||
oldWidget.itemList != itemList) { oldWidget.itemList != itemList) {
_selectedIndex = 0;
SchedulerBinding.instance.addPostFrameCallback((timeStamp) { SchedulerBinding.instance.addPostFrameCallback((timeStamp) {
changeDefaultIndex(); changeDefaultIndex();
setState(() {}); setState(() {});
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论