poem_video_player.dart
4.64 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
import 'package:fijkplayer/fijkplayer.dart';
import 'package:flutter/material.dart';
import 'package:Parlando/res/resources.dart';
import 'package:Parlando/routers/fluro_navigator.dart';
import 'package:Parlando/widgets/my_app_bar.dart';
import 'package:Parlando/extension/int_extension.dart';
import 'package:path_provider/path_provider.dart';
import '../../net/dio_utils.dart';
import '../../net/http_api.dart';
import '../models/poem_entity.dart';
import '../poem_router.dart';
class PoemVideoPlayer extends StatefulWidget {
final String url;
final String? title;
final int id;
final int type;
final int poemId;
const PoemVideoPlayer({
Key? key,
required this.url,
this.title,
required this.id,
required this.type,
required this.poemId,
}) : super(key: key);
@override
PoemVideoPlayerState createState() => PoemVideoPlayerState();
}
class PoemVideoPlayerState extends State<PoemVideoPlayer> {
final FijkPlayer player = FijkPlayer();
PoemData? _poem;
PoemVideoPlayerState();
Future<String> _getDir() async {
final directory = await getApplicationDocumentsDirectory();
return directory.path;
}
@override
void initState() {
super.initState();
_getDir().then((value) {
String path = "$value/${widget.url}";
player.setDataSource(
path,
autoPlay: true,
);
player.setLoop(0);
});
fetchPoemDetail();
}
Future<void> fetchPoemDetail() async {
DioUtils.instance.asyncRequestNetwork<PoemEntity>(
Method.get,
"${HttpApi.poem}/${widget.poemId}",
params: [],
onSuccess: (data) {
_poem = data!.data!;
setState(() {});
},
onError: (code, msg) {},
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: MyAppBar(
homeMenuHeader: Container(
alignment: Alignment.center,
child: Text(
widget.title ?? "视频播放",
style: const TextStyle(
color: Colors.white,
),
),
),
),
body: Stack(
children: [
FijkView(
height: MediaQuery.of(context).size.height,
player: player,
fit: FijkFit.fill,
),
Padding(
padding: EdgeInsets.fromLTRB(10.px, 30.px, 10.px, 10.px),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
_poem != null ? _poem!.title.toString() : "",
style: TextStyle(
color: Colors.white,
fontSize: 28.px,
),
),
Gaps.vGap10,
Text(
_poem != null ? _poem!.author.toString() : "",
style: TextStyle(
color: Colors.white,
fontSize: 15.px,
),
),
Gaps.vGap5,
Text(
_poem != null ? _poem!.content.toString() : "",
style: TextStyle(
color: Colors.white,
fontFamily: "ZCOOLXiaoWei",
fontSize: 25.px,
),
),
Gaps.vGap5,
Text(
"临者:老魔取西经",
style: TextStyle(
color: Colors.white,
fontSize: 15.px,
),
),
Text(
"2022年01月25日 辰时三刻",
style: TextStyle(
color: Colors.white,
fontSize: 15.px,
),
),
],
),
),
Positioned(
bottom: 10.px,
right: 20.px,
child: ElevatedButton(
onPressed: () {
NavigatorUtils.push(context,
'${PoemRouter.poemPublish}?data=${widget.url}&id=${widget.id}&type=${widget.type}',
clearStack: true);
},
style: TextButton.styleFrom(
primary: Colors.white,
backgroundColor: Colors.black54,
),
child: Text(
"下一步",
style: TextStyle(fontSize: 15.px),
),
),
),
],
));
}
@override
void dispose() {
player.release();
super.dispose();
}
}