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

根据source type 加载视频文件

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