|
|
package com.hh.xuetubao.activity.study;
|
|
|
|
|
|
import android.content.Intent;
|
|
|
import android.content.pm.ActivityInfo;
|
|
|
import android.content.res.Configuration;
|
|
|
import android.graphics.Bitmap;
|
|
|
import android.media.MediaMetadataRetriever;
|
...
|
...
|
@@ -15,13 +16,9 @@ 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.dou361.ijkplayer.listener.OnShowThumbnailListener;
|
|
|
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;
|
...
|
...
|
@@ -34,6 +31,9 @@ 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 com.shuyu.gsyvideoplayer.GSYVideoManager;
|
|
|
import com.shuyu.gsyvideoplayer.utils.OrientationUtils;
|
|
|
import com.shuyu.gsyvideoplayer.video.StandardGSYVideoPlayer;
|
|
|
|
|
|
import org.greenrobot.eventbus.EventBus;
|
|
|
import org.greenrobot.eventbus.Subscribe;
|
...
|
...
|
@@ -53,7 +53,7 @@ public class CourseDetailActivity_Video extends BaseMvpActivity<CommonPresenter, |
|
|
|
|
|
private String lessonOid;
|
|
|
private String accountOid;
|
|
|
PlayerView play;
|
|
|
// PlayerView play;
|
|
|
OptimizeViewpager pager;
|
|
|
|
|
|
FrameLayout course_A, course_B, back;
|
...
|
...
|
@@ -71,8 +71,9 @@ public class CourseDetailActivity_Video extends BaseMvpActivity<CommonPresenter, |
|
|
boolean isFinish = false;//判断视频是否加载完毕
|
|
|
boolean isCanStudy = false;//判断是否有权限观看这条视频
|
|
|
|
|
|
TextView time_video;
|
|
|
private Event event;
|
|
|
private StandardGSYVideoPlayer player;
|
|
|
OrientationUtils orientationUtils;
|
|
|
|
|
|
|
|
|
@Override
|
|
|
public void initView() {
|
...
|
...
|
@@ -92,11 +93,10 @@ public class CourseDetailActivity_Video extends BaseMvpActivity<CommonPresenter, |
|
|
tv_list = this.findViewById(R.id.tv_list); // 目录
|
|
|
titleValue = this.findViewById(R.id.titleValue);
|
|
|
|
|
|
|
|
|
time_video = this.findViewById(R.id.app_video_endTime);
|
|
|
|
|
|
titleValue.setText(title);
|
|
|
|
|
|
player = this.findViewById(R.id.videoplay);
|
|
|
|
|
|
start.setOnClickListener(this);
|
|
|
back.setOnClickListener(this);
|
|
|
introduce.setOnClickListener(this);
|
...
|
...
|
@@ -150,12 +150,6 @@ public class CourseDetailActivity_Video extends BaseMvpActivity<CommonPresenter, |
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
protected void onResume() {
|
|
|
super.onResume();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public int initLayout() {
|
|
|
return R.layout.activity_course_detail_two;
|
...
|
...
|
@@ -179,9 +173,6 @@ public class CourseDetailActivity_Video extends BaseMvpActivity<CommonPresenter, |
|
|
@Override //添加,避免旋转屏幕之后只显示半个屏幕
|
|
|
public void onConfigurationChanged(Configuration newConfig) {
|
|
|
super.onConfigurationChanged(newConfig);
|
|
|
if (play != null) {
|
|
|
play.onConfigurationChanged(newConfig);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Override
|
...
|
...
|
@@ -264,21 +255,40 @@ public class CourseDetailActivity_Video extends BaseMvpActivity<CommonPresenter, |
|
|
@Override
|
|
|
protected void onPause() {
|
|
|
super.onPause();
|
|
|
player.onVideoPause();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
protected void onResume() {
|
|
|
super.onResume();
|
|
|
player.onVideoResume();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
protected void onDestroy() {
|
|
|
super.onDestroy();
|
|
|
EventBus.getDefault().unregister(this);
|
|
|
GSYVideoManager.releaseAllVideos();
|
|
|
if (orientationUtils != null)
|
|
|
orientationUtils.releaseListener();
|
|
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
protected void onStop() {
|
|
|
super.onStop();
|
|
|
if (play != null) {
|
|
|
play.stopPlay();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void onBackPressed() {
|
|
|
//先返回正常状态
|
|
|
if (orientationUtils.getScreenType() == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) {
|
|
|
player.getFullscreenButton().performClick();
|
|
|
return;
|
|
|
}
|
|
|
//释放所有
|
|
|
player.setVideoAllCallBack(null);
|
|
|
super.onBackPressed();
|
|
|
}
|
|
|
|
|
|
@Subscribe(threadMode = ThreadMode.MAIN, sticky = true)
|
...
|
...
|
@@ -293,34 +303,29 @@ public class CourseDetailActivity_Video extends BaseMvpActivity<CommonPresenter, |
|
|
|
|
|
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":
|
|
|
// 跳转
|
|
|
// Intent intent = new Intent(CourseDetailActivity_Video.this, WebActivity.class);
|
|
|
// intent.putExtra("tml",urlA);
|
|
|
// startActivity(intent);
|
|
|
// 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)
|
|
|
.setAutoReConnect(true, 0)
|
|
|
.startPlay();
|
|
|
|
|
|
time_video.setText(play.getDuration() + "");
|
|
|
player.setUp(urlA,true,"视频");
|
|
|
|
|
|
player.getBackButton().setVisibility(View.VISIBLE);
|
|
|
//设置旋转
|
|
|
orientationUtils = new OrientationUtils(this, player);
|
|
|
//设置全屏按键功能,这是使用的是选择屏幕,而不是全屏
|
|
|
player.getFullscreenButton().setOnClickListener(new View.OnClickListener() {
|
|
|
@Override
|
|
|
public void onClick(View v) {
|
|
|
orientationUtils.resolveByClick();
|
|
|
}
|
|
|
});
|
|
|
|
|
|
//是否可以滑动调整
|
|
|
player.setIsTouchWiget(true);
|
|
|
//设置返回按键功能
|
|
|
player.getBackButton().setOnClickListener(new View.OnClickListener() {
|
|
|
@Override
|
|
|
public void onClick(View v) {
|
|
|
onBackPressed();
|
|
|
}
|
|
|
});
|
|
|
player.startPlayLogic();
|
|
|
|
|
|
if ((urlA.substring(urlA.length() - 3, urlA.length())).trim().equals("tml")) {
|
|
|
course_A.setVisibility(View.GONE);
|
...
|
...
|
@@ -336,32 +341,30 @@ public class CourseDetailActivity_Video extends BaseMvpActivity<CommonPresenter, |
|
|
|
|
|
// 播放视频
|
|
|
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":
|
|
|
|
|
|
|
|
|
Intent intent = new Intent(CourseDetailActivity_Video.this, WebActivity.class);
|
|
|
intent.putExtra("tml", url);
|
|
|
startActivity(intent);
|
|
|
// 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();
|
|
|
|
|
|
player.setUp(url,true,"视频");
|
|
|
|
|
|
player.getBackButton().setVisibility(View.VISIBLE);
|
|
|
//设置旋转
|
|
|
orientationUtils = new OrientationUtils(this, player);
|
|
|
//设置全屏按键功能,这是使用的是选择屏幕,而不是全屏
|
|
|
player.getFullscreenButton().setOnClickListener(new View.OnClickListener() {
|
|
|
@Override
|
|
|
public void onClick(View v) {
|
|
|
orientationUtils.resolveByClick();
|
|
|
}
|
|
|
});
|
|
|
|
|
|
//是否可以滑动调整
|
|
|
player.setIsTouchWiget(true);
|
|
|
//设置返回按键功能
|
|
|
player.getBackButton().setOnClickListener(new View.OnClickListener() {
|
|
|
@Override
|
|
|
public void onClick(View v) {
|
|
|
onBackPressed();
|
|
|
}
|
|
|
});
|
|
|
player.startPlayLogic();
|
|
|
|
|
|
if ((url.substring(url.length() - 3, url.length())).trim().equals("tml")) {
|
|
|
course_A.setVisibility(View.GONE);
|
...
|
...
|
@@ -395,14 +398,13 @@ public class CourseDetailActivity_Video extends BaseMvpActivity<CommonPresenter, |
|
|
@Override
|
|
|
public void run() {
|
|
|
try {
|
|
|
playing = play.getCurrentPosition();
|
|
|
duration = (int) play.getDuration();
|
|
|
duration = player.getDuration(); // 总时长
|
|
|
playing = player.getCurrentPositionWhenPlaying();
|
|
|
// 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,
|
...
|
...
|
@@ -432,14 +434,14 @@ public class CourseDetailActivity_Video extends BaseMvpActivity<CommonPresenter, |
|
|
}
|
|
|
|
|
|
//视频开始播放时使用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;
|
|
|
}
|
|
|
// 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) {
|
...
|
...
|
|