-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGaoxiaoVideo.java
275 lines (230 loc) · 12.3 KB
/
GaoxiaoVideo.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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
package cn.buildworld.ahlive.fragment;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.RotateAnimation;
import com.alibaba.fastjson.JSON;
import java.util.List;
import cn.buildworld.ahlive.R;
import cn.buildworld.ahlive.adapter.FunVideoAdapter;
import cn.buildworld.ahlive.bean.funvideo.FunVideoBean;
import cn.buildworld.ahlive.utils.net.MyCallBack;
import cn.buildworld.ahlive.utils.MyDecoration;
import cn.buildworld.ahlive.utils.StandardVideoPlayer;
import cn.buildworld.ahlive.utils.net.XUtils;
import cn.sharesdk.onekeyshare.OnekeyShare;
import fm.jiecao.jcvideoplayer_lib.JCMediaManager;
import fm.jiecao.jcvideoplayer_lib.JCVideoPlayer;
/**
* 作者:MiChong on 2017/7/12 0012 20:16
* 邮箱:[email protected]
*/
public class GaoxiaoVideo extends BaseFragment {
private SwipeRefreshLayout mSwipeRefreshLayout;
private RecyclerView mRecyclerView;
private String TAG = "搞笑视频:";
private FloatingActionButton mActionButton;
private Animation mAnimation;
private String mFunVedio;
private long min_time = 0;
private FunVideoAdapter mFunVideoAdapter;
private FunVideoBean.DataBeanX mData;
private List<FunVideoBean.DataBeanX.DataBean> mDataBeen;
private String mShare_url;
private String mImgUrl;
private String mText;
public static GaoxiaoVideo newInstance(){
return new GaoxiaoVideo();
}
@Override
public View initView() {
View view = View.inflate(getActivity(), R.layout.fm_gaoxiaovideo,null);
mActionButton = (FloatingActionButton) view.findViewById(R.id.funvideo_floatbutton);
mRecyclerView = (RecyclerView) view.findViewById(R.id.gxvideo_recyclerview);
mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false));
mRecyclerView.addItemDecoration(new MyDecoration(getActivity(), MyDecoration.VERTICAL_LIST));
mSwipeRefreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.gx_swiperefresh);
mActionButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
getData();
}
});
mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
private int _firstItemPosition = -1, _lastItemPosition;
private View fistView, lastView;
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
}
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
//判断是当前layoutManager是否为LinearLayoutManager
// 只有LinearLayoutManager才有查找第一个和最后一个可见view位置的方法
if (layoutManager instanceof LinearLayoutManager) {
LinearLayoutManager linearManager = (LinearLayoutManager) layoutManager;
//获取最后一个可见view的位置
int lastItemPosition = linearManager.findLastVisibleItemPosition();
//获取第一个可见view的位置
int firstItemPosition = linearManager.findFirstVisibleItemPosition();
//获取可见view的总数
int visibleItemCount = linearManager.getChildCount();
if (_firstItemPosition < firstItemPosition) {
Log.i(TAG, "onScrolled: "+"视频划上去了");
_firstItemPosition = firstItemPosition;
_lastItemPosition = lastItemPosition;
GCView(fistView);
fistView = recyclerView.getChildAt(0);
lastView = recyclerView.getChildAt(visibleItemCount - 1);
} else if (_lastItemPosition > lastItemPosition) {
Log.i(TAG, "onScrolled: "+"视频划下去了");
_firstItemPosition = firstItemPosition;
_lastItemPosition = lastItemPosition;
GCView(lastView);
fistView = recyclerView.getChildAt(0);
lastView = recyclerView.getChildAt(visibleItemCount - 1);
}else if (_firstItemPosition > firstItemPosition){
Log.i(TAG, "onScrolled: "+"视频从上滑倒下了");
_firstItemPosition = firstItemPosition;
_lastItemPosition = lastItemPosition;
ResumeView(fistView);
fistView = recyclerView.getChildAt(0);
lastView = recyclerView.getChildAt(visibleItemCount - 1);
}else if (_lastItemPosition < lastItemPosition){
_firstItemPosition = firstItemPosition;
_lastItemPosition = lastItemPosition;
Log.i(TAG, "onScrolled: "+"视频从下滑倒上了");
ResumeView(lastView);
fistView = recyclerView.getChildAt(0);
lastView = recyclerView.getChildAt(visibleItemCount - 1);
}
}
}
/**
* 回收播放
* @param gcView
*/
public void GCView(View gcView) {
if (gcView != null && gcView.findViewById(R.id.JCVideoPlayerStandard) != null) {
StandardVideoPlayer video = (StandardVideoPlayer) gcView
.findViewById(R.id.JCVideoPlayerStandard);
if (video != null
&& (video.currentState == JCVideoPlayer.CURRENT_STATE_PLAYING || video.currentState == JCVideoPlayer.CURRENT_STATE_ERROR)) {
video.setSystemUiVisibility(JCVideoPlayer.CURRENT_STATE_AUTO_COMPLETE);
JCMediaManager.instance().mediaPlayer.pause();
}
}
}
/**
* 恢复播放
* @param gcView
*/
public void ResumeView(View gcView) {
if (gcView != null && gcView.findViewById(R.id.JCVideoPlayerStandard) != null) {
StandardVideoPlayer video = (StandardVideoPlayer) gcView
.findViewById(R.id.JCVideoPlayerStandard);
if (video != null
&& (video.currentState == JCVideoPlayer.CURRENT_STATE_PLAYING || video.currentState == JCVideoPlayer.CURRENT_STATE_ERROR)) {
video.setSystemUiVisibility(JCVideoPlayer.CURRENT_STATE_AUTO_COMPLETE);
JCMediaManager.instance().mediaPlayer.start();
}
}
}
});
getData();
return view;
}
@Override
public View initData() {
return null;
}
private void getData() {
//悬浮按钮刷新
mAnimation = new RotateAnimation(0.0f,+720f, Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f);
mAnimation.setDuration(800);
mAnimation.setFillAfter(true);
mActionButton.setAnimation(mAnimation);
//数据刷新
mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
getData();
mSwipeRefreshLayout.setRefreshing(false);
}
});
//释放所有的视频
StandardVideoPlayer.releaseAllVideos();
long millis = System.currentTimeMillis();
if (min_time == 0) {
mFunVedio = "http://iu.snssdk.com/neihan/stream/mix/v1/?mpic=one&webp=one&essence=one&content_type=-104&message_cursor=-one&am_loc_time=" + millis + "&count=30&min_time="+millis+"&screen_width=1450&do00le_col_mode=0&iid=3216590132&device_id=32613520945&ac=wifi&channel=360&aid=7&app_name=joke_essay&version_code=612&version_name=6.one.2&device_platform=android&ssmix=a&device_type=sansung&device_brand=xiaomi&os_api=28&os_version=6.10.one&uuid=326135942187625&openudid=3dg6s95rhg2a3dg5&manifest_version_code=612&resolution=1920*1080&dpi=620&update_version_code=6470";
}else {
mFunVedio = "http://iu.snssdk.com/neihan/stream/mix/v1/?mpic=one&webp=one&essence=one&content_type=-104&message_cursor=-one&am_loc_time=" + millis + "&count=30&min_time="+min_time+"&screen_width=1450&do00le_col_mode=0&iid=3216590132&device_id=32613520945&ac=wifi&channel=360&aid=7&app_name=joke_essay&version_code=612&version_name=6.one.2&device_platform=android&ssmix=a&device_type=sansung&device_brand=xiaomi&os_api=28&os_version=6.10.one&uuid=326135942187625&openudid=3dg6s95rhg2a3dg5&manifest_version_code=612&resolution=1920*1080&dpi=620&update_version_code=6470";
Log.i(TAG, "min_time"+min_time);
}
min_time = millis;
XUtils.Get(mFunVedio,null,new MyCallBack<String>(){
@Override
public void onSuccess(String result) {
super.onSuccess(result);
Log.i(TAG, "onSuccess: "+result);
com.alibaba.fastjson.JSONObject jsonObject = JSON.parseObject(result);
mData = jsonObject.getObject("data", FunVideoBean.DataBeanX.class);
Log.i(TAG, "data:"+ mData.toString());
mDataBeen = mData.getData();
Log.i(TAG, "databean: "+ mDataBeen.size());
String mp4_url = mDataBeen.get(0).getGroup().getMp4_url();
Log.i(TAG, "mp4_url: "+mp4_url);
mFunVideoAdapter = new FunVideoAdapter(getContext(), mDataBeen);
mRecyclerView.setAdapter(mFunVideoAdapter);
mFunVideoAdapter.setOnImageShareListener(new FunVideoAdapter.OnImageShareListener() {
@Override
public void OnClick(View view, int position) {
mShare_url = mDataBeen.get(position).getGroup().getShare_url();
mImgUrl = mDataBeen.get(position).getGroup().getLarge_cover().getUrl_list().get(0).getUrl();
mText = mDataBeen.get(position).getGroup().getText();
showShare();
}
});
}
@Override
public void onError(Throwable ex, boolean isOnCallback) {
super.onError(ex, isOnCallback);
}
@Override
public void onFinished() {
super.onFinished();
}
});
}
private void showShare() {
OnekeyShare oks = new OnekeyShare();
//关闭sso授权
oks.disableSSOWhenAuthorize();
// 分享时Notification的图标和文字 2.5.9以后的版本不 调用此方法
//oks.setNotification(R.drawable.ic_launcher, getString(R.string.app_name));
// title标题,印象笔记、邮箱、信息、微信、人人网和QQ空间使用
oks.setTitle(mText);
// titleUrl是标题的网络链接,仅在人人网和QQ空间使用
oks.setTitleUrl(mShare_url);
// text是分享文本,所有平台都需要这个字段
oks.setText("内涵段子搞笑视频");
// imagePath是图片的本地路径,Linked-In以外的平台都支持此参数
oks.setImageUrl(mImgUrl);//确保SDcard下面存在此张图片
// url仅在微信(包括好友和朋友圈)中使用
oks.setUrl(mShare_url);
// comment是我对这条分享的评论,仅在人人网和QQ空间使用
oks.setComment(mText);
// site是分享此内容的网站名称,仅在QQ空间使用
oks.setSite(getString(R.string.app_name));
// siteUrl是分享此内容的网站地址,仅在QQ空间使用
oks.setSiteUrl(mShare_url);
// 启动分享GUI
oks.show(getActivity());
}
}