mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-11-22 12:59:21 +00:00
Add a video player
This commit is contained in:
parent
46affd4e68
commit
858f81d05e
68
lib/ui/routes/video_player_route.dart
Normal file
68
lib/ui/routes/video_player_route.dart
Normal file
@ -0,0 +1,68 @@
|
||||
import 'package:chewie/chewie.dart';
|
||||
import 'package:comunic/ui/widgets/async_screen_widget.dart';
|
||||
import 'package:comunic/ui/widgets/comunic_back_button_widget.dart';
|
||||
import 'package:comunic/utils/intl_utils.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:video_player/video_player.dart';
|
||||
|
||||
/// Video player route
|
||||
///
|
||||
/// @author Pierre Hubert
|
||||
|
||||
class VideoPlayerRoute extends StatefulWidget {
|
||||
final String url;
|
||||
|
||||
const VideoPlayerRoute({
|
||||
Key key,
|
||||
@required this.url,
|
||||
}) : assert(url != null),
|
||||
super(key: key);
|
||||
|
||||
@override
|
||||
_VideoPlayerRouteState createState() => _VideoPlayerRouteState();
|
||||
}
|
||||
|
||||
class _VideoPlayerRouteState extends State<VideoPlayerRoute> {
|
||||
VideoPlayerController _videoPlayerController;
|
||||
ChewieController _chewieController;
|
||||
|
||||
Future<void> _initialize() async {
|
||||
_videoPlayerController = VideoPlayerController.network(widget.url);
|
||||
|
||||
await _videoPlayerController.initialize();
|
||||
|
||||
_chewieController = ChewieController(
|
||||
videoPlayerController: _videoPlayerController,
|
||||
looping: false,
|
||||
allowFullScreen: true,
|
||||
allowMuting: true,
|
||||
allowedScreenSleep: false,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
if (_videoPlayerController != null) _videoPlayerController.dispose();
|
||||
if (_chewieController != null) _chewieController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
leading: ComunicBackButton(),
|
||||
title: Text("Video"),
|
||||
),
|
||||
body: _buildBody(),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildBody() => AsyncScreenWidget(
|
||||
onReload: _initialize,
|
||||
onBuild: _showBody,
|
||||
errorMessage: tr("Failed to initialize video!"),
|
||||
);
|
||||
|
||||
Widget _showBody() => Chewie(controller: _chewieController);
|
||||
}
|
@ -3,6 +3,8 @@
|
||||
/// @author Pierre Hubert
|
||||
import 'package:comunic/models/conversation_message.dart';
|
||||
import 'package:comunic/ui/dialogs/audio_player_dialog.dart';
|
||||
import 'package:comunic/ui/routes/main_route/main_route.dart';
|
||||
import 'package:comunic/ui/routes/video_player_route.dart';
|
||||
import 'package:comunic/ui/widgets/network_image_widget.dart';
|
||||
import 'package:filesize/filesize.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
@ -84,6 +86,14 @@ class _ConversationFileWidgetState extends State<ConversationFileWidget> {
|
||||
showAudioPlayerDialog(context, file.url);
|
||||
break;
|
||||
|
||||
case ConversationMessageFileType.VIDEO:
|
||||
MainController.of(context).push(
|
||||
VideoPlayerRoute(url: file.url),
|
||||
hideNavBar: true,
|
||||
canShowAsDialog: true,
|
||||
);
|
||||
break;
|
||||
|
||||
default:
|
||||
launch(file.url);
|
||||
}
|
||||
|
@ -50,6 +50,13 @@ packages:
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.2.0-nullsafety.1"
|
||||
chewie:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: chewie
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.12.2"
|
||||
chewie_audio:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
|
@ -106,6 +106,7 @@ dependencies:
|
||||
# Video / Audio player
|
||||
video_player: ^1.0.1
|
||||
chewie_audio: ^1.1.2
|
||||
chewie: ^0.12.2
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
Loading…
Reference in New Issue
Block a user