我正在尝试使用
VideoPlayer
包显示文件中的视频,如下所示:
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
videoFileShow == null ||
videoFileShow!.length <= movie.videoIndex
? Image.asset('assets/images/video-placeholder.jpg')
: VideoPlayerWidget(
isNetwork: false,
videoAddress: videoFileShow![movie.videoIndex]
),
这是
VideoPlayerWidget.dart
:
class VideoPlayerWidget extends StatefulWidget {
final dynamic? videoAddress;
final bool? isNetwork;
const VideoPlayerWidget({Key? key, this.isNetwork, this.videoAddress})
: super(key: key);
@override
State<VideoPlayerWidget> createState() => _VideoPlayerWidgetState();
}
class _VideoPlayerWidgetState extends State<VideoPlayerWidget> {
VideoPlayerController? controller;
@override
void initState() {
super.initState();
if (widget.isNetwork!) {
controller = VideoPlayerController.network(widget.videoAddress!)
..addListener(() => setState(() {}))
..setLooping(false)
..initialize().then((_) => controller!.pause());
} else {
print(VideoPlayerController.file(widget.videoAddress));
VideoPlayerController.file(widget.videoAddress!)
..addListener(() => setState(() {}))
..setLooping(false)
..initialize().then((_) => controller!.pause());
print('here?');
}
}
@override
void dispose() {
super.dispose();
controller!.dispose();
}
@override
Widget build(BuildContext context) {
return Container(
alignment: Alignment.center,
child: Column(children: [
VideoPlayerBaseWidget(controller: controller),
]),
);
}
}
但是我得到以下错误:
@patch
@pragma("vm:external-name", "Error_throwWithStackTrace")
external static Never _throw(Object error, StackTrace stackTrace);
EDIT
:我在 else
语句中添加了 2 个打印命令,这是第一个可能有帮助的结果(第二个打印未执行):
我/颤动(5055): VideoPlayerController#ba01e(VideoPlayerValue(持续时间: 0:00:00.000000, 大小:大小(0.0,0.0),位置:0:00:00.000000,标题: 标题(数字:0,开始:0:00:00.000000,结束:0:00:00.000000,文本: ), captionOffset: 0:00:00.000000, buffered: [], isInitialized: false, isPlaying: false, isLooping: false, isBuffering: false, volume: 1.0, playbackSpeed: 1.0, errorDescription: null))