mirror of
https://github.com/twonlyapp/twonly-app.git
synced 2026-01-17 01:48:40 +00:00
59 lines
1.4 KiB
Dart
59 lines
1.4 KiB
Dart
import 'dart:async';
|
|
import 'dart:io';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:video_player/video_player.dart';
|
|
|
|
class VideoPlayerWrapper extends StatefulWidget {
|
|
const VideoPlayerWrapper({
|
|
required this.videoPath,
|
|
required this.mirrorVideo,
|
|
super.key,
|
|
});
|
|
final File videoPath;
|
|
final bool mirrorVideo;
|
|
|
|
@override
|
|
State<VideoPlayerWrapper> createState() => _VideoPlayerWrapperState();
|
|
}
|
|
|
|
class _VideoPlayerWrapperState extends State<VideoPlayerWrapper> {
|
|
late VideoPlayerController _controller;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_controller = VideoPlayerController.file(widget.videoPath);
|
|
|
|
unawaited(
|
|
_controller.initialize().then((_) async {
|
|
if (context.mounted) {
|
|
await _controller.setLooping(true);
|
|
await _controller.play();
|
|
setState(() {});
|
|
}
|
|
}),
|
|
);
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
unawaited(_controller.dispose());
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Center(
|
|
child: _controller.value.isInitialized
|
|
? AspectRatio(
|
|
aspectRatio: _controller.value.aspectRatio,
|
|
child: Transform.flip(
|
|
flipX: widget.mirrorVideo,
|
|
child: VideoPlayer(_controller),
|
|
),
|
|
)
|
|
: const CircularProgressIndicator(), // Show loading indicator while initializing
|
|
);
|
|
}
|
|
}
|