mirror of
https://bitbucket.org/FransoletThomas/tablet-app.git
synced 2025-12-06 08:31:19 +00:00
95 lines
2.7 KiB
Dart
95 lines
2.7 KiB
Dart
import 'dart:io';
|
|
|
|
//import 'package:cached_video_player/cached_video_player.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:tablet_app/Components/loading_common.dart';
|
|
import 'package:video_player/video_player.dart';
|
|
import '../../constants.dart';
|
|
|
|
class VideoViewer extends StatefulWidget {
|
|
final String videoUrl;
|
|
final File? file;
|
|
VideoViewer({required this.videoUrl, required this.file});
|
|
|
|
@override
|
|
_VideoViewer createState() => _VideoViewer();
|
|
}
|
|
|
|
class _VideoViewer extends State<VideoViewer> {
|
|
late VideoPlayerController _controller; // Cached
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
if(widget.file != null) {
|
|
_controller = VideoPlayerController.file(widget.file!) // Uri.parse() // Cached
|
|
..initialize().then((_) {
|
|
// Ensure the first frame is shown after the video is initialized, even before the play button has been pressed.
|
|
setState(() {});
|
|
});
|
|
} else {
|
|
_controller = VideoPlayerController.networkUrl(Uri.parse(widget.videoUrl)) // Uri.parse()
|
|
..initialize().then((_) {
|
|
// Ensure the first frame is shown after the video is initialized, even before the play button has been pressed.
|
|
setState(() {});
|
|
});
|
|
}
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
super.dispose();
|
|
_controller.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Stack(
|
|
children: [
|
|
Center(
|
|
child: InkWell(
|
|
onTap: () {
|
|
setState(() {
|
|
if(_controller.value.isInitialized) {
|
|
if(_controller.value.isPlaying) {
|
|
_controller.pause();
|
|
} else {
|
|
_controller.play();
|
|
}
|
|
}
|
|
});
|
|
},
|
|
child: _controller.value.isInitialized
|
|
? AspectRatio(
|
|
aspectRatio: _controller.value.aspectRatio,
|
|
child: VideoPlayer(_controller),
|
|
)
|
|
: Center(
|
|
child: Container(
|
|
child: LoadingCommon()
|
|
)
|
|
),
|
|
),
|
|
),
|
|
if(!_controller.value.isPlaying && _controller.value.isInitialized)
|
|
Center(
|
|
child: FloatingActionButton(
|
|
backgroundColor: kTestSecondColor.withValues(alpha: 0.8),
|
|
onPressed: () {
|
|
setState(() {
|
|
_controller.value.isPlaying
|
|
? _controller.pause()
|
|
: _controller.play();
|
|
});
|
|
},
|
|
child: Icon(
|
|
_controller.value.isPlaying ? Icons.pause : Icons.play_arrow,
|
|
color: Colors.white),
|
|
),
|
|
)
|
|
],
|
|
);
|
|
}
|
|
}
|
|
|