-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathchewie_player.dart
81 lines (74 loc) · 2.19 KB
/
chewie_player.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import 'package:chewie/chewie.dart';
import 'package:flutter/material.dart';
import 'package:video_player/video_player.dart';
class ChewiePlayer extends StatefulWidget {
// This will contain the URL/asset path which we want to play
final VideoPlayerController videoPlayerController;
final bool looping;
const ChewiePlayer({
Key? key,
required this.videoPlayerController,
required this.looping,
}) : super(key: key);
@override
State<ChewiePlayer> createState() => _ChewiePlayerState();
}
class _ChewiePlayerState extends State<ChewiePlayer> {
late ChewieController _chewieController;
@override
void initState() {
super.initState();
// Wrapper on top of the videoPlayerController
_chewieController = ChewieController(
videoPlayerController: widget.videoPlayerController,
aspectRatio: 16 / 9,
// Prepare the video to be played and display the first frame
autoInitialize: true,
looping: widget.looping,
// Errors can occur for example when trying to play a video
// from a non-existent URL
errorBuilder: (context, errorMessage) {
return Center(
child: Padding(
padding: const EdgeInsets.all(10.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Icon(
Icons.error_outline_outlined,
size: 35,
color: Colors.redAccent,
),
const SizedBox(height: 10),
Text(
errorMessage,
style: const TextStyle(color: Colors.red),
textAlign: TextAlign.center,
),
],
),
),
);
},
);
}
@override
void dispose() {
super.dispose();
// IMPORTANT to dispose of all the used resources
widget.videoPlayerController.dispose();
_chewieController.dispose();
}
@override
Widget build(BuildContext context) {
return SizedBox(
height: 220,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Chewie(
controller: _chewieController,
),
),
);
}
}