flutter_integrated_whb/lib/customWidget/full_screen_video_page.dart

86 lines
2.5 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

import 'package:flutter/material.dart';
import 'package:video_player/video_player.dart';
import 'package:chewie/chewie.dart';
/// 弹窗组件Chewie 版 VideoPlayerPopup
class VideoPlayerPopup extends StatefulWidget {
final String videoUrl;
const VideoPlayerPopup({Key? key, required this.videoUrl}) : super(key: key);
@override
State<VideoPlayerPopup> createState() => _VideoPlayerPopupState();
}
class _VideoPlayerPopupState extends State<VideoPlayerPopup> {
late VideoPlayerController _videoController;
ChewieController? _chewieController;
@override
void initState() {
super.initState();
_videoController = VideoPlayerController.networkUrl(Uri.parse(widget.videoUrl))
..initialize().then((_) {
setState(() {});
});
_chewieController = ChewieController(
videoPlayerController: _videoController,
autoPlay: true,
looping: false,
showOptions:false,
allowFullScreen: true,
allowPlaybackSpeedChanging: true,
allowMuting: true,
showControlsOnInitialize: true,
materialProgressColors: ChewieProgressColors(playedColor: Colors.blue,backgroundColor: Colors.white, handleColor:Colors.blue,bufferedColor:Colors.red),
aspectRatio: _videoController.value.aspectRatio,
);
}
@override
void dispose() {
_chewieController?.dispose();
_videoController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Center(
child: Material(
color: Colors.transparent,
child: Container(
constraints: BoxConstraints(
maxWidth: MediaQuery.of(context).size.width * 0.9,
maxHeight: 500,
),
decoration: BoxDecoration(
color: Colors.black,
borderRadius: BorderRadius.circular(8),
),
child: Stack(
children: [
// 视频播放器
if (_chewieController != null &&
_videoController.value.isInitialized)
Chewie(controller: _chewieController!)
else
const Center(child: CircularProgressIndicator()),
// 关闭按钮
Positioned(
top: 4,
right: 4,
child: IconButton(
icon: const Icon(Icons.close, color: Colors.white),
onPressed: () => Navigator.of(context).pop(),
),
),
],
),
),
),
);
}
}