Repository navigation
Expand file tree
/
Copy pathSampleControlVideo.java
More file actions
265 lines (234 loc) · 8.15 KB
/
Copy pathSampleControlVideo.java
File metadata and controls
265 lines (234 loc) · 8.15 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
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
package com.example.gsyvideoplayer.video;
import android.content.Context;
import android.graphics.Matrix;
import android.util.AttributeSet;
import android.view.Surface;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.example.gsyvideoplayer.R;
import com.shuyu.gsyvideoplayer.utils.GSYVideoType;
import com.shuyu.gsyvideoplayer.video.StandardGSYVideoPlayer;
import com.shuyu.gsyvideoplayer.video.base.GSYBaseVideoPlayer;
import com.shuyu.gsyvideoplayer.video.base.GSYVideoPlayer;
/**
* Created by shuyu on 2016/12/7.
* 注意
* 这个播放器的demo配置切换到全屏播放器
* 这只是单纯的作为全屏播放显示,如果需要做大小屏幕切换,请记得在这里耶设置上视频全屏的需要的自定义配置
*/
public class SampleControlVideo extends StandardGSYVideoPlayer {
private TextView mMoreScale;
private TextView mChangeRotate;
private TextView mChangeTransform;
//记住切换数据源类型
private int mType = 0;
private int mTransformSize = 0;
//数据源
private int mSourcePosition = 0;
/**
* 1.5.0开始加入,如果需要不同布局区分功能,需要重载
*/
public SampleControlVideo(Context context, Boolean fullFlag) {
super(context, fullFlag);
}
public SampleControlVideo(Context context) {
super(context);
}
public SampleControlVideo(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void init(Context context) {
super.init(context);
initView();
}
private void initView() {
mMoreScale = (TextView) findViewById(R.id.moreScale);
mChangeRotate = (TextView) findViewById(R.id.change_rotate);
mChangeTransform = (TextView) findViewById(R.id.change_transform);
//切换清晰度
mMoreScale.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (!mHadPlay) {
return;
}
if (mType == 0) {
mType = 1;
} else if (mType == 1) {
mType = 2;
} else if (mType == 2) {
mType = 3;
} else if (mType == 3) {
mType = 4;
} else if (mType == 4) {
mType = 0;
}
resolveTypeUI();
}
});
//旋转播放角度
mChangeRotate.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (!mHadPlay) {
return;
}
if ((mTextureView.getRotation() - mRotate) == 270) {
mTextureView.setRotation(mRotate);
mTextureView.requestLayout();
} else {
mTextureView.setRotation(mTextureView.getRotation() + 90);
mTextureView.requestLayout();
}
}
});
//镜像旋转
mChangeTransform.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (!mHadPlay) {
return;
}
if (mTransformSize == 0) {
mTransformSize = 1;
} else if (mTransformSize == 1) {
mTransformSize = 2;
} else if (mTransformSize == 2) {
mTransformSize = 0;
}
resolveTransform();
}
});
}
@Override
public void onSurfaceSizeChanged(Surface surface, int width, int height) {
super.onSurfaceSizeChanged(surface, width, height);
resolveTransform();
}
/**
* 处理显示逻辑
*/
@Override
public void onSurfaceAvailable(Surface surface) {
super.onSurfaceAvailable(surface);
resolveRotateUI();
resolveTransform();
}
/**
* 处理镜像旋转
* 注意,暂停时
*/
protected void resolveTransform() {
switch (mTransformSize) {
case 1: {
Matrix transform = new Matrix();
transform.setScale(-1, 1, mTextureView.getWidth() / 2, 0);
mTextureView.setTransform(transform);
mChangeTransform.setText("左右镜像");
mTextureView.invalidate();
}
break;
case 2: {
Matrix transform = new Matrix();
transform.setScale(1, -1, 0, mTextureView.getHeight() / 2);
mTextureView.setTransform(transform);
mChangeTransform.setText("上下镜像");
mTextureView.invalidate();
}
break;
case 0: {
Matrix transform = new Matrix();
transform.setScale(1, 1, mTextureView.getWidth() / 2, 0);
mTextureView.setTransform(transform);
mChangeTransform.setText("旋转镜像");
mTextureView.invalidate();
}
break;
}
}
@Override
public int getLayoutId() {
return R.layout.sample_video;
}
/**
* 全屏时将对应处理参数逻辑赋给全屏播放器
*
* @param context
* @param actionBar
* @param statusBar
* @return
*/
@Override
public GSYBaseVideoPlayer startWindowFullscreen(Context context, boolean actionBar, boolean statusBar) {
SampleControlVideo sampleVideo = (SampleControlVideo) super.startWindowFullscreen(context, actionBar, statusBar);
sampleVideo.mSourcePosition = mSourcePosition;
sampleVideo.mType = mType;
sampleVideo.mTransformSize = mTransformSize;
//sampleVideo.resolveTransform();
sampleVideo.resolveTypeUI();
//sampleVideo.resolveRotateUI();
//这个播放器的demo配置切换到全屏播放器
//这只是单纯的作为全屏播放显示,如果需要做大小屏幕切换,请记得在这里耶设置上视频全屏的需要的自定义配置
//比如已旋转角度之类的等等
//可参考super中的实现
return sampleVideo;
}
/**
* 推出全屏时将对应处理参数逻辑返回给非播放器
*
* @param oldF
* @param vp
* @param gsyVideoPlayer
*/
@Override
protected void resolveNormalVideoShow(View oldF, ViewGroup vp, GSYVideoPlayer gsyVideoPlayer) {
super.resolveNormalVideoShow(oldF, vp, gsyVideoPlayer);
if (gsyVideoPlayer != null) {
SampleControlVideo sampleVideo = (SampleControlVideo) gsyVideoPlayer;
mSourcePosition = sampleVideo.mSourcePosition;
mType = sampleVideo.mType;
mTransformSize = sampleVideo.mTransformSize;
resolveTypeUI();
}
}
/**
* 旋转逻辑
*/
private void resolveRotateUI() {
if (!mHadPlay) {
return;
}
mTextureView.setRotation(mRotate);
mTextureView.requestLayout();
}
/**
* 显示比例
* 注意,GSYVideoType.setShowType是全局静态生效,除非重启APP。
*/
private void resolveTypeUI() {
if (!mHadPlay) {
return;
}
if (mType == 1) {
mMoreScale.setText("16:9");
GSYVideoType.setShowType(GSYVideoType.SCREEN_TYPE_16_9);
} else if (mType == 2) {
mMoreScale.setText("4:3");
GSYVideoType.setShowType(GSYVideoType.SCREEN_TYPE_4_3);
} else if (mType == 3) {
mMoreScale.setText("全屏");
GSYVideoType.setShowType(GSYVideoType.SCREEN_TYPE_FULL);
} else if (mType == 4) {
mMoreScale.setText("拉伸全屏");
GSYVideoType.setShowType(GSYVideoType.SCREEN_MATCH_FULL);
} else if (mType == 0) {
mMoreScale.setText("默认比例");
GSYVideoType.setShowType(GSYVideoType.SCREEN_TYPE_DEFAULT);
}
changeTextureViewShowType();
if (mTextureView != null)
mTextureView.requestLayout();
}
}