Skip to content

Commit

Permalink
[video_player_avplayer] Add a case that plays the video of assets to …
Browse files Browse the repository at this point in the history
…the example

Play Butterfly-209.mp4 from assets.
  • Loading branch information
JSUYA committed Feb 2, 2024
1 parent d61197e commit 172d0af
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/video_player_avplay/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
63 changes: 62 additions & 1 deletion packages/video_player_avplay/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class _App extends StatelessWidget {
@override
Widget build(BuildContext context) {
return DefaultTabController(
length: 6,
length: 7,
child: Scaffold(
key: const ValueKey<String>('home_page'),
appBar: AppBar(
Expand All @@ -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'),
],
),
),
Expand All @@ -50,6 +51,7 @@ class _App extends StatelessWidget {
_DrmRemoteVideo(),
_DrmRemoteVideo2(),
_TrackTest(),
_AssetVideo(),
],
),
),
Expand Down Expand Up @@ -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: <Widget>[
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: <Widget>[
VideoPlayer(_controller),
ClosedCaption(text: _controller.value.caption.text),
_ControlsOverlay(controller: _controller),
VideoProgressIndicator(_controller, allowScrubbing: true),
],
),
),
),
],
),
);
}
}

class _ControlsOverlay extends StatelessWidget {
const _ControlsOverlay({required this.controller});

Expand Down

0 comments on commit 172d0af

Please sign in to comment.