use of fm.jiecao.jcvideoplayer_lib.JCVideoPlayer in project AndroidNews by zhjohow.
the class VideosFragment method initView.
@Override
protected void initView() {
if (getArguments() != null) {
mVideoType = getArguments().getString(AppConstant.VIDEO_TYPE);
}
irc.setLayoutManager(new LinearLayoutManager(getContext()));
videoListAdapter = new CommonRecycleViewAdapter<VideoData>(getContext(), R.layout.item_video_list) {
@Override
public void convert(ViewHolderHelper helper, VideoData videoData) {
helper.setImageRoundUrl(R.id.iv_logo, videoData.getTopicImg());
helper.setText(R.id.tv_from, videoData.getTopicName());
helper.setText(R.id.tv_play_time, String.format(getResources().getString(R.string.video_play_times), String.valueOf(videoData.getPlayCount())));
JCVideoPlayerStandard jcVideoPlayerStandard = helper.getView(R.id.videoplayer);
boolean setUp = jcVideoPlayerStandard.setUp(videoData.getMp4_url(), JCVideoPlayer.SCREEN_LAYOUT_LIST, TextUtils.isEmpty(videoData.getDescription()) ? videoData.getTitle() + "" : videoData.getDescription());
if (setUp) {
Glide.with(mContext).load(videoData.getCover()).diskCacheStrategy(DiskCacheStrategy.ALL).centerCrop().error(com.zhjh.common.R.drawable.ic_empty_picture).crossFade().into(jcVideoPlayerStandard.thumbImageView);
}
}
};
irc.setAdapter(videoListAdapter);
irc.setOnRefreshListener(this);
irc.setOnLoadMoreListener(this);
// 视频监听
irc.addOnChildAttachStateChangeListener(new RecyclerView.OnChildAttachStateChangeListener() {
@Override
public void onChildViewAttachedToWindow(View view) {
}
@Override
public void onChildViewDetachedFromWindow(View view) {
if (JCVideoPlayerManager.listener() != null) {
JCVideoPlayer videoPlayer = (JCVideoPlayer) JCVideoPlayerManager.listener();
if (((ViewGroup) view).indexOfChild(videoPlayer) != -1 && videoPlayer.currentState == JCVideoPlayer.CURRENT_STATE_PLAYING) {
JCVideoPlayer.releaseAllVideos();
}
}
}
});
// 数据为空才重新发起请求
if (videoListAdapter.getSize() <= 0) {
// 发起请求
mStartPage = 0;
mPresenter.getVideosListDataRequest(mVideoType, mStartPage);
}
}
Aggregations