|
|
package com.hh.xuetubao.activity.study;
|
|
|
|
|
|
import android.content.res.Configuration;
|
|
|
import android.graphics.Bitmap;
|
|
|
import android.media.MediaMetadataRetriever;
|
|
|
import android.os.Bundle;
|
|
|
import android.os.Handler;
|
|
|
import android.os.Message;
|
|
|
import android.support.v4.app.Fragment;
|
|
|
import android.support.v4.app.FragmentManager;
|
|
|
import android.support.v4.app.FragmentPagerAdapter;
|
|
|
import android.support.v4.view.ViewPager;
|
|
|
import android.util.Log;
|
|
|
import android.view.View;
|
|
|
import android.view.ViewGroup;
|
|
|
import android.widget.FrameLayout;
|
|
|
import android.widget.ImageView;
|
|
|
import android.widget.TextView;
|
|
|
import android.widget.Toast;
|
|
|
|
|
|
import com.bumptech.glide.Glide;
|
|
|
import com.dou361.ijkplayer.listener.OnShowThumbnailListener;
|
|
|
import com.dou361.ijkplayer.widget.IjkVideoView;
|
|
|
import com.dou361.ijkplayer.widget.PlayStateParams;
|
|
|
import com.dou361.ijkplayer.widget.PlayerView;
|
|
|
import com.hh.xuetubao.R;
|
|
|
import com.hh.xuetubao.Utils.OptimizeViewpager;
|
|
|
import com.hh.xuetubao.Utils.SharedPrefrenceUtils;
|
|
|
import com.hh.xuetubao.bean.ChapterLstBean;
|
|
|
import com.hh.xuetubao.bean.Event;
|
|
|
import com.hh.xuetubao.bean.UserBean;
|
|
|
import com.hh.xuetubao.fragment.IntroduceFragment;
|
|
|
import com.hh.xuetubao.fragment.ListFragment;
|
|
|
import com.hh.xuetubao.model.LearnModel;
|
|
|
import com.hh.xuetubao.mvp.BaseMvpActivity;
|
|
|
import com.hh.xuetubao.mvp.CommonPresenter;
|
|
|
import com.hh.xuetubao.mvp.ICommonView;
|
|
|
|
|
|
import org.greenrobot.eventbus.EventBus;
|
|
|
import org.greenrobot.eventbus.Subscribe;
|
|
|
import org.greenrobot.eventbus.ThreadMode;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
|
|
|
import butterknife.ButterKnife;
|
|
|
import fm.jiecao.jcvideoplayer_lib.JCVideoPlayerStandard;
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 课程详情
|
|
|
*/
|
|
|
public class CourseDetailActivity_Video extends BaseMvpActivity<CommonPresenter, LearnModel> implements ICommonView, View.OnClickListener {
|
|
|
|
|
|
private String lessonOid;
|
|
|
private String accountOid;
|
|
|
PlayerView play;
|
|
|
OptimizeViewpager pager;
|
|
|
|
|
|
FrameLayout course_A, course_B, back;
|
|
|
TextView start;
|
|
|
|
|
|
String playUrl; // = "http://dat.prepro.pq1959.com/lesson/274A9F7C-5A2D-4123-A97E-82F4A49D9BD8/XTBRES/C9696D55-660A-418C-86C8-858C3E919AD9/VIDEO/720.mp4";
|
|
|
private List<Fragment> fragmentList = new ArrayList<>();
|
|
|
|
|
|
MyViewPagerAdapter pagerAdapter;
|
|
|
TextView introduce, tv_list;
|
|
|
|
|
|
@Override
|
|
|
public void initView() {
|
|
|
EventBus.getDefault().register(this);
|
|
|
|
|
|
accountOid = SharedPrefrenceUtils.getString(this, "AccountOid");
|
|
|
lessonOid = getIntent().getExtras().getString("lessonOid");
|
|
|
Log.e("AccountOid", "AccountOid " + accountOid + "," + "lessonOid" + lessonOid);
|
|
|
|
|
|
course_A = this.findViewById(R.id.course_A); // 视频
|
|
|
course_B = this.findViewById(R.id.course_B); // 初始
|
|
|
back = this.findViewById(R.id.course_detail_back); // 退回
|
|
|
start = this.findViewById(R.id.course_detail_start); // 开始学习
|
|
|
pager = this.findViewById(R.id.pager);
|
|
|
introduce = this.findViewById(R.id.tv_introduce); // 介绍
|
|
|
tv_list = this.findViewById(R.id.tv_list); // 目录
|
|
|
|
|
|
start.setOnClickListener(this);
|
|
|
back.setOnClickListener(this);
|
|
|
introduce.setOnClickListener(this);
|
|
|
tv_list.setOnClickListener(this);
|
|
|
|
|
|
fragmentList.add(new IntroduceFragment());
|
|
|
fragmentList.add(new ListFragment(lessonOid));
|
|
|
|
|
|
pagerAdapter = new MyViewPagerAdapter(getSupportFragmentManager());
|
|
|
pager.setOffscreenPageLimit(2);//设置ViewPage缓存界面数
|
|
|
pager.setAdapter(pagerAdapter);
|
|
|
|
|
|
pager.setCurrentItem(1); // 直接定位目录
|
|
|
tv_list.setTextColor(getResources().getColor(R.color.color_ff5400));
|
|
|
introduce.setTextColor(getResources().getColor(R.color.color_616161));
|
|
|
|
|
|
pager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
|
|
|
@Override
|
|
|
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
|
|
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void onPageSelected(int position) {
|
|
|
switch (position) {
|
|
|
case 0:
|
|
|
introduce.setTextColor(getResources().getColor(R.color.color_ff5400));
|
|
|
tv_list.setTextColor(getResources().getColor(R.color.color_616161));
|
|
|
break;
|
|
|
case 1:
|
|
|
tv_list.setTextColor(getResources().getColor(R.color.color_ff5400));
|
|
|
introduce.setTextColor(getResources().getColor(R.color.color_616161));
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void onPageScrollStateChanged(int state) {
|
|
|
|
|
|
}
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
protected void onResume() {
|
|
|
super.onResume();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public int initLayout() {
|
|
|
return R.layout.activity_course_detail_two;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void initData() {
|
|
|
mPresenter.getPresenter(3, 1, "", lessonOid);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public CommonPresenter getPresenter() {
|
|
|
return new CommonPresenter();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public LearnModel getModel() {
|
|
|
return new LearnModel();
|
|
|
}
|
|
|
|
|
|
@Override //添加,避免旋转屏幕之后只显示半个屏幕
|
|
|
public void onConfigurationChanged(Configuration newConfig) {
|
|
|
super.onConfigurationChanged(newConfig);
|
|
|
if (play != null) {
|
|
|
play.onConfigurationChanged(newConfig);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void getData(Object o, int api, int intent) {
|
|
|
if (api == 3 && intent == 1) {
|
|
|
ChapterLstBean bean = (ChapterLstBean) o;
|
|
|
Log.e("bean", bean.toString());
|
|
|
playUrl = bean.getChapterLst().get(0).getSectionLst().get(0).getResourceLst().get(0).getPlayUrl(); // html
|
|
|
Log.e("player", playUrl);
|
|
|
}
|
|
|
|
|
|
/* 发送消息 */
|
|
|
if (api == 6 && intent == 1) {
|
|
|
UserBean userBean = (UserBean) o;
|
|
|
if (userBean.getSuccess() == true) {
|
|
|
Log.e("Course_Success", "发送成功");
|
|
|
} else {
|
|
|
Log.e("Course_fail", "发送失败");
|
|
|
}
|
|
|
handler.removeCallbacksAndMessages(null); // 关闭线程
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void onComplete(int api) {
|
|
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void onError(Throwable e, int api) {
|
|
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
super.onCreate(savedInstanceState);
|
|
|
ButterKnife.bind(this);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void onClick(View v) {
|
|
|
switch (v.getId()) {
|
|
|
case R.id.course_detail_back: // 返回
|
|
|
this.finish();
|
|
|
break;
|
|
|
case R.id.course_detail_start: // 开始学习
|
|
|
playVideo(playUrl);
|
|
|
break;
|
|
|
case R.id.tv_introduce: // 介绍
|
|
|
pager.setCurrentItem(0, true);
|
|
|
introduce.setTextColor(getResources().getColor(R.color.color_ff5400));
|
|
|
tv_list.setTextColor(getResources().getColor(R.color.color_616161));
|
|
|
break;
|
|
|
case R.id.tv_list: // 目录
|
|
|
pager.setCurrentItem(1, true);
|
|
|
tv_list.setTextColor(getResources().getColor(R.color.color_ff5400));
|
|
|
introduce.setTextColor(getResources().getColor(R.color.color_616161));
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
protected void onPause() {
|
|
|
super.onPause();
|
|
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
protected void onDestroy() {
|
|
|
super.onDestroy();
|
|
|
EventBus.getDefault().unregister(this);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
protected void onStop() {
|
|
|
super.onStop();
|
|
|
if (play != null) {
|
|
|
play.stopPlay();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Subscribe(threadMode = ThreadMode.MAIN, sticky = true)
|
|
|
public void handleEvent(Event event) {
|
|
|
|
|
|
if (event.getCode() == 1) {
|
|
|
onResumeJC(event); // 先发送
|
|
|
playVideo(event.getPlayUrl()); // 播放视频
|
|
|
}
|
|
|
if (event.getCode() == 2) {
|
|
|
|
|
|
final String urlA = event.getPlayUrl();
|
|
|
|
|
|
play = new PlayerView(this)
|
|
|
.setTitle("视频")
|
|
|
.setScaleType(PlayStateParams.fitparent)
|
|
|
.hideMenu(true)
|
|
|
.forbidTouch(false)
|
|
|
.showThumbnail(new OnShowThumbnailListener() {
|
|
|
@Override
|
|
|
public void onShowThumbnail(ImageView ivThumbnail) {
|
|
|
switch (urlA.substring(urlA.length() - 3, urlA.length()).trim()) {
|
|
|
case "tml":
|
|
|
Toast.makeText(CourseDetailActivity_Video.this, "链接需网页打开", Toast.LENGTH_SHORT).show();
|
|
|
break;
|
|
|
default: // mp4 , wav ..
|
|
|
ivThumbnail.setImageBitmap(getNetVideoBitmap(urlA));
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
})
|
|
|
.setPlaySource((urlA.substring(urlA.length() - 3, urlA.length())).trim().equals("tml") ? "" : urlA)
|
|
|
.startPlay();
|
|
|
|
|
|
course_A.setVisibility(View.VISIBLE);
|
|
|
course_B.setVisibility(View.GONE);
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 播放视频
|
|
|
private void playVideo(final String url) {
|
|
|
play = new PlayerView(this)
|
|
|
.setTitle("视频")
|
|
|
.setScaleType(PlayStateParams.fitparent)
|
|
|
.hideMenu(true)
|
|
|
.forbidTouch(false)
|
|
|
.showThumbnail(new OnShowThumbnailListener() {
|
|
|
@Override
|
|
|
public void onShowThumbnail(ImageView ivThumbnail) {
|
|
|
switch (url.substring(url.length() - 3, url.length()).trim()) {
|
|
|
case "tml":
|
|
|
Toast.makeText(CourseDetailActivity_Video.this, "链接需网页打开", Toast.LENGTH_SHORT).show();
|
|
|
break;
|
|
|
default: // mp4 , wav ..
|
|
|
ivThumbnail.setImageBitmap(getNetVideoBitmap(url));
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
})
|
|
|
.setPlaySource((url.substring(url.length() - 3, url.length())).trim().equals("tml") ? "" : url)
|
|
|
.startPlay();
|
|
|
|
|
|
course_A.setVisibility(View.VISIBLE);
|
|
|
course_B.setVisibility(View.GONE);
|
|
|
}
|
|
|
|
|
|
private Handler handler = new Handler() {
|
|
|
@Override
|
|
|
public void handleMessage(Message msg) {
|
|
|
super.handleMessage(msg);
|
|
|
switch (msg.what) {
|
|
|
case 1:
|
|
|
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
|
|
|
|
|
|
public void onResumeJC(final Event event) {
|
|
|
|
|
|
Runnable runnable = new Runnable() {
|
|
|
int duration;
|
|
|
int playing;
|
|
|
|
|
|
@Override
|
|
|
public void run() {
|
|
|
try {
|
|
|
playing = play.getCurrentPosition();
|
|
|
duration = (int) play.getDuration();
|
|
|
|
|
|
Log.e("Course_Play", "playing:" + playing + ", duration:" + duration);
|
|
|
|
|
|
String s = refreshTime();
|
|
|
Log.e("Course_refresh", s + "");
|
|
|
|
|
|
mPresenter.getPresenter(6,
|
|
|
1,
|
|
|
accountOid,
|
|
|
event.getLessonOid(),
|
|
|
event.getChapterOid(),
|
|
|
event.getSectionOid(),
|
|
|
event.getResourceOid(),
|
|
|
String.valueOf(playing / 1000),
|
|
|
String.valueOf(playing / 1000),
|
|
|
String.valueOf(duration / 1000)
|
|
|
);
|
|
|
|
|
|
Message msg = new Message();
|
|
|
msg.what = 1;
|
|
|
handler.sendMessage(msg);
|
|
|
|
|
|
Thread.sleep(1000);
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
|
|
|
handler.post(runnable);
|
|
|
|
|
|
}
|
|
|
|
|
|
//视频开始播放时使用handle.sendMessageDelayed更新时间显示
|
|
|
private String refreshTime() {
|
|
|
int totalSeconds = play.getCurrentPosition() / 1000;
|
|
|
int seconds = totalSeconds % 60;
|
|
|
int minutes = (totalSeconds / 60) % 60;
|
|
|
int hours = totalSeconds / 3600;
|
|
|
String ti = hours > 0 ? String.format("%02d:%02d:%02d", hours, minutes, seconds) : String.format("%02d:%02d", minutes, seconds);
|
|
|
return ti;
|
|
|
}
|
|
|
|
|
|
public static Bitmap getNetVideoBitmap(String videoUrl) {
|
|
|
Bitmap bitmap = null;
|
|
|
|
|
|
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
|
|
|
try {
|
|
|
//根据url获取缩略图
|
|
|
retriever.setDataSource(videoUrl, new HashMap());
|
|
|
//获得第一帧图片
|
|
|
bitmap = retriever.getFrameAtTime();
|
|
|
} catch (IllegalArgumentException e) {
|
|
|
e.printStackTrace();
|
|
|
} finally {
|
|
|
retriever.release();
|
|
|
}
|
|
|
return bitmap;
|
|
|
}
|
|
|
|
|
|
public class MyViewPagerAdapter extends FragmentPagerAdapter {
|
|
|
|
|
|
public MyViewPagerAdapter(FragmentManager fm) {
|
|
|
super(fm);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public Fragment getItem(int position) {
|
|
|
return fragmentList.get(position);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public int getCount() {
|
|
|
return fragmentList.size();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void destroyItem(ViewGroup container, int position, Object object) {
|
|
|
// super.destroyItem(container, position, object);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
...
|
...
|
|