-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Expand file tree
/
Copy pathWebDetailActivity.java
More file actions
172 lines (138 loc) · 5.81 KB
/
WebDetailActivity.java
File metadata and controls
172 lines (138 loc) · 5.81 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
package com.example.gsyvideoplayer;
import android.graphics.Point;
import android.os.Bundle;
import androidx.core.widget.NestedScrollView;
import android.view.View;
import android.webkit.WebSettings;
import android.widget.ImageView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.example.gsyvideoplayer.databinding.ActivityWebDetailBinding;
import com.shuyu.gsyvideoplayer.GSYBaseActivityDetail;
import com.shuyu.gsyvideoplayer.builder.GSYVideoOptionBuilder;
import com.shuyu.gsyvideoplayer.utils.GSYVideoType;
import com.shuyu.gsyvideoplayer.video.StandardGSYVideoPlayer;
import com.shuyu.gsyvideoplayer.listener.LockClickListener;
import com.shuyu.gsyvideoplayer.utils.CommonUtil;
/**
* Created by shuyu on 2016/12/26.
*/
public class WebDetailActivity extends GSYBaseActivityDetail<StandardGSYVideoPlayer> {
private boolean isSmall;
private int backupRendType;
private ActivityWebDetailBinding binding;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = ActivityWebDetailBinding.inflate(getLayoutInflater());
View rootView = binding.getRoot();
setContentView(rootView);
backupRendType = GSYVideoType.getRenderType();
//设置为Surface播放模式,注意此设置是全局的
GSYVideoType.setRenderType(GSYVideoType.SUFRACE);
resolveNormalVideoUI();
initVideoBuilderMode();
binding.webPlayer.setLockClickListener(new LockClickListener() {
@Override
public void onClick(View view, boolean lock) {
if (orientationUtils != null) {
//配合下方的onConfigurationChanged
orientationUtils.setEnable(!lock);
binding.webPlayer.getCurrentPlayer().setRotateViewAuto(!lock);
}
}
});
WebSettings settings = binding.scrollWebView.getSettings();
settings.setJavaScriptEnabled(true);
binding.scrollWebView.loadUrl("https://www.baidu.com");
orientationUtils.setRotateWithSystem(false);
binding.webTopLayout.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {
@Override
public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
if (!binding.webPlayer.isIfCurrentIsFullscreen() && scrollY >= 0 && isPlay) {
if (scrollY > binding.webPlayer.getHeight()) {
//如果是小窗口就不需要处理
if (!isSmall) {
isSmall = true;
int size = CommonUtil.dip2px(WebDetailActivity.this, 150);
binding.webPlayer.showSmallVideo(new Point(size, size), true, true);
orientationUtils.setEnable(false);
}
} else {
if (isSmall) {
isSmall = false;
orientationUtils.setEnable(true);
//必须
binding.webTopLayoutVideo.postDelayed(new Runnable() {
@Override
public void run() {
binding.webPlayer.hideSmallVideo();
}
}, 50);
}
}
binding.webTopLayoutVideo.setTranslationY((scrollY <= binding.webTopLayoutVideo.getHeight()) ? -scrollY : -binding.webTopLayoutVideo.getHeight());
}
}
});
}
@Override
protected void onDestroy() {
super.onDestroy();
//设置为GL播放模式,才能支持滤镜,注意此设置是全局的
GSYVideoType.setRenderType(backupRendType);
}
@Override
public StandardGSYVideoPlayer getGSYVideoPlayer() {
return binding.webPlayer;
}
@Override
public GSYVideoOptionBuilder getGSYVideoOptionBuilder() {
String url = "https://www.w3schools.com/html/mov_bbb.mp4";
//String url = "https://d131x7vzzf85jg.cloudfront.net/upload/documents/paper/b2/61/00/00/20160420_115018_b544.mp4";
//增加封面。内置封面可参考SampleCoverVideo
ImageView imageView = new ImageView(this);
loadCover(imageView, url);
return new GSYVideoOptionBuilder()
.setThumbImageView(imageView)
.setUrl(url)
.setCacheWithPlay(false)
.setRotateWithSystem(false)
.setVideoTitle("测试视频")
.setIsTouchWiget(true)
.setRotateViewAuto(false)
.setLockLand(false)
.setShowFullAnimation(false)
.setNeedLockFull(true);
}
@Override
public void clickForFullScreen() {
}
/**
* 是否启动旋转横屏,true表示启动
*
* @return true
*/
@Override
public boolean getDetailOrientationRotateAuto() {
return true;
}
private void loadCover(ImageView imageView, String url) {
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setImageResource(R.mipmap.xxx1);
Glide.with(this.getApplicationContext())
.setDefaultRequestOptions(
new RequestOptions()
.frame(3000000)
.centerCrop()
.error(R.mipmap.xxx2)
.placeholder(R.mipmap.xxx1))
.load(url)
.into(imageView);
}
private void resolveNormalVideoUI() {
//增加title
binding.webPlayer.getTitleTextView().setVisibility(View.GONE);
binding.webPlayer.getBackButton().setVisibility(View.GONE);
}
}