上面是ijkplayer播放器,我添加的播放控制器比较丑,就不展示了,首页是一个轮播图加双RecyclerView的嵌套进行数据的一个展示,由于首页图片无法上传就不进行展示了。
先发一下首页的xml布局:
接下来是首页的一些数据展示:
package Frag;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ImageView;
import com.bigkoo.convenientbanner.ConvenientBanner;
import com.bigkoo.convenientbanner.holder.CBViewHolderCreator;
import com.bigkoo.convenientbanner.holder.Holder;
import com.bigkoo.convenientbanner.listener.OnItemClickListener;
import com.bumptech.glide.Glide;
import com.facebook.drawee.backends.pipeline.Fresco;
import com.facebook.drawee.view.SimpleDraweeView;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import Bean.RootBean;
import MyAdapters_List.FatherAdapter;
import Presenter.Data_Presenter;
import Views.IView;
import zhangtao.bwie.com.demo.MyRecy;
import zhangtao.bwie.com.demo.Player_activity;
import zhangtao.bwie.com.demo.R;
/**
* Created by ZhangTAO on 2017/12/14.
*/
public class Frag1 extends Fragment implements IView,OnItemClickListener{
private ConvenientBanner banner;
private EditText edit_sele;
private Data_Presenter data_presenter;
private List imglist = new ArrayList<>();
private List shareUrl = new ArrayList<>();
private List childList;
private List father_data = new ArrayList<>();
private ImageView imageView;
private MyRecy myrecy;
private FatherAdapter fatherAdapter;
private HashMap map;
private List zt_list;
private Handler ler = new Handler() {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
imglist.clear();
for(int i=0;i();
setPresenter("http://api.svipmovie.com/front/",map);
}
private void getinit() {
//开始自动翻页
banner.setPages(new CBViewHolderCreator() {
@Override
public NetWorkLoacl createHolder() {
return new NetWorkLoacl();
}
},imglist)
//设置指示器是否可见
.setPointViewVisible(true)
//设置自动切换(同时设置了切换时间间隔)
.startTurning(2000)
//设置两个点图片作为翻页指示器,不设置则没有指示器,可以根据自己需求自行配合自己的指示器,不需要圆点指示器可用不设
.setPageIndicator(new int[]{R.drawable.checked,R.drawable.kong})
//设置指示器的方向(左、中、右)
.setPageIndicatorAlign(ConvenientBanner.PageIndicatorAlign.CENTER_HORIZONTAL)
//设置点击监听事件
.setOnItemClickListener(this)
//设置手动影响(设置了该项无法手动切换)
.setManualPageable(true);
}
private void setPresenter(String baseurl, Map map) {
data_presenter = new Data_Presenter();
data_presenter.attach(this);
data_presenter.getData(baseurl,map);
}
private void initView(View v1) {
banner = v1.findViewById(R.id.banner);
edit_sele = v1.findViewById(R.id.select_edit);
myrecy = v1.findViewById(R.id.recy_view);
}
private void setMyadapters() {
fatherAdapter = new FatherAdapter(getContext(),father_data);
LinearLayoutManager manager = new LinearLayoutManager(getContext());
myrecy.setLayoutManager(manager);
myrecy.setAdapter(fatherAdapter);
}
@Override
public void onsuccess(Object o) {
if(o instanceof RootBean) {
RootBean bean = (RootBean) o;
if(bean != null) {
zt_list = bean.getRet().getList();
childList = zt_list.get(0).getChildList();
Log.d("zzz","总数据:"+childList.toString());
ler.sendMessage(new Message());
}
}
}
@Override
public void onfailed(Exception e) {
}
@Override
public void onItemClick(int position) {
Intent intent = new Intent(getActivity(), Player_activity.class);
String dataId = childList.get(position).getDataId();
intent.putExtra("key",dataId);
getContext().startActivity(intent);
}
public class NetWorkLoacl implements Holder {
@Override
public View createView(Context context) {
imageView = new ImageView(context);
imageView.setScaleType(SimpleDraweeView.ScaleType.FIT_XY);
return imageView;
}
@Override
public void UpdateUI(Context context, int position, String data) {
Glide.with(context).load(data).placeholder(R.mipmap.ic_launcher).into(imageView);
}
}
}
下来是播放器页面的xml布局:
package zhangtao.bwie.com.demo;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import Bean.VideoBean;
import Frag.Player1;
import Frag.Player2;
import ImmerSionUtil.ImmersionUtil;
import Presenter.Data_Presenter;
import Views.IView;
import tv.danmaku.ijk.media.player.IjkMediaPlayer;
import tv.danmaku.ijk.media.player.widget.IjkVideoView;
/**
* Created by ZhangTAO on 2017/12/15.
*/
public class Player_activity extends AppCompatActivity implements IView,View.OnClickListener{
private TabLayout tablayout;
private List textlist = new ArrayList<>();
private List fraglist = new ArrayList<>();
private HashMap map;
private String key;
private Data_Presenter data_presenter;
private VideoBean.RetBean ret;
private MyViewPager vps;
private TextView tit_movic;
private ImageView back_img;
private AndroidMediaController androidMediaController;
private boolean playstart;
private IjkVideoView ijkplayer;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.player_layout);
IjkMediaPlayer.loadLibrariesOnce(null);
IjkMediaPlayer.native_profileBegin("libijkplayer.so");
new ImmersionUtil().setImmersion(getWindow(),getSupportActionBar());
key = getIntent().getStringExtra("key");
map = new HashMap<>();
map.put("mediaId", key);
Log.d("mediaId", key);
initView();
init();
setOnclicked();
getinit();
tablayout.setupWithViewPager(vps);
setPresenter_Video("http://api.svipmovie.com/front/", map);
}
private void setOnclicked() {
back_img.setOnClickListener(this);
}
private void setPresenter_Video(String baseurl, Map map) {
data_presenter = new Data_Presenter();
data_presenter.attach(this);
data_presenter.getData(baseurl, map);
}
private void initView() {
ijkplayer = (IjkVideoView) findViewById(R.id.ijkplayer);
tablayout = (TabLayout) findViewById(R.id.tablayout);
vps = (MyViewPager) findViewById(R.id.vps);
tit_movic = (TextView) findViewById(R.id.title_movic);
back_img = (ImageView) findViewById(R.id.back_img);
}
private void init() {
textlist.add("简介");
textlist.add("评论");
fraglist.add(new Player1());
fraglist.add(new Player2());
}
private void getinit() {
MyAdapter_tab myAdapter_tab = new MyAdapter_tab(getSupportFragmentManager(), fraglist);
vps.setAdapter(myAdapter_tab);
}
@Override
public void onsuccess(Object o) {
if (o instanceof VideoBean) {
VideoBean bean = (VideoBean) o;
if (bean != null) {
ret = bean.getRet();
ijkplayer.setVideoURI(Uri.parse(ret.getHDURL()));
androidMediaController = new AndroidMediaController(this,false);
ijkplayer.setMediaController(androidMediaController);
tit_movic.setText(ret.getTitle());
ijkplayer.start();
}
}
}
@Override
public void onfailed(Exception e) {
}
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.back_img:
ijkplayer.stopPlayback();
finish();
break;
}
}
@Override
protected void onStop() {
super.onStop();
ijkplayer.stopPlayback();
}
private class MyAdapter_tab extends FragmentPagerAdapter {
private List fraglist;
public MyAdapter_tab(FragmentManager supportFragmentManager, List fraglist) {
super(supportFragmentManager);
this.fraglist = fraglist;
}
@Override
public CharSequence getPageTitle(int position) {
return textlist.get(position);
}
@Override
public Fragment getItem(int position) {
Bundle bundle = new Bundle();
bundle.putString("keys",key);
fraglist.get(position).setArguments(bundle);
return fraglist.get(position);
}
@Override
public int getCount() {
return textlist.size();
}
}
}
接下来是播放器的控制器:
package zhangtao.bwie.com.demo;
import android.content.Context;
import android.support.v7.app.ActionBar;
import android.util.AttributeSet;
import android.view.View;
import android.widget.MediaController;
import java.util.ArrayList;
import java.util.List;
import tv.danmaku.ijk.media.player.widget.IMediaController;
/**
* Created by ZhangTAO on 2017/12/16.
*/
public class AndroidMediaController extends MediaController implements IMediaController{
private ActionBar mActionBar;
private List mShowOnceArray = new ArrayList<>();
public AndroidMediaController(Context context, AttributeSet attrs) {
super(context, attrs);
initView(context);
}
public AndroidMediaController(Context context, boolean useFastForward) {
super(context, useFastForward);
initView(context);
}
public AndroidMediaController(Context context) {
super(context);
initView(context);
}
private void initView(Context context) {
}
public void setSupportActionBar(ActionBar actionBar) {
this.mActionBar = actionBar;
if(isShowing()) {
actionBar.show();
} else {
actionBar.hide();
}
}
@Override
public void show() {
super.show();
if(mActionBar != null) {
mActionBar.show();
}
}
@Override
public void hide() {
super.hide();
if(mActionBar != null) {
mActionBar.hide();
}
for(View view : mShowOnceArray) {
view.setVisibility(GONE);
}
mShowOnceArray.clear();
}
@Override
public void showOnce(View view) {
mShowOnceArray.add(view);
view.setVisibility(View.VISIBLE);
show();
}
}