From 172d0afdc10be3b6ee664ee602cfcfb8ce13d642 Mon Sep 17 00:00:00 2001 From: JunsuChoi Date: Thu, 1 Feb 2024 16:49:50 +0900 Subject: [PATCH] [video_player_avplayer] Add a case that plays the video of assets to the example Play Butterfly-209.mp4 from assets. --- packages/video_player_avplay/CHANGELOG.md | 1 + .../video_player_avplay/example/lib/main.dart | 63 ++++++++++++++++++- 2 files changed, 63 insertions(+), 1 deletion(-) diff --git a/packages/video_player_avplay/CHANGELOG.md b/packages/video_player_avplay/CHANGELOG.md index cb9b23a4f..9870df184 100644 --- a/packages/video_player_avplay/CHANGELOG.md +++ b/packages/video_player_avplay/CHANGELOG.md @@ -2,6 +2,7 @@ * Check httper_headers pointer when creating media player. * Fix state check in SetVolume. +* Add a case that plays the video of assets to the example. ## 0.3.2 diff --git a/packages/video_player_avplay/example/lib/main.dart b/packages/video_player_avplay/example/lib/main.dart index d7431dd13..dfd23a18d 100644 --- a/packages/video_player_avplay/example/lib/main.dart +++ b/packages/video_player_avplay/example/lib/main.dart @@ -25,7 +25,7 @@ class _App extends StatelessWidget { @override Widget build(BuildContext context) { return DefaultTabController( - length: 6, + length: 7, child: Scaffold( key: const ValueKey('home_page'), appBar: AppBar( @@ -39,6 +39,7 @@ class _App extends StatelessWidget { Tab(icon: Icon(Icons.cloud), text: 'DRM Widevine'), Tab(icon: Icon(Icons.cloud), text: 'DRM PlayReady'), Tab(icon: Icon(Icons.cloud), text: 'Track'), + Tab(icon: Icon(Icons.cloud), text: 'Asset'), ], ), ), @@ -50,6 +51,7 @@ class _App extends StatelessWidget { _DrmRemoteVideo(), _DrmRemoteVideo2(), _TrackTest(), + _AssetVideo(), ], ), ), @@ -439,6 +441,65 @@ class _TrackTestState extends State<_TrackTest> { } } +class _AssetVideo extends StatefulWidget { + @override + State<_AssetVideo> createState() => _AssetVideoState(); +} + +class _AssetVideoState extends State<_AssetVideo> { + late VideoPlayerController _controller; + + @override + void initState() { + super.initState(); + + _controller = VideoPlayerController.asset('assets/Butterfly-209.mp4'); + + _controller.addListener(() { + if (_controller.value.hasError) { + print(_controller.value.errorDescription); + } + setState(() {}); + }); + _controller.setLooping(true); + _controller.initialize().then((_) => setState(() {})); + _controller.play(); + } + + @override + void dispose() { + _controller.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + return SingleChildScrollView( + child: Column( + children: [ + Container(padding: const EdgeInsets.only(top: 20.0)), + const Text('With assets mp4'), + Container( + padding: const EdgeInsets.all(20), + child: AspectRatio( + aspectRatio: _controller.value.aspectRatio, + child: Stack( + alignment: Alignment.bottomCenter, + children: [ + VideoPlayer(_controller), + ClosedCaption(text: _controller.value.caption.text), + _ControlsOverlay(controller: _controller), + VideoProgressIndicator(_controller, allowScrubbing: true), + ], + ), + ), + ), + ], + ), + ); + } +} + class _ControlsOverlay extends StatelessWidget { const _ControlsOverlay({required this.controller});