-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
SampleCoverVideo.java
256 lines (215 loc) · 8.1 KB
/
SampleCoverVideo.java
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
package com.example.gsyvideoplayer.video;
import android.content.Context;
import android.graphics.Point;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.Surface;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.ImageView;
import android.widget.SeekBar;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.example.gsyvideoplayer.R;
import com.shuyu.gsyvideoplayer.utils.CommonUtil;
import com.shuyu.gsyvideoplayer.utils.Debuger;
import com.shuyu.gsyvideoplayer.utils.GSYVideoType;
import com.shuyu.gsyvideoplayer.video.StandardGSYVideoPlayer;
import com.shuyu.gsyvideoplayer.video.base.GSYBaseVideoPlayer;
/**
* 带封面
* Created by guoshuyu on 2017/9/3.
*/
public class SampleCoverVideo extends StandardGSYVideoPlayer {
ImageView mCoverImage;
String mCoverOriginUrl;
int mCoverOriginId = 0;
int mDefaultRes;
public SampleCoverVideo(Context context, Boolean fullFlag) {
super(context, fullFlag);
}
public SampleCoverVideo(Context context) {
super(context);
}
public SampleCoverVideo(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void init(Context context) {
super.init(context);
mCoverImage = (ImageView) findViewById(R.id.thumbImage);
if (mThumbImageViewLayout != null &&
(mCurrentState == -1 || mCurrentState == CURRENT_STATE_NORMAL || mCurrentState == CURRENT_STATE_ERROR)) {
mThumbImageViewLayout.setVisibility(VISIBLE);
}
}
@Override
public int getLayoutId() {
return R.layout.video_layout_cover;
}
public void loadCoverImage(String url, int res) {
mCoverOriginUrl = url;
mDefaultRes = res;
Glide.with(getContext().getApplicationContext())
.setDefaultRequestOptions(
new RequestOptions()
.frame(1000000)
.centerCrop()
.error(res)
.placeholder(res))
.load(url)
.into(mCoverImage);
}
public void loadCoverImageBy(int id, int res) {
mCoverOriginId = id;
mDefaultRes = res;
mCoverImage.setImageResource(id);
}
@Override
public GSYBaseVideoPlayer startWindowFullscreen(Context context, boolean actionBar, boolean statusBar) {
GSYBaseVideoPlayer gsyBaseVideoPlayer = super.startWindowFullscreen(context, actionBar, statusBar);
SampleCoverVideo sampleCoverVideo = (SampleCoverVideo) gsyBaseVideoPlayer;
if(mCoverOriginUrl != null) {
sampleCoverVideo.loadCoverImage(mCoverOriginUrl, mDefaultRes);
} else if(mCoverOriginId != 0) {
sampleCoverVideo.loadCoverImageBy(mCoverOriginId, mDefaultRes);
}
return gsyBaseVideoPlayer;
}
@Override
public GSYBaseVideoPlayer showSmallVideo(Point size, boolean actionBar, boolean statusBar) {
//下面这里替换成你自己的强制转化
SampleCoverVideo sampleCoverVideo = (SampleCoverVideo) super.showSmallVideo(size, actionBar, statusBar);
sampleCoverVideo.mStartButton.setVisibility(GONE);
sampleCoverVideo.mStartButton = null;
return sampleCoverVideo;
}
@Override
protected void cloneParams(GSYBaseVideoPlayer from, GSYBaseVideoPlayer to) {
super.cloneParams(from, to);
SampleCoverVideo sf = (SampleCoverVideo) from;
SampleCoverVideo st = (SampleCoverVideo) to;
st.mShowFullAnimation = sf.mShowFullAnimation;
}
/**
* 退出window层播放全屏效果
*/
@SuppressWarnings("ResourceType")
@Override
protected void clearFullscreenLayout() {
if (!mFullAnimEnd) {
return;
}
mIfCurrentIsFullscreen = false;
int delay = 0;
// ------- !!!如果不需要旋转屏幕,可以不调用!!!-------
// 不需要屏幕旋转,还需要设置 setNeedOrientationUtils(false)
if (mOrientationUtils != null) {
delay = mOrientationUtils.backToProtVideo();
mOrientationUtils.setEnable(false);
if (mOrientationUtils != null) {
mOrientationUtils.releaseListener();
mOrientationUtils = null;
}
}
if (!mShowFullAnimation) {
delay = 0;
}
final ViewGroup vp = (CommonUtil.scanForActivity(getContext())).findViewById(Window.ID_ANDROID_CONTENT);
final View oldF = vp.findViewById(getFullId());
if (oldF != null) {
//此处fix bug#265,推出全屏的时候,虚拟按键问题
SampleCoverVideo gsyVideoPlayer = (SampleCoverVideo) oldF;
gsyVideoPlayer.mIfCurrentIsFullscreen = false;
}
if (delay == 0) {
backToNormal();
} else {
postDelayed(new Runnable() {
@Override
public void run() {
backToNormal();
}
}, delay);
}
}
/******************* 下方两个重载方法,在播放开始前不屏蔽封面,不需要可屏蔽 ********************/
@Override
public void onSurfaceUpdated(Surface surface) {
super.onSurfaceUpdated(surface);
if (mThumbImageViewLayout != null && mThumbImageViewLayout.getVisibility() == VISIBLE) {
mThumbImageViewLayout.setVisibility(INVISIBLE);
}
}
@Override
protected void setViewShowState(View view, int visibility) {
if (view == mThumbImageViewLayout && visibility != VISIBLE) {
return;
}
super.setViewShowState(view, visibility);
}
@Override
public void onSurfaceAvailable(Surface surface) {
super.onSurfaceAvailable(surface);
if (GSYVideoType.getRenderType() != GSYVideoType.TEXTURE) {
if (mThumbImageViewLayout != null && mThumbImageViewLayout.getVisibility() == VISIBLE) {
mThumbImageViewLayout.setVisibility(INVISIBLE);
}
}
}
/******************* 下方重载方法,在播放开始不显示底部进度和按键,不需要可屏蔽 ********************/
protected boolean byStartedClick;
@Override
protected void onClickUiToggle(MotionEvent e) {
if (mIfCurrentIsFullscreen && mLockCurScreen && mNeedLockFull) {
setViewShowState(mLockScreen, VISIBLE);
return;
}
byStartedClick = true;
super.onClickUiToggle(e);
}
@Override
protected void changeUiToNormal() {
super.changeUiToNormal();
byStartedClick = false;
}
@Override
protected void changeUiToPreparingShow() {
super.changeUiToPreparingShow();
Debuger.printfLog("Sample changeUiToPreparingShow");
setViewShowState(mBottomContainer, INVISIBLE);
setViewShowState(mStartButton, INVISIBLE);
}
@Override
protected void changeUiToPlayingBufferingShow() {
super.changeUiToPlayingBufferingShow();
Debuger.printfLog("Sample changeUiToPlayingBufferingShow");
if (!byStartedClick) {
setViewShowState(mBottomContainer, INVISIBLE);
setViewShowState(mStartButton, INVISIBLE);
}
}
@Override
protected void changeUiToPlayingShow() {
super.changeUiToPlayingShow();
Debuger.printfLog("Sample changeUiToPlayingShow");
if (!byStartedClick) {
setViewShowState(mBottomContainer, INVISIBLE);
setViewShowState(mStartButton, INVISIBLE);
}
}
@Override
public void startAfterPrepared() {
super.startAfterPrepared();
Debuger.printfLog("Sample startAfterPrepared");
setViewShowState(mBottomContainer, INVISIBLE);
setViewShowState(mStartButton, INVISIBLE);
setViewShowState(mBottomProgressBar, VISIBLE);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
byStartedClick = true;
super.onStartTrackingTouch(seekBar);
}
}