我点击RecyclerView任意一个item的播放按钮,始终都是第一个item播放,请问这个该怎么解决?视频播放用的是IjkPlayer,Adapter用的是BRVAH.
public class HomeFragment extends Fragment implements BaseQuickAdapter.OnItemChildClickListener {
@BindView(R.id.rv_home)
RecyclerView mRvHome;
private HomeAdapter homeAdapter;
private List<HomeListBean> mDatas;
private PlayerView player;
private Context mContext;
private List<VideoijkBean> list;
private PowerManager.WakeLock wakeLock;
View rootView;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
this.mContext = getActivity();
rootView = inflater.inflate(R.layout.fragment_home, null);
ButterKnife.bind(this, rootView);
initData();
initEvent();
return rootView;
}
private void initData() {
mDatas = new ArrayList<>();
HomeListBean bean;
for (int i = 0; i < 6; i++) {
bean = new HomeListBean();
bean.setTvHomeItemTitle("2018年德玛西亚冬季赛八强赛败者组决赛 第3场2018年德玛西亚第3场2018年德玛西亚第3场2018年德玛西亚");
bean.setBtnGameType("LOL");
bean.setTvType("解说");
bean.setTvYearType("2018德玛西亚杯");
bean.setTvVideoCount("555个视频");
bean.setImgUrl("http://pic2.nipic.com/20090413/406638_125424003_2.jpg");
mDatas.add(bean);
}
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity());
linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
mRvHome.setLayoutManager(linearLayoutManager);
mRvHome.addItemDecoration(new DividerItemDecoration(getActivity(), 1));
homeAdapter = new HomeAdapter(R.layout.item_home, mDatas, mContext);
mRvHome.setLayoutManager(new LinearLayoutManager(getActivity()));
}
private void initEvent() {
mRvHome.setAdapter(homeAdapter);
homeAdapter.setOnItemChildClickListener(this);
}
@Override
public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
Toast.makeText(mContext, "点击了第" + position + "个播放", Toast.LENGTH_SHORT).show();
/**虚拟按键的隐藏方法*/
rootView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
//比较Activity根布局与当前布局的大小
int heightDiff = rootView.getRootView().getHeight() - rootView.getHeight();
if (heightDiff > 100) {
//大小超过100时,一般为显示虚拟键盘事件
rootView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
} else {
//大小小于100时,为不显示虚拟键盘或虚拟键盘隐藏
rootView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
}
}
});
/**常亮*/
PowerManager pm = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
wakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "liveTAG");
wakeLock.acquire();
list = new ArrayList<>();
String url = "http://9890.vod.myqcloud.com/9890_9c1fa3e2aea011e59fc841df10c92278.f20.mp4";
// View itemView = View.inflate(mContext, R.layout.item_home, null);
player = new PlayerView(getActivity(), rootView) {
@Override
public PlayerView toggleProcessDurationOrientation() {
hideSteam(getScreenOrientation() == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
return setProcessDurationOrientation(getScreenOrientation() == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT ? PlayStateParams.PROCESS_PORTRAIT : PlayStateParams.PROCESS_LANDSCAPE);
}
@Override
public PlayerView setPlaySource(List<VideoijkBean> list) {
return super.setPlaySource(list);
}
};
player.setProcessDurationOrientation(PlayStateParams.PROCESS_PORTRAIT)
.setScaleType(PlayStateParams.fillparent)
.forbidTouch(false)
.hideSteam(true)
.hideCenterPlayer(true)
// .showThumbnail(new OnShowThumbnailListener() {
// @Override
// public void onShowThumbnail(ImageView ivThumbnail) {
// Glide.with(mContext)
// .load("http://pic2.nipic.com/20090413/406638_125424003_2.jpg")//默认封面
// .placeholder(R.mipmap.temp_home)
// .error(R.color.cl_error)
// .into(ivThumbnail);
// }
// })
.setPlaySource(url)//播放网络视频
.setChargeTie(false, 60).startPlay();// 手动设置暂停时间,true为需要收费(根据maxPlaytime自动暂停),false不收费(正常完整播放)
}
@Override
public void onPause() {
super.onPause();
if (player != null) {
player.onPause();
}
/**demo的内容,恢复系统其它媒体的状态*/
MediaUtils.muteAudioFocus(mContext, true);
}
@Override
public void onResume() {
super.onResume();
if (player != null) {
player.onResume();
}
/**demo的内容,暂停系统其它媒体的状态*/
MediaUtils.muteAudioFocus(mContext, false);
/**demo的内容,激活设备常亮状态*/
if (wakeLock != null) {
wakeLock.acquire();
}
}
@Override
public void onDestroy() {
super.onDestroy();
if (player != null) {
player.onDestroy();
}
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if (player != null) {
player.onConfigurationChanged(newConfig);
}
}
//TODO:Fragment监听返回按钮
// @Override
// public void onBackPressed() {
// if (player != null && player.onBackPressed()) {
// return;
// }
// super.onBackPressed();
// /**demo的内容,恢复设备亮度状态*/
// if (wakeLock != null) {
// wakeLock.release();
// }
// }
}
???然后咧?