MainActivtiy向Main2Activty中傳值
阿新 • • 發佈:2019-01-26
http://result.eolinker.com/iYXEPGn4e9c6dafce6e5cdd23287d2bb136ee7e9194d3e9?uri=vedio
MainActivity中
public class MainActivity extends AppCompatActivity implements IHomeView{
private Banner mbanner;
HomePresenter homePresenter;
ArrayList mlist;
private RecyclerView recyclerView;
MyAdapter myAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mbanner= (Banner) findViewById(R.id.mybanner);
recyclerView= (RecyclerView) findViewById(R.id.id_recyclerview);
homePresenter=new HomePresenter(this);
homePresenter.setNews(Api.URL);
}
@Override
protected void onDestroy() {
super.onDestroy();
homePresenter=null;//解綁
}
@Override
public void getHome(final List<Home.DataBean> list) {
mlist=new ArrayList();
for (int i=0;i<list.size();i++)
{
mlist.add(list.get(i).getImage_url());
}
mbanner.setImageLoader(new GlideImageLoader());
mbanner.setImages(mlist);
mbanner.start();
myAdapter=new MyAdapter(MainActivity.this,list);
recyclerView.setAdapter(myAdapter);
myAdapter.setOnItemClickLitener(new OnItemClickLitener() {
@Override
public void onItemClick(View view, int position) {
Intent intent=new Intent(MainActivity.this,Main2Activity.class);
String vedio_url = list.get(position).getVedio_url();
EventBus.getDefault().postSticky(new Chuan(vedio_url));
startActivity(intent);
}
@Override
public void onItemLongClick(View view, int position) {
}
});
recyclerView.setLayoutManager(new LinearLayoutManager(MainActivity.this));
}
}
Main2Activtiy(MainActivtiy向Main2Activity中傳URI,在Main2Activty中進行播放並下載)
public class Main2Activity extends AppCompatActivity implements PlayerManager.PlayerStateListener{
private PlayerManager player;
private String vedio_url;
private static final String TAG = MainActivity.class.getSimpleName();
private ProgressBar mProgressBar;
private Button start;
private Button pause;
private TextView total;
private int max;
private DownloadUtil mDownloadUtil;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
EventBus.getDefault().register(this);
//初始化播放器
player = new PlayerManager(this);
player.setFullScreenOnly(true);
player.setScaleType(PlayerManager.SCALETYPE_FILLPARENT);
player.playInFullScreen(true);
player.setPlayerStateListener(Main2Activity.this);
player.play(vedio_url);
total = (TextView) findViewById(R.id.textView);
start = (Button) findViewById(R.id.start);
pause = (Button) findViewById(R.id.delete);
mProgressBar = (ProgressBar) findViewById(R.id.progressBar);
String urlString = vedio_url;
Log.d("aaaaaaaaaaaa",vedio_url.toString());
//vedio_url http://2449.vod.myqcloud.com/2449_bfbbfa3cea8f11e5aac3db03cda99974.f20.mp4
//vedio_url https://wdl.wallstreetcn.com/41aae4d2-390a-48ff-9230-ee865552e72d.mp4
String localPath = Environment.getExternalStorageDirectory()
.getAbsolutePath();
String substring = vedio_url.substring(vedio_url.length() - 8);
mDownloadUtil = new DownloadUtil(2, localPath, substring, urlString,
this);
mDownloadUtil.setOnDownloadListener(new DownloadUtil.OnDownloadListener() {
@Override
public void downloadStart(int fileSize) {
// TODO Auto-generated method stub
Log.w(TAG, "fileSize::" + fileSize);
max = fileSize;
mProgressBar.setMax(fileSize);
}
@Override
public void downloadProgress(int downloadedSize) {
// TODO Auto-generated method stub
Log.w(TAG, "Compelete::" + downloadedSize);
mProgressBar.setProgress(downloadedSize);
total.setText((int) downloadedSize * 100 / max + "%");
}
@Override
public void downloadEnd() {
// TODO Auto-generated method stub
Log.w(TAG, "ENd");
}
});
start.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
mDownloadUtil.start();
}
});
pause.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
mDownloadUtil.pause();
}
});
}
@Override
protected void onDestroy() {
super.onDestroy();
EventBus.getDefault().unregister(this);//取消註冊
}
@Subscribe(threadMode = ThreadMode.POSTING,sticky = true)
public void getData(Chuan user){
vedio_url = user.getVedio_url();
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if (player.gestureDetector.onTouchEvent(event))
return true;
return super.onTouchEvent(event);
}
@Override
public void onComplete() {
}
@Override
protected void onStop() {
super.onStop();
player.stop();
}
@Override
public void onError() {
}
@Override
public void onLoading() {
}
@Override
public void onPlay() {
}
}