75 lines
1.8 KiB
Dart
Executable File
75 lines
1.8 KiB
Dart
Executable File
import 'package:flutter/material.dart';
|
|
import 'package:video_player/video_player.dart';
|
|
|
|
class NetworkVideoPlayer extends StatefulWidget {
|
|
final String videoUrl;
|
|
|
|
const NetworkVideoPlayer({super.key, required this.videoUrl});
|
|
|
|
@override
|
|
State<NetworkVideoPlayer> createState() => _NetworkVideoPlayerState();
|
|
}
|
|
|
|
class _NetworkVideoPlayerState extends State<NetworkVideoPlayer> {
|
|
late VideoPlayerController _controller;
|
|
bool isInitialized = false;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
|
|
_controller = VideoPlayerController.networkUrl(
|
|
Uri.parse(widget.videoUrl),
|
|
)
|
|
..initialize().then((_) {
|
|
setState(() {
|
|
isInitialized = true;
|
|
});
|
|
});
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_controller.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return AspectRatio(
|
|
aspectRatio:
|
|
isInitialized ? _controller.value.aspectRatio : 16 / 9,
|
|
child: isInitialized
|
|
? Stack(
|
|
alignment: Alignment.bottomCenter,
|
|
children: [
|
|
VideoPlayer(_controller),
|
|
VideoProgressIndicator(
|
|
_controller,
|
|
allowScrubbing: true,
|
|
),
|
|
Center(
|
|
child: IconButton(
|
|
iconSize: 60,
|
|
icon: Icon(
|
|
_controller.value.isPlaying
|
|
? Icons.pause_circle
|
|
: Icons.play_circle,
|
|
color: Colors.white,
|
|
),
|
|
onPressed: () {
|
|
setState(() {
|
|
_controller.value.isPlaying
|
|
? _controller.pause()
|
|
: _controller.play();
|
|
});
|
|
},
|
|
),
|
|
),
|
|
],
|
|
)
|
|
: const Center(child: CircularProgressIndicator()),
|
|
);
|
|
}
|
|
}
|