dartlangeditorflutterflutter-appsflutter-examplesflutter-packageflutter-widgetquillquill-deltaquilljsreactquillrich-textrich-text-editorwysiwygwysiwyg-editor
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
112 lines
3.1 KiB
112 lines
3.1 KiB
4 years ago
|
import 'dart:io';
|
||
|
|
||
4 years ago
|
import 'package:flutter/gestures.dart';
|
||
4 years ago
|
import 'package:flutter/material.dart';
|
||
3 years ago
|
import 'package:flutter_quill/flutter_quill.dart';
|
||
4 years ago
|
import 'package:url_launcher/url_launcher.dart';
|
||
4 years ago
|
import 'package:video_player/video_player.dart';
|
||
|
|
||
|
/// Widget for playing back video
|
||
|
/// Refer to https://github.com/flutter/plugins/tree/master/packages/video_player/video_player
|
||
|
class VideoApp extends StatefulWidget {
|
||
3 years ago
|
const VideoApp({
|
||
|
required this.videoUrl,
|
||
|
required this.context,
|
||
|
required this.readOnly,
|
||
|
this.onVideoInit,
|
||
|
});
|
||
4 years ago
|
|
||
4 years ago
|
final String videoUrl;
|
||
4 years ago
|
final BuildContext context;
|
||
4 years ago
|
final bool readOnly;
|
||
3 years ago
|
final void Function(GlobalKey videoContainerKey)? onVideoInit;
|
||
4 years ago
|
|
||
|
@override
|
||
|
_VideoAppState createState() => _VideoAppState();
|
||
|
}
|
||
|
|
||
|
class _VideoAppState extends State<VideoApp> {
|
||
|
late VideoPlayerController _controller;
|
||
3 years ago
|
GlobalKey videoContainerKey = GlobalKey();
|
||
4 years ago
|
|
||
|
@override
|
||
|
void initState() {
|
||
|
super.initState();
|
||
|
|
||
|
_controller = widget.videoUrl.startsWith('http')
|
||
|
? VideoPlayerController.network(widget.videoUrl)
|
||
4 years ago
|
: VideoPlayerController.file(File(widget.videoUrl))
|
||
4 years ago
|
..initialize().then((_) {
|
||
|
// Ensure the first frame is shown after the video is initialized,
|
||
|
// even before the play button has been pressed.
|
||
|
setState(() {});
|
||
3 years ago
|
if (widget.onVideoInit != null) {
|
||
|
widget.onVideoInit?.call(videoContainerKey);
|
||
|
}
|
||
3 years ago
|
}).catchError((error) {
|
||
|
setState(() {});
|
||
3 years ago
|
});
|
||
4 years ago
|
}
|
||
|
|
||
|
@override
|
||
|
Widget build(BuildContext context) {
|
||
4 years ago
|
final defaultStyles = DefaultStyles.getInstance(context);
|
||
3 years ago
|
if (_controller.value.hasError) {
|
||
4 years ago
|
if (widget.readOnly) {
|
||
|
return RichText(
|
||
|
text: TextSpan(
|
||
|
text: widget.videoUrl,
|
||
|
style: defaultStyles.link,
|
||
|
recognizer: TapGestureRecognizer()
|
||
3 years ago
|
..onTap = () => launchUrl(Uri.parse(widget.videoUrl))),
|
||
4 years ago
|
);
|
||
|
}
|
||
|
|
||
4 years ago
|
return RichText(
|
||
4 years ago
|
text: TextSpan(text: widget.videoUrl, style: defaultStyles.link));
|
||
3 years ago
|
} else if (!_controller.value.isInitialized) {
|
||
3 years ago
|
return VideoProgressIndicator(
|
||
|
_controller,
|
||
|
allowScrubbing: true,
|
||
|
colors: const VideoProgressColors(playedColor: Colors.blue),
|
||
3 years ago
|
);
|
||
4 years ago
|
}
|
||
|
|
||
4 years ago
|
return Container(
|
||
3 years ago
|
key: videoContainerKey,
|
||
|
// height: 300,
|
||
4 years ago
|
child: InkWell(
|
||
|
onTap: () {
|
||
|
setState(() {
|
||
|
_controller.value.isPlaying
|
||
|
? _controller.pause()
|
||
|
: _controller.play();
|
||
|
});
|
||
|
},
|
||
|
child: Stack(alignment: Alignment.center, children: [
|
||
|
Center(
|
||
4 years ago
|
child: AspectRatio(
|
||
|
aspectRatio: _controller.value.aspectRatio,
|
||
|
child: VideoPlayer(_controller),
|
||
|
)),
|
||
|
_controller.value.isPlaying
|
||
4 years ago
|
? const SizedBox.shrink()
|
||
4 years ago
|
: Container(
|
||
4 years ago
|
color: const Color(0xfff5f5f5),
|
||
4 years ago
|
child: const Icon(
|
||
|
Icons.play_arrow,
|
||
|
size: 60,
|
||
|
color: Colors.blueGrey,
|
||
|
))
|
||
4 years ago
|
]),
|
||
|
),
|
||
|
);
|
||
|
}
|
||
|
|
||
|
@override
|
||
|
void dispose() {
|
||
|
super.dispose();
|
||
|
_controller.dispose();
|
||
|
}
|
||
|
}
|