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

根据source type 加载视频文件

上级 993eb30c
......@@ -73,7 +73,7 @@ class _MyAppState extends State<MyApp> {
videoUrl != ""
? GZVideoPlayer(
dataSource: videoUrl,
sourceType: DataSourceType.asset,
/// 视频播放配置
playOptions: VideoPlayOptions(
seekSeconds: 30,
......
import 'dart:async';
import 'dart:io';
import 'package:connectivity/connectivity.dart';
import 'package:flutter/material.dart';
......@@ -19,10 +20,13 @@ import 'package:screen_brightness/screen_brightness.dart';
import 'package:video_player/video_player.dart';
import 'package:wakelock/wakelock.dart';
export 'package:video_player/video_player.dart';
class GZVideoPlayer extends StatefulWidget {
GZVideoPlayer({
super.key,
required this.dataSource,
required this.sourceType,
VideoPlayOptions? playOptions,
VideoStyle? videoStyle,
this.brightnessWidget,
......@@ -45,6 +49,7 @@ class GZVideoPlayer extends StatefulWidget {
/// 视频资源
final dynamic dataSource;
final DataSourceType sourceType;
/// 播放自定义属性
final VideoPlayOptions playOptions;
......@@ -457,16 +462,15 @@ class GZVideoPlayerState extends State<GZVideoPlayer>
/// 创建video controller
VideoPlayerController _createVideoPlayerController() {
final netRegx = RegExp(r'^(http|https)://([\w.]+/?)\S*');
final fileRegx = RegExp(r'^(file)://([\w.]+/?)\S*');
final isNetwork = netRegx.hasMatch(widget.dataSource);
final isFile = fileRegx.hasMatch(widget.dataSource);
if (isNetwork) {
return VideoPlayerController.networkUrl(Uri.parse(widget.dataSource));
} else if (isFile) {
return VideoPlayerController.file(widget.dataSource);
} else {
return VideoPlayerController.asset(widget.dataSource);
switch (widget.sourceType) {
case DataSourceType.asset:
return VideoPlayerController.asset(widget.dataSource);
case DataSourceType.file:
return VideoPlayerController.file(File(widget.dataSource));
case DataSourceType.contentUri:
return VideoPlayerController.contentUri(Uri.parse(widget.dataSource));
case DataSourceType.network:
return VideoPlayerController.networkUrl(Uri.parse(widget.dataSource));
}
}
......@@ -766,8 +770,10 @@ class GZVideoPlayerState extends State<GZVideoPlayer>
if (!_controller.value.isInitialized) return;
},
onVerticalDragUpdate: (DragUpdateDetails details) async {
if (!_controller.value.isInitialized || details.primaryDelta == null)
if (!_controller.value.isInitialized ||
details.primaryDelta == null) {
return;
}
// 右侧垂直滑动 - 音量调节
if (details.globalPosition.dx >= (screenSize.width / 2)) {
_volume.value = _controller.value.volume;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论