第三方视频播放库的使用
关于DanmakuVideoPlayer的使用
介绍DanmakuVideoPlayer
基于IJKPlayer(兼容系统MediaPlayer与EXOPlayer2),实现了多功能的视频播放器
(包括弹幕)引入
A、直接引入
1
2//完整版引入
implementation 'com.shuyu:GSYVideoPlayer:7.1.6'B、添加java和你想要的so支持:
1
2
3
4
5
6
7
8
9
10
11implementation 'com.shuyu:gsyVideoPlayer-java:7.1.6'
//是否需要ExoPlayer模式
implementation 'com.shuyu:GSYVideoPlayer-exo2:7.1.6'
//根据你的需求ijk模式的so
implementation 'com.shuyu:gsyVideoPlayer-armv5:7.1.6'
implementation 'com.shuyu:gsyVideoPlayer-armv7a:7.1.6'
implementation 'com.shuyu:gsyVideoPlayer-arm64:7.1.6'
implementation 'com.shuyu:gsyVideoPlayer-x64:7.1.6'
implementation 'com.shuyu:gsyVideoPlayer-x86:7.1.6'支持其他格式协议的(mpeg,rtsp, concat、crypto协议)
A、B普通版本支持263/264/265等,对于mpeg编码会有声音无画面情况。 C 引入的so支持mpeg编码和其他补充协议,但是so包相对变大。1
2
3
4
5
6
7implementation 'com.shuyu:gsyVideoPlayer-java:7.1.6'
//是否需要ExoPlayer模式
implementation 'com.shuyu:GSYVideoPlayer-exo2:7.1.6'
//更多ijk的编码支持
implementation 'com.shuyu:gsyVideoPlayer-ex_so:7.1.6'
activity/fragment中使用
- 创建一个播放器类,继承StandardGSYVideoPlayer,并且创建播放器的布局。
1
2
3public class DanmakuVideoPlayer extends StandardGSYVideoPlayer {
} - 布局文件次布局包括 顶部、播放/暂停按钮、底部、弹幕、画面。对应的区域控件只能写在对应的区域,
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/black">
<RelativeLayout
android:id="@+id/surface_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
<ImageView
android:id="@+id/thumbImage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop" />
</RelativeLayout>
//弹幕控件(可直接使用)
<master.flame.danmaku.ui.widget.DanmakuView
android:id="@+id/danmaku_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/layout_bottom" />
<RelativeLayout
android:id="@+id/thumb"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:background="#000000"
android:scaleType="fitCenter">
</RelativeLayout>
//底部区域(底部区域有分成两层,一层进度条,一层播放控制)
<LinearLayout
android:id="@+id/layout_bottom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="center_vertical"
android:orientation="vertical">
<LinearLayout
android:id="@+id/seekbar"
android:layout_width="match_parent"
android:layout_height="35dp"
android:gravity="center_vertical"
android:orientation="horizontal"
android:paddingLeft="@dimen/dp_10"
android:paddingRight="@dimen/dp_10">
<ImageView
android:id="@+id/Video_SeekBar_play"
android:layout_width="@dimen/dp_24"
android:layout_height="@dimen/dp_24"
android:src="@mipmap/play"
android:visibility="gone" />
<SeekBar
android:id="@+id/progress"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1.0"
android:background="@null"
android:max="100"
android:maxHeight="4dp"
android:minHeight="4dp"
android:paddingTop="8dp"
android:paddingBottom="8dp"
android:progressDrawable="@drawable/seekbar_color"
android:thumb="@mipmap/seekbar_img" />
<ImageView
android:id="@+id/fullscreen"
android:layout_width="@dimen/dp_24"
android:layout_height="@dimen/dp_24"
android:layout_marginLeft="@dimen/dp_5"
android:layout_marginRight="@dimen/dp_5"
android:scaleType="center"
android:src="@drawable/crop_free_24" />
</LinearLayout>
<LinearLayout
android:id="@+id/Bottom_controller"
android:layout_width="match_parent"
android:layout_height="25dp"
android:layout_gravity="center"
android:layout_marginBottom="@dimen/dp_10"
android:orientation="horizontal"
android:paddingLeft="@dimen/dp_10"
android:paddingRight="@dimen/dp_10">
<ImageView
android:id="@+id/Video_play"
android:layout_width="@dimen/dp_24"
android:layout_height="@dimen/dp_24"
android:layout_marginLeft="@dimen/dp_8"
android:src="@mipmap/play" />
<ImageView
android:layout_width="@dimen/dp_24"
android:layout_height="@dimen/dp_24"
android:layout_marginLeft="@dimen/dp_10"
android:src="@drawable/skip_next_24" />
<TextView
android:id="@+id/current"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/dp_10"
android:text="00:00"
android:textColor="#ffffff" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:text="/"
android:textColor="#ffffff" />
<TextView
android:id="@+id/total"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="@dimen/dp_10"
android:text="00:00"
android:textColor="#ffffff" />
<ImageView
android:id="@+id/definition_off"
android:layout_width="50dp"
android:layout_height="match_parent"
android:gravity="center"
android:src="@mipmap/definition" />
<com.gcssloop.widget.RCRelativeLayout
android:id="@+id/Re_video_cover"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
app:round_corner="5dp">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:alpha="0.3"
android:src="#fff" />
<TextView
android:id="@+id/send_danmaku"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerVertical="true"
android:layout_marginLeft="@dimen/dp_20"
android:gravity="center|left"
android:paddingLeft="@dimen/dp_5"
android:text="@string/BulletScreenTips"
android:textColor="#b1b0b5" />
</com.gcssloop.widget.RCRelativeLayout>
<TextView
android:id="@+id/Double_speed"
android:layout_width="50dp"
android:layout_height="match_parent"
android:layout_marginLeft="20dp"
android:gravity="center"
android:text="@string/DoubleSpeed"
android:textColor="#ffffff" />
<TextView
android:id="@+id/definition"
android:layout_width="50dp"
android:layout_height="match_parent"
android:layout_marginLeft="20dp"
android:gravity="center"
android:textColor="#ffffff" />
</LinearLayout>
</LinearLayout>
<ProgressBar
android:id="@+id/bottom_progressbar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="1.5dp"
android:layout_alignParentBottom="true"
android:max="100"
android:progressDrawable="@drawable/video_progress" />
<ImageView
android:id="@+id/back_tiny"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginLeft="6dp"
android:layout_marginTop="6dp"
android:visibility="gone" />
//顶部区域(相应的控件只能写在名为layout_top的父布局下面)
<RelativeLayout
android:id="@+id/layout_top"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/video_title_bg"
android:gravity="center_vertical">
<RelativeLayout
android:id="@+id/first_floor"
android:layout_width="match_parent"
android:layout_height="@dimen/dp_48">
<ImageView
android:id="@+id/back"
android:layout_width="48dp"
android:layout_height="48dp"
android:paddingLeft="10dp"
android:scaleType="centerInside"
android:src="@drawable/video_back" />
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="@+id/back"
android:paddingLeft="10dp"
android:textColor="@android:color/white"
android:textSize="18sp" />
<LinearLayout
android:id="@+id/Sanlians"
android:layout_marginEnd="@dimen/dp_15"
android:layout_centerVertical="true"
android:layout_alignParentEnd="true"
android:gravity="right|center_vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="@+id/Dm_like"
android:layout_width="@dimen/dp_24"
android:layout_height="@dimen/dp_24"
android:src="@mipmap/like_while"/>
<ImageView
android:id="@+id/Dm_coin"
android:layout_marginLeft="@dimen/dp_15"
android:layout_width="@dimen/dp_24"
android:layout_height="@dimen/dp_24"
android:src="@mipmap/coin_while"/>
<ImageView
android:id="@+id/Dm_forward"
android:layout_marginLeft="@dimen/dp_15"
android:layout_width="@dimen/dp_24"
android:layout_height="@dimen/dp_24"
android:src="@mipmap/forward_while"/>
<ImageView
android:id="@+id/Dm_more"
android:layout_marginLeft="@dimen/dp_20"
android:layout_width="@dimen/dp_24"
android:layout_height="@dimen/dp_24"
android:src="@drawable/more_vert_24"/>
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:id="@+id/UPImage"
android:layout_width="@dimen/dp_120"
android:layout_height="@dimen/dp_30"
android:layout_below="@+id/first_floor"
android:layout_marginLeft="@dimen/dp_20">
<ImageView
android:alpha="0.5"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/file_background_circular_grey"/>
<com.android.liuzhuang.rcimageview.CircleImageView
android:id="@+id/up_img"
android:layout_width="@dimen/dp_30"
android:layout_height="@dimen/dp_30" />
<TextView
android:id="@+id/up_name"
android:layout_centerVertical="true"
android:gravity="center_vertical"
android:paddingRight="@dimen/dp_10"
android:text="UP主名称"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
android:layout_toRightOf="@+id/up_img"
android:textColor="@color/White"
android:textSize="16sp" />
</RelativeLayout>
</RelativeLayout>
<moe.codeest.enviews.ENDownloadView
android:id="@+id/loading"
android:layout_width="28dp"
android:layout_height="28dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:visibility="invisible" />
<moe.codeest.enviews.ENPlayView
android:id="@+id/start"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_gravity="center_vertical" />
<ImageView
android:id="@+id/small_close"
android:layout_width="30dp"
android:layout_height="30dp"
android:paddingLeft="10dp"
android:paddingTop="10dp"
android:scaleType="centerInside"
android:src="@drawable/video_small_close"
android:visibility="gone" />
<ImageView
android:id="@+id/lock_screen"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="50dp"
android:scaleType="centerInside"
android:src="@drawable/unlock"
android:visibility="gone" />
//小图预览
<RelativeLayout
android:id="@+id/preview_layout"
android:layout_width="@dimen/seek_bar_image"
android:layout_height="100dp"
android:layout_above="@+id/layout_bottom"
android:visibility="gone">
<ImageView
android:id="@+id/preview_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000" />
</RelativeLayout>
</RelativeLayout>
否则后期无法控制隐藏与显示。