package com.weikou.beibeivideo.ui.media;
|
|
import android.app.Activity;
|
import android.app.ProgressDialog;
|
import android.content.ContentValues;
|
import android.content.Context;
|
import android.content.Intent;
|
import android.content.SharedPreferences;
|
import android.content.pm.ActivityInfo;
|
import android.content.res.Configuration;
|
import android.database.Cursor;
|
import android.graphics.drawable.Drawable;
|
import android.os.Bundle;
|
|
import androidx.annotation.NonNull;
|
import androidx.annotation.Nullable;
|
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.FragmentManager;
|
import androidx.fragment.app.FragmentTransaction;
|
|
import android.util.Log;
|
import android.view.KeyEvent;
|
import android.view.View;
|
import android.view.View.OnClickListener;
|
import android.view.ViewGroup;
|
import android.view.WindowManager;
|
import android.widget.FrameLayout;
|
import android.widget.ImageView;
|
import android.widget.LinearLayout;
|
import android.widget.LinearLayout.LayoutParams;
|
import android.widget.TextView;
|
import android.widget.Toast;
|
|
import com.bumptech.glide.Glide;
|
import com.bumptech.glide.request.RequestOptions;
|
import com.bumptech.glide.request.target.SimpleTarget;
|
import com.bumptech.glide.request.transition.Transition;
|
import com.bytedance.sdk.openadsdk.TTFullScreenVideoAd;
|
import com.google.gson.FieldNamingPolicy;
|
import com.google.gson.Gson;
|
import com.google.gson.GsonBuilder;
|
import com.google.gson.reflect.TypeToken;
|
import com.lcjian.library.entity.eventbus.PlayerControllerShow;
|
import com.lcjian.library.entity.eventbus.PlayerLock;
|
import com.lcjian.library.util.SingleToast;
|
import com.lcjian.library.util.SystemCommon;
|
import com.lcjian.library.util.common.DimenUtils;
|
import com.lcjian.library.util.common.StringUtils;
|
import com.loopj.android.http.JsonHttpResponseHandler;
|
import com.weikou.beibeivideo.BasicTextHttpResponseHandler;
|
import com.weikou.beibeivideo.BeibeiVideoAPI;
|
import com.weikou.beibeivideo.BeibeiVideoApplication;
|
import com.weikou.beibeivideo.R;
|
import com.weikou.beibeivideo.db.WatchHistoryTable;
|
import com.weikou.beibeivideo.entity.AccumulateRule;
|
import com.weikou.beibeivideo.entity.Follow;
|
import com.weikou.beibeivideo.entity.Play;
|
import com.weikou.beibeivideo.entity.PlayUrl;
|
import com.weikou.beibeivideo.entity.Playlocation;
|
import com.weikou.beibeivideo.entity.PushEpisode;
|
import com.weikou.beibeivideo.entity.VideoDetailInfo;
|
import com.weikou.beibeivideo.entity.VideoInfo;
|
import com.weikou.beibeivideo.entity.VideoResource;
|
import com.weikou.beibeivideo.entity.video.ChangeVideoEvent;
|
import com.weikou.beibeivideo.entity.vo.VideoDetailAdInfoVO;
|
import com.weikou.beibeivideo.ui.BaseActivity;
|
import com.weikou.beibeivideo.ui.ad.PlayVideoPreADFragment;
|
import com.weikou.beibeivideo.ui.common.ShareActivity;
|
import com.weikou.beibeivideo.ui.mine.PPTVPlayFragment;
|
import com.weikou.beibeivideo.ui.video.VideoPlayerBrowserActivity;
|
import com.weikou.beibeivideo.ui.video.FunshionPlayerFragment;
|
import com.weikou.beibeivideo.util.BeibeiConstant;
|
import com.weikou.beibeivideo.util.UmengEventUtil;
|
import com.weikou.beibeivideo.util.VideoUtil;
|
import com.weikou.beibeivideo.util.ad.FullVideoAdManager;
|
import com.weikou.beibeivideo.util.goldcorn.GoldCornUtil;
|
import com.weikou.beibeivideo.util.ui.IPageEventListener;
|
import com.weikou.beibeivideo.util.ui.TopStatusSettings;
|
|
import org.apache.http.Header;
|
import org.json.JSONArray;
|
import org.json.JSONObject;
|
|
import java.util.ArrayList;
|
import java.util.List;
|
|
import de.greenrobot.event.EventBus;
|
|
|
/**
|
* 视频详情
|
*
|
* @author Administrator
|
*/
|
//
|
public class VideoDetailActivity2 extends BaseActivity implements
|
OnClickListener {
|
|
private final String TAG = VideoDetailActivity2.class.getName();
|
|
//外层容器
|
LinearLayout ll_other;
|
FrameLayout fl_pptv;
|
|
|
// private boolean mLandscape;
|
private VideoInfo videoInfo;
|
|
private ImageView iv_download_failure;
|
private ImageView iv_background;
|
|
private TextView tv_back;
|
|
private String resourceId = "";
|
|
private String detailid = "";
|
private Fragment mIQYVideoPlayerFragment;
|
private ProgressDialog progressDialog;
|
|
private boolean isClick = false;
|
|
private FragmentManager fm = getSupportFragmentManager();
|
|
private PlayVideoPreADFragment mVideoDetailVideoAdFragment;
|
|
//风行播放器
|
private FunshionPlayerFragment mFunshionPlayerFragment;
|
|
private ImageView iv_select_play;
|
|
private FrameLayout fl_ad;
|
|
private boolean playerLock;//播放器是否锁屏
|
|
private String from;
|
|
private VideoDetailAdInfoVO adInfo;
|
|
//会话ID
|
private String sessionId;
|
|
@Override
|
protected void onSaveInstanceState(Bundle outState) {
|
outState.putString("flash exit", "VideoDetailActivity");
|
super.onSaveInstanceState(outState);
|
}
|
|
private void initView() {
|
ll_other = findViewById(R.id.ll_other);
|
fl_pptv = findViewById(R.id.fl_pptv);
|
fl_pptv.setVisibility(View.GONE);
|
|
iv_select_play = findViewById(R.id.iv_select_play);
|
tv_back = findViewById(R.id.iv_back);
|
iv_download_failure = findViewById(R.id.iv_download_failure);
|
|
fl_video_play_background = findViewById(R.id.fl_video_play_background);
|
iv_background = findViewById(R.id.iv_video_play_background);
|
fl_ad = findViewById(R.id.fl_ad);
|
|
initPlayer();
|
}
|
|
@Override
|
public void onCreate(Bundle savedInstanceState) {
|
super.onCreate(savedInstanceState);
|
setContentView(R.layout.video_detail_activity);
|
VideoUtil.clearVideoEpisodeList(this);
|
TopStatusSettings.setStatusViewAndDeepColor(this);
|
|
//广告
|
mVideoDetailVideoAdFragment = new PlayVideoPreADFragment();
|
//播放器
|
mFunshionPlayerFragment = new FunshionPlayerFragment();
|
|
getSupportFragmentManager().beginTransaction().replace(R.id.fl_ad, mVideoDetailVideoAdFragment).commit();
|
|
initView();
|
|
|
progressDialog = new ProgressDialog(this, ProgressDialog.STYLE_SPINNER);
|
progressDialog.setCanceledOnTouchOutside(false);
|
progressDialog.setMessage("正在请求网络...");
|
progressDialog.show();
|
|
|
tv_back.setOnClickListener(this);
|
|
iv_download_failure.setOnClickListener(this);
|
if (getIntent().getSerializableExtra("video_info") != null) {
|
videoInfo = (VideoInfo) getIntent().getSerializableExtra(
|
"video_info");
|
if (videoInfo != null)
|
videoInfo.setVideoDetailList(null);
|
|
from = getIntent().getStringExtra("from");
|
UmengEventUtil.videoDetail(getApplicationContext(), from);
|
|
if (getIntent().getBooleanExtra("isFromWatchHistory", false)) {
|
Cursor cursor = getContentResolver().query(
|
WatchHistoryTable.CONTENT_URI, null,
|
WatchHistoryTable.VIDEO_ID + " = ? ",
|
new String[]{videoInfo.getId()}, null);
|
cursor.moveToFirst();
|
if (cursor.getCount() > 0) {
|
try {
|
resourceId = cursor.getString(cursor.getColumnIndex(WatchHistoryTable.VIDEO_RESOURCE_ID));
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
}
|
cursor.close();
|
}
|
} else {
|
videoInfo = new VideoInfo();
|
Bundle bundle = this.getIntent().getExtras();
|
videoInfo.setId(bundle.getString("Id"));
|
videoInfo.setShare(bundle.getString("Share"));
|
videoInfo.setThirdType(bundle.getString("ThirdType"));
|
//后面使用setResouceId
|
resourceId = bundle.getString("ResourceId");
|
detailid = bundle.getString("DetailId");
|
}
|
|
if (videoInfo == null)
|
BeibeiVideoAPI.setVideoError(this,
|
getSharedPreferences("user", Context.MODE_PRIVATE)
|
.getString("uid", ""),
|
"VideoDetailActivity:传入的VideoInfo为空",
|
new JsonHttpResponseHandler() {
|
});
|
if ("1".equals(videoInfo.getShare())) {
|
SharedPreferences preferences = getSharedPreferences("user",
|
Context.MODE_PRIVATE);
|
if (!preferences.getBoolean("shared", false)) {
|
Toast.makeText(VideoDetailActivity2.this, "该影片需要分享之后才能观看",
|
Toast.LENGTH_LONG).show();
|
startActivity(getIntent().setClass(VideoDetailActivity2.this,
|
ShareActivity.class));
|
finish();
|
return;
|
}
|
}
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
|
(int) SystemCommon.getScreenWidth(this),
|
(int) ((SystemCommon.getScreenWidth(this) * 9) / 16));
|
findViewById(R.id.fragment_video_play_container1).setLayoutParams(
|
params);
|
|
iv_select_play.setOnClickListener(new OnClickListener() {
|
|
@Override
|
public void onClick(View arg0) {
|
if (videoInfo == null) {
|
return;
|
}
|
isClick = true;
|
startPlay();
|
}
|
});
|
iv_background.setOnClickListener(new OnClickListener() {
|
@Override
|
public void onClick(View v) {
|
if (videoInfo == null) {
|
return;
|
}
|
isClick = true;
|
startPlay();
|
}
|
});
|
iv_background.setClickable(false);
|
Fragment videoDetailFragment = fm
|
.findFragmentByTag("VideoDetailFragment");
|
if (videoDetailFragment == null) {
|
videoDetailFragment = new VideoDetailFragment();
|
Bundle bundle = new Bundle();
|
bundle.putInt("playing_position", getIntent().getIntExtra("playing_position", 0));
|
videoDetailFragment.setArguments(bundle);
|
|
fm.beginTransaction()
|
.add(R.id.fragment_video_detail_container,
|
videoDetailFragment, "VideoDetailFragment")
|
.commitAllowingStateLoss();
|
}
|
iNet();
|
}
|
|
|
private void loadFullVideoAd() {
|
if (adInfo == null || !adInfo.isFullVideo())
|
return;
|
//加载广告
|
if (BeibeiConstant.AD_TYPE.isVideoDetailSplashAd()) {
|
if (FullVideoAdManager.getInstance().isCacahed()) {
|
FullVideoAdManager.getInstance().showAd(this);
|
} else {
|
FullVideoAdManager.getInstance().loadAd(BeibeiVideoApplication.application, new FullVideoAdManager.IFullVideoAdListener() {
|
@Override
|
public void onSuccess(TTFullScreenVideoAd ad) {
|
FullVideoAdManager.getInstance().showAd(VideoDetailActivity2.this);
|
}
|
});
|
}
|
}
|
}
|
|
private static FrameLayout fl_video_play_background;
|
|
public static void hideImage() {
|
fl_video_play_background.setVisibility(View.GONE);
|
}
|
|
private int mPosition = 0;
|
|
|
Fragment mSohuVideoFragment;
|
Fragment mLeTVVideoFragment;
|
Fragment mYoukuPlayerFragment;
|
|
private boolean isFirst = true;
|
|
private synchronized void startPlay() {
|
//移除所有的fragment
|
if (mVideoDetailVideoAdFragment.isAdded()) {
|
getSupportFragmentManager().beginTransaction().remove(mVideoDetailVideoAdFragment).commit();
|
}
|
|
if (mFunshionPlayerFragment.isAdded()) {
|
getSupportFragmentManager().beginTransaction().remove(mFunshionPlayerFragment).commit();
|
}
|
|
iv_select_play.setVisibility(View.GONE);
|
if (BeibeiConstant.IS_TEST)
|
BeibeiConstant.AD_TYPE = null;
|
//需要加载广告
|
if (BeibeiConstant.AD_TYPE != null && BeibeiConstant.AD_TYPE.isPlayerAd() && playUrl != null && playUrl.getPlayType() != 2 && adInfo != null && adInfo.isPlayVideo()) {
|
mVideoDetailVideoAdFragment = new PlayVideoPreADFragment();
|
mVideoDetailVideoAdFragment.setPageEventListener(new IPageEventListener() {
|
@Override
|
public void onCreateView() {
|
mVideoDetailVideoAdFragment.loadVideoAD(new PlayVideoPreADFragment.IVideoAdListener() {
|
@Override
|
public void finishPlay() {
|
getSupportFragmentManager().beginTransaction().remove(mVideoDetailVideoAdFragment).commitAllowingStateLoss();
|
clickPlay();//进入播放事件
|
}
|
|
@Override
|
public void startPlay() {
|
|
}
|
|
@Override
|
public void onOtherClick(String name) {
|
|
}
|
|
@Override
|
public void noAd() {
|
getSupportFragmentManager().beginTransaction().remove(mVideoDetailVideoAdFragment).commitAllowingStateLoss();
|
clickPlay();//进入播放事件
|
}
|
});
|
}
|
});
|
|
if (!mVideoDetailVideoAdFragment.isAdded()) {
|
fl_ad.setVisibility(View.VISIBLE);
|
getSupportFragmentManager().beginTransaction().replace(R.id.fl_ad, mVideoDetailVideoAdFragment).commit();
|
}
|
|
} else {//进入播放视频事件
|
clickPlay();
|
}
|
|
|
}
|
|
private void clickPlay() {
|
if (playUrl == null) {
|
SingleToast.showToast(VideoDetailActivity2.this, "初始化播放路径中,请稍候点击播放!");
|
return;
|
}
|
|
for (int i = 0; i < videoInfo.getResourceList().size(); i++) {
|
if (playUrl.getResource().getId().equalsIgnoreCase(videoInfo.getResourceList().get(i).getId())) {
|
videoInfo.getResourceList().get(i).setChecked(true);
|
} else {
|
videoInfo.getResourceList().get(i).setChecked(false);
|
}
|
}
|
|
//播放统计
|
BeibeiVideoAPI.playStatistic(BeibeiVideoApplication.application, videoInfo.getId(), playUrl.getResource().getId() + "", new BasicTextHttpResponseHandler() {
|
@Override
|
public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception {
|
|
}
|
});
|
|
if (playUrl.getResource().getName().contains("爱奇艺")) {
|
if (playUrl != null) {
|
if (playUrl.getPlayType() == 0) {
|
Toast.makeText(VideoDetailActivity2.this, "此节目不可播!",
|
Toast.LENGTH_LONG).show();
|
return;
|
} else if (playUrl.getPlayType() == 1) {
|
Intent intent = new Intent(VideoDetailActivity2.this,
|
VideoPlayerBrowserActivity.class);
|
intent.putExtra("url", playUrl.getUrl());
|
startActivity(intent);
|
initPlayer();
|
} else if (playUrl.getPlayType() == 2) {
|
iv_select_play.setVisibility(View.GONE);
|
iv_background.setClickable(false);
|
mIQYVideoPlayerFragment = fm
|
.findFragmentByTag("IQYVideoFragment");
|
mIQYVideoPlayerFragment = new IQYVideoFragment();
|
Bundle b = new Bundle();
|
b.putSerializable("playUrl", playUrl);
|
mIQYVideoPlayerFragment.setArguments(b);
|
fm.beginTransaction()
|
.replace(R.id.fragment_video_play_container,
|
mIQYVideoPlayerFragment, "IQYVideoFragment")
|
.commitAllowingStateLoss();
|
// EventBus.getDefault().post(playUrl);
|
Toast.makeText(VideoDetailActivity2.this, "影片加载中...",
|
Toast.LENGTH_LONG).show();
|
initPlayer();
|
}
|
saveWatchHistory("爱奇艺");
|
}
|
|
} else if (playUrl.getResource().getName().contains("风行")) {
|
|
if (playUrl.getPlayType() == 0) {
|
Toast.makeText(VideoDetailActivity2.this, "此节目不可播!",
|
Toast.LENGTH_LONG).show();
|
return;
|
} else if (playUrl.getPlayType() == 1) {
|
Intent intent = new Intent(VideoDetailActivity2.this,
|
VideoPlayerBrowserActivity.class);
|
intent.putExtra("url", playUrl.getUrl());
|
startActivity(intent);
|
saveWatchHistory("风行");
|
initPlayer();
|
} else if (playUrl.getPlayType() == 2) {//SDK播放
|
//播放风行视频
|
//添加风行播放页
|
mFunshionPlayerFragment = new FunshionPlayerFragment();
|
Bundle bundle = new Bundle();
|
bundle.putSerializable("videoInfo", videoInfo);
|
bundle.putSerializable("playUrl", playUrl);
|
bundle.putInt("position", mPosition);
|
bundle.putBoolean("collect", false);
|
bundle.putSerializable("resource", resource);
|
mFunshionPlayerFragment.setArguments(bundle);
|
if (!mFunshionPlayerFragment.isAdded()) {
|
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_video_play_container, mFunshionPlayerFragment).commit();
|
}
|
fl_video_play_background.setVisibility(View.GONE);
|
}
|
|
} else {
|
if (playUrl.getPlayType() == 0) {
|
Toast.makeText(VideoDetailActivity2.this, "此节目不可播!",
|
Toast.LENGTH_LONG).show();
|
return;
|
} else if (playUrl.getPlayType() == 1) {
|
Intent intent = new Intent(VideoDetailActivity2.this,
|
VideoPlayerBrowserActivity.class);
|
intent.putExtra("url", playUrl.getUrl());
|
startActivity(intent);
|
saveWatchHistory(playUrl.getResource().getName());
|
}
|
initPlayer();
|
}
|
}
|
|
|
private PlayUrl info;
|
|
public void onEventMainThread(Playlocation location) {
|
fl_ad.setVisibility(View.VISIBLE);
|
mPosition = location.getPosition();
|
}
|
|
/**
|
* 初始化播放器
|
*/
|
private void initPlayer() {
|
fl_ad.setVisibility(View.GONE);
|
iv_select_play.setVisibility(View.VISIBLE);
|
iv_background.setVisibility(View.VISIBLE);
|
fl_video_play_background.setVisibility(View.VISIBLE);
|
}
|
|
|
public void onEventMainThread(PlayUrl info) {
|
this.info = info;
|
Toast.makeText(this, "播放", Toast.LENGTH_SHORT).show();
|
}
|
|
private SimpleTarget<Drawable> target = new SimpleTarget<Drawable>() {
|
|
@Override
|
public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
|
((ImageView) findViewById(R.id.iv_video_play_background))
|
.setImageDrawable(resource);
|
}
|
|
@Override
|
public void onLoadCleared(@Nullable Drawable placeholder) {
|
|
}
|
};
|
|
@Override
|
public void onBackPressed() {
|
Log.i(TAG, "onBackPressed");
|
if (playerLock)
|
return;//锁屏不做处理
|
if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
|
super.onBackPressed();
|
} else {
|
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
|
}
|
}
|
|
@Override
|
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
onBackPressed();
|
return false;
|
} else {
|
return super.onKeyDown(keyCode, event);
|
}
|
}
|
|
public void onEventMainThread(AccumulateRule info) {// 播放界面返回替代使用
|
clickBack();
|
}
|
|
public void onEventMainThread(PlayerLock info) {//播放器锁屏
|
playerLock = info.isLock();
|
}
|
|
public void onEventMainThread(PlayerControllerShow show) {//播放控制器显示
|
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
|
tv_back.setVisibility(View.GONE);
|
} else {
|
if (show.isShow()) {
|
tv_back.setVisibility(View.GONE);
|
} else {
|
tv_back.setVisibility(View.VISIBLE);
|
}
|
|
}
|
|
}
|
|
|
private void clickBack() {
|
Log.i(TAG, "clickBack");
|
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
|
findViewById(R.id.fl_video_detail).setVisibility(View.VISIBLE);
|
fl_video_play_background.setVisibility(View.VISIBLE);
|
iv_select_play.setVisibility(View.VISIBLE);
|
try {
|
Glide.with(getApplicationContext()).load(R.drawable.ic_select_play)
|
.into(iv_select_play);
|
} catch (IllegalArgumentException e) {
|
e.printStackTrace();
|
}
|
findViewById(R.id.v_status_bar).setVisibility(View.VISIBLE);
|
android.widget.LinearLayout.LayoutParams params = new android.widget.LinearLayout.LayoutParams(
|
(int) SystemCommon.getScreenWidth(this),
|
(int) ((SystemCommon.getScreenWidth(this) * 9) / 16));
|
findViewById(R.id.fragment_video_play_container1).setLayoutParams(
|
params);
|
if (playUrl != null && playUrl.getResource().getName().contains("爱奇艺")) {
|
iv_background.setClickable(true);
|
if (mIQYVideoPlayerFragment != null)
|
fm.beginTransaction().remove(mIQYVideoPlayerFragment)
|
.commitAllowingStateLoss();
|
} else if (playUrl != null
|
&& playUrl.getResource().getName().contains("搜狐")) {
|
iv_background.setClickable(true);
|
if (mSohuVideoFragment != null)
|
fm.beginTransaction().remove(mSohuVideoFragment)
|
.commitAllowingStateLoss();
|
} else if (playUrl != null
|
&& playUrl.getResource().getName().contains("优酷")) {
|
iv_background.setClickable(true);
|
if (mYoukuPlayerFragment != null)
|
fm.beginTransaction().remove(mYoukuPlayerFragment)
|
.commitAllowingStateLoss();
|
} else if (playUrl != null
|
&& playUrl.getResource().getName().contains("LeTV")) {
|
iv_background.setClickable(true);
|
if (mLeTVVideoFragment != null)
|
fm.beginTransaction().remove(mLeTVVideoFragment)
|
.commitAllowingStateLoss();
|
}
|
}
|
|
@Override
|
public void onConfigurationChanged(Configuration newConfig) {
|
super.onConfigurationChanged(newConfig);
|
Log.i(TAG, "onConfigurationChanged");
|
checkConfiguration(newConfig);
|
}
|
|
/**
|
* 方向改变后相关的参数设置
|
*
|
* @param newConfig
|
*/
|
private void checkConfiguration(Configuration newConfig) {
|
Log.i(TAG, "checkConfiguration");
|
if (newConfig == null)
|
return;
|
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {//横屏
|
findViewById(R.id.fl_video_detail).setVisibility(View.GONE);
|
findViewById(R.id.v_status_bar).setVisibility(View.GONE);
|
ViewGroup.LayoutParams params1 = findViewById(R.id.v_status_bar).getLayoutParams();
|
params1.height = 0;
|
|
// Hide the status bar隐藏状态栏
|
//测试 不做全屏
|
WindowManager.LayoutParams attrs = getWindow().getAttributes();
|
attrs.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
|
getWindow().setAttributes(attrs);
|
|
Fragment videoDetailFragment = getSupportFragmentManager()
|
.findFragmentByTag("VideoDetailFragment");
|
if (videoDetailFragment != null && !videoDetailFragment.isHidden()) {
|
getSupportFragmentManager().beginTransaction()
|
.hide(videoDetailFragment).commitAllowingStateLoss();
|
}
|
|
if (playUrl != null
|
&& playUrl.getResource().getName().contains("自主")) {
|
Fragment videoPlayerFragment = getSupportFragmentManager()
|
.findFragmentByTag("VideoPlayerFragment");
|
if (videoPlayerFragment != null) {
|
}
|
}
|
|
|
android.widget.LinearLayout.LayoutParams params = new android.widget.LinearLayout.LayoutParams(
|
LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
|
findViewById(R.id.fragment_video_play_container1).setLayoutParams(
|
params);
|
if (mFunshionPlayerFragment != null)
|
mFunshionPlayerFragment.requestLayout();
|
} else {
|
findViewById(R.id.v_status_bar).setVisibility(View.VISIBLE);
|
findViewById(R.id.fl_video_detail).setVisibility(View.VISIBLE);
|
ViewGroup.LayoutParams params1 = findViewById(R.id.v_status_bar).getLayoutParams();
|
params1.height = DimenUtils.getStatusBarHeight(getApplicationContext());
|
|
// Show the status bar显示状态栏
|
WindowManager.LayoutParams attrs = getWindow().getAttributes();
|
attrs.flags &= ~WindowManager.LayoutParams.FLAG_FULLSCREEN;
|
getWindow().setAttributes(attrs);
|
|
Fragment videoDetailFragment = getSupportFragmentManager()
|
.findFragmentByTag("VideoDetailFragment");
|
if (videoDetailFragment != null) {
|
getSupportFragmentManager().beginTransaction()
|
.show(videoDetailFragment).commitAllowingStateLoss();
|
}
|
|
if (playUrl != null
|
&& playUrl.getResource().getName().contains("自主")) {
|
Fragment videoPlayerFragment = getSupportFragmentManager()
|
.findFragmentByTag("VideoPlayerFragment");
|
|
}
|
|
FrameLayout layout = findViewById(R.id.fragment_video_play_container1);
|
if (layout == null)
|
return;
|
android.view.ViewGroup.LayoutParams layoutParams = layout
|
.getLayoutParams();
|
layoutParams.height = (int) (DimenUtils.getScreenWidth(this) * 0.5625f);
|
layout.requestLayout();
|
if (mFunshionPlayerFragment != null)
|
mFunshionPlayerFragment.requestLayout();
|
}
|
|
}
|
|
@Override
|
public void onResume() {
|
Log.i(TAG, "onResume");
|
super.onResume();
|
EventBus.getDefault().register(this);
|
if (fl_ad.getVisibility() == View.GONE) {
|
iv_select_play.setVisibility(View.VISIBLE);
|
}
|
}
|
|
@Override
|
public void onPause() {
|
Log.i(TAG, "onPause");
|
super.onPause();
|
EventBus.getDefault().unregister(this);
|
}
|
|
public void onEventMainThread(ChangeVideoEvent changeVideoEvent) {
|
VideoInfo videoInfo = changeVideoEvent.getVideoInfo();
|
resourceId = "";
|
if (!progressDialog.isShowing()) {
|
progressDialog.show();
|
}
|
uploadSession();
|
getVideoDetail(this, videoInfo.getId(), videoInfo.getThirdType(), false, changeVideoEvent.getFrom());
|
}
|
|
public void onEventMainThread(Play info) {
|
Log.i("mResult", "VideoDetailActivity-----onEventMainThread----开始播放");
|
playUrl = info.getPlayUrl();
|
if (videoInfo == null) {
|
return;
|
}
|
try {
|
startPlay();
|
} catch (IndexOutOfBoundsException e) {
|
e.printStackTrace();
|
}
|
}
|
|
public void onEventMainThread(VideoInfo info) {
|
Log.i(TAG, "onEventMainThread-videoInfo");
|
videoInfo = info;
|
}
|
|
//上报session
|
private void uploadSession() {
|
if (StringUtils.isEmpty(sessionId)) {
|
return;
|
}
|
BeibeiVideoAPI.uploadSession(getApplicationContext(), sessionId, "videoDetail", new BasicTextHttpResponseHandler() {
|
@Override
|
public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception {
|
}
|
});
|
}
|
|
//赚影视豆
|
private Runnable makeGoldCornRunnable;
|
|
private void getVideoDetail(final Context context, String videoId,
|
String videoThirdType, final boolean isSetup, final String fromName) {
|
int position = getIntent().getIntExtra(
|
"playing_position", 0);
|
SharedPreferences preferences = context.getSharedPreferences("user",
|
Context.MODE_PRIVATE);
|
String uid = preferences.getString("uid", "");
|
String loginid = preferences.getString("LoginUid", "");
|
BeibeiVideoAPI.getVideoDetail(context, uid, resourceId, videoId, position, loginid,
|
videoThirdType, fromName, new BasicTextHttpResponseHandler() {
|
|
@Override
|
public void onStart() {
|
super.onStart();
|
}
|
|
@Override
|
public void onFailure(int statusCode, Header[] headers,
|
String responseString, Throwable throwable) {
|
super.onFailure(statusCode, headers, responseString,
|
throwable);
|
if (progressDialog.isShowing()) {
|
progressDialog.dismiss();
|
}
|
findViewById(R.id.fragment_video_detail_container)
|
.setVisibility(View.GONE);
|
findViewById(R.id.fragment_video_episode_container)
|
.setVisibility(View.GONE);
|
findViewById(R.id.iv_download_failure).setVisibility(
|
View.VISIBLE);
|
}
|
|
@Override
|
public void onSuccessPerfect(int statusCode,
|
Header[] headers, JSONObject jsonObject)
|
throws Exception {
|
|
|
// if (BeibeiConstant.DEBUG)
|
// Toast.makeText(VideoDetailActivity2.this,
|
// "onSuccessPerfect",
|
// Toast.LENGTH_SHORT).show();
|
iv_background.setClickable(true);
|
try {
|
if (((Activity) context).isDestroyed()) {
|
return;
|
}
|
} catch (NoSuchMethodError e) {
|
e.printStackTrace();
|
}
|
if (jsonObject.getBoolean("IsPost")) {
|
|
if (BeibeiConstant.watchVideoGoldCorn != null && BeibeiConstant.watchVideoGoldCorn.expireTime > System.currentTimeMillis() && getIntent() != null) {
|
getIntent().putExtra("goldcorn", BeibeiConstant.watchVideoGoldCorn.goldcorn);
|
BeibeiConstant.watchVideoGoldCorn = null;
|
}
|
|
//挣影视豆
|
makeGoldCornRunnable = GoldCornUtil.makeGoldCorn(getIntent(), fl_video_play_background, videoId, resourceId, 20, null);
|
|
JSONObject data = jsonObject.optJSONObject("Data");
|
boolean pptv = data.optBoolean("pptv", false);
|
if (pptv) {
|
UmengEventUtil.pptvPlay(getApplicationContext());
|
String playUrl = data.optString("playUrl");
|
sessionId = data.optString("sessionId");
|
|
fl_pptv.setVisibility(View.VISIBLE);
|
ll_other.setVerticalGravity(View.GONE);
|
PPTVPlayFragment pptvPlayFragment = new PPTVPlayFragment();
|
Bundle bundle = new Bundle();
|
bundle.putString("playUrl", playUrl);
|
bundle.putString("videoId", data.optString("videoId"));
|
bundle.putString("name", data.optString("name"));
|
pptvPlayFragment.setArguments(bundle);
|
getSupportFragmentManager().beginTransaction().replace(R.id.fl_pptv, pptvPlayFragment).commit();
|
if (progressDialog.isShowing()) {
|
progressDialog.dismiss();
|
}
|
return;
|
} else {
|
fl_pptv.setVisibility(View.GONE);
|
ll_other.setVisibility(View.VISIBLE);
|
}
|
|
|
findViewById(R.id.fragment_video_detail_container)
|
.setVisibility(View.VISIBLE);
|
findViewById(R.id.fragment_video_episode_container)
|
.setVisibility(View.VISIBLE);
|
findViewById(R.id.iv_download_failure)
|
.setVisibility(View.GONE);
|
if (!isSetup) {
|
update();
|
}
|
|
Gson gson = new GsonBuilder().setFieldNamingPolicy(
|
FieldNamingPolicy.UPPER_CAMEL_CASE)
|
.create();
|
JSONObject videoJson = data.optJSONObject("Video");
|
final VideoInfo videoInfo = gson
|
.fromJson(videoJson
|
.toString(),
|
new TypeToken<VideoInfo>() {
|
}.getType());
|
if (videoInfo != null) {
|
VideoUtil.saveVideoEpisodeList(BeibeiVideoApplication.application, videoInfo.getVideoDetailList(), false);
|
}
|
|
if (data.optJSONObject("AdInfo") != null) {
|
adInfo = gson.fromJson(data.optJSONObject("AdInfo").toString(), VideoDetailAdInfoVO.class);
|
}
|
// 关注
|
if (data.optJSONObject("Attention") != null) {
|
JSONObject obj = data.optJSONObject("Attention");
|
Follow attention = new Follow();
|
attention.setMoviePicture(obj.optString("Picture"));
|
attention.setMovieName(obj.optString("Name"));
|
attention.setUpdateInfo(obj.optString("UpdateInfo"));
|
attention.setAttention(obj.optBoolean("Attention"));
|
videoInfo.setAttention(attention);
|
}
|
VideoDetailActivity2.this.videoInfo = videoInfo;
|
JSONArray extraData = jsonObject
|
.optJSONArray("Extra");
|
if (extraData != null)
|
videoInfo.setExtraData(extraData.toString());
|
|
|
for (int i = 0; i < videoInfo.getResourceList().size(); i++) {
|
if (videoInfo.getResourceList().get(i).isChecked()) {
|
resource = videoInfo.getResourceList().get(i);
|
}
|
}
|
if (VideoUtil.videoEpisodeList == null
|
|| VideoUtil.videoEpisodeList.isEmpty()) {
|
Toast.makeText(VideoDetailActivity2.this,
|
"影片已删除", Toast.LENGTH_LONG).show();
|
finish();
|
return;
|
}
|
|
sessionId = data.optString("SessionId");
|
|
|
Glide.with(getApplicationContext())
|
.load(videoInfo.getPlayPicture()).apply(new RequestOptions().centerCrop()).into(target);
|
if (isSetup) {
|
int position = getIntent().getIntExtra(
|
"playing_position", 0);
|
boolean isFromWatchHistory = getIntent()
|
.getBooleanExtra("isFromWatchHistory",
|
false);// 是否从观看记录点击过来
|
Log.i("mResult", "是否是从观看记录点击进来的:" + isFromWatchHistory);
|
if (isFromWatchHistory || position > 0) {
|
mPosition = getIntent().getIntExtra("playing_position", 0);
|
//防止数组越界
|
mPosition = mPosition >= VideoUtil.videoEpisodeList.size() ? VideoUtil.videoEpisodeList.size() - 1 : mPosition;
|
EventBus.getDefault().post(videoInfo);
|
getUrl(VideoUtil.videoEpisodeList.get(mPosition), isSetup);
|
EventBus.getDefault().post(VideoUtil.videoEpisodeList.get(mPosition));
|
} else {// 不是从观看记录点击过来 --跳到当前播放的集数
|
// position = VideoPlayUrlUtil
|
// .getVideoDetailPosition(context,
|
// videoInfo);
|
EventBus.getDefault().post(videoInfo);
|
if (StringUtils.isEmpty(detailid)) {
|
getUrl(VideoUtil.videoEpisodeList.get(
|
position), isSetup);
|
EventBus.getDefault().post(
|
VideoUtil.videoEpisodeList.get(
|
position));
|
} else {
|
if (VideoUtil.videoEpisodeList != null)
|
for (int i = 0; i < VideoUtil.videoEpisodeList.size(); i++) {
|
if (detailid.equalsIgnoreCase(VideoUtil.videoEpisodeList.get(i).getId())) {
|
getUrl(VideoUtil.videoEpisodeList.get(
|
i), false);
|
PushEpisode info = new PushEpisode();
|
info.setEpisodeNum(i);
|
EventBus.getDefault().post(
|
VideoUtil.videoEpisodeList.get(
|
i));
|
}
|
}
|
}
|
}
|
} else {
|
for (int i = 0; i < videoInfo.getResourceList().size(); i++) {
|
if (videoInfo.getResourceList().get(i).isChecked()) {
|
resource = videoInfo.getResourceList().get(i);
|
}
|
}
|
getUrl(VideoUtil.videoEpisodeList.get(0),
|
true);
|
findViewById(android.R.id.content).postDelayed(
|
new Runnable() {
|
|
@Override
|
public void run() {
|
|
try {
|
EventBus.getDefault().post(
|
videoInfo);
|
EventBus.getDefault()
|
.post(VideoUtil.videoEpisodeList
|
.get(0));
|
} catch (NullPointerException e) {
|
//出现过空指针的异常
|
}
|
}
|
}, 200);
|
}
|
|
} else {
|
findViewById(R.id.fragment_video_detail_container)
|
.setVisibility(View.GONE);
|
findViewById(R.id.fragment_video_episode_container)
|
.setVisibility(View.GONE);
|
findViewById(R.id.iv_download_failure)
|
.setVisibility(View.VISIBLE);
|
}
|
if (progressDialog.isShowing()) {
|
progressDialog.dismiss();
|
}
|
|
//加载视频广告
|
if (!BeibeiConstant.IS_TEST)
|
loadFullVideoAd();
|
}
|
});
|
}
|
|
private PlayUrl playUrl;
|
|
private void getUrl(VideoDetailInfo info, final boolean isSetup) {
|
SharedPreferences preferences = getSharedPreferences("user",
|
Context.MODE_PRIVATE);
|
String uid = preferences.getString("uid", "");
|
BeibeiVideoAPI.getPlayUrl(this, uid, info.getType(), videoInfo.getId(), info.getId(),
|
resource.getId(), info.geteId(), new BasicTextHttpResponseHandler() {
|
|
@Override
|
public void onSuccessPerfect(int statusCode,
|
Header[] headers, JSONObject jsonObject)
|
throws Exception {
|
if (jsonObject.getBoolean("IsPost")) {
|
Gson gson = new GsonBuilder().setFieldNamingPolicy(
|
FieldNamingPolicy.UPPER_CAMEL_CASE)
|
.create();
|
VideoResource resource = gson.fromJson(
|
jsonObject.getJSONObject("Data")
|
.getJSONObject("Resource")
|
.toString(),
|
new TypeToken<VideoResource>() {
|
}.getType());
|
PlayUrl info = new PlayUrl();
|
info.setResource(resource);
|
JSONObject data = jsonObject
|
.getJSONObject("Data");
|
info.setPlayType(Integer.parseInt(
|
data.optString("PlayType")));
|
info.setUrl(data
|
.optString("Url"));
|
info.setParams(data
|
.optString("Params"));
|
info.setAid(data.optString("Aid"));
|
info.setVid(data.optString("Vid"));
|
info.setCode(jsonObject.getJSONObject("Data")
|
.optString("Code"));
|
playUrl = info;
|
if (videoInfo == null) {
|
return;
|
}
|
|
if (!isSetup || isClick) {
|
fl_ad.setVisibility(View.VISIBLE);
|
startPlay();
|
isClick = false;
|
}
|
}
|
}
|
});
|
}
|
|
private VideoResource resource;
|
|
public void onEventMainThread(VideoResource resource) {
|
this.resource = resource;
|
}
|
|
private void update() {
|
FragmentTransaction transaction = getSupportFragmentManager()
|
.beginTransaction();
|
Fragment videoDetailFragment = new VideoDetailFragment();
|
transaction.replace(R.id.fragment_video_detail_container,
|
videoDetailFragment, "VideoDetailFragment");
|
transaction.commitAllowingStateLoss();
|
checkConfiguration(getResources().getConfiguration());
|
Log.i(TAG, "update");
|
}
|
|
@Override
|
public void onClick(View v) {
|
switch (v.getId()) {
|
case R.id.iv_download_failure:
|
iNet();
|
break;
|
case R.id.iv_back:
|
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
|
clickBack();
|
} else if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
|
finish();
|
}
|
break;
|
|
default:
|
break;
|
}
|
}
|
|
/**
|
* video网络数据请求
|
*/
|
private void iNet() {
|
if (VideoUtil.videoEpisodeList == null
|
|| VideoUtil.videoEpisodeList.isEmpty()) {
|
getVideoDetail(this, videoInfo.getId(), videoInfo.getThirdType(),
|
true, from);
|
} else {
|
findViewById(android.R.id.content).postDelayed(new Runnable() {
|
|
@Override
|
public void run() {
|
EventBus.getDefault().post(videoInfo);
|
int position = getIntent().getIntExtra("playing_position", 0) >=
|
VideoUtil.videoEpisodeList.size() ? VideoUtil.videoEpisodeList.size() - 1 : getIntent().getIntExtra("playing_position",
|
0);
|
EventBus.getDefault().post(
|
VideoUtil.videoEpisodeList.get(position));
|
}
|
}, 200);
|
}
|
}
|
|
private void saveWatchHistory(String from) {
|
if (videoInfo != null) {
|
String videoDetailId = "";
|
if (VideoUtil.videoEpisodeList == null || VideoUtil.videoEpisodeList.size() == 0)
|
return;
|
if (mPosition >= VideoUtil.videoEpisodeList.size()) {
|
videoDetailId = VideoUtil.videoEpisodeList.get(0)
|
.getId();
|
} else {
|
videoDetailId = VideoUtil.videoEpisodeList.get(mPosition)
|
.getId();
|
}
|
String resoureID = "";
|
for (int i = 0; i < videoInfo.getResourceList().size(); i++) {
|
if (videoInfo.getResourceList().get(i).isChecked()) {
|
resoureID = videoInfo.getResourceList().get(i).getId();
|
}
|
}
|
Cursor cursor = getContentResolver().query(
|
WatchHistoryTable.CONTENT_URI, null,
|
WatchHistoryTable.VIDEO_DETAIL_ID + " = ? ",
|
new String[]{videoDetailId}, null);
|
Cursor cursor1 = getContentResolver().query(
|
WatchHistoryTable.CONTENT_URI, null,
|
WatchHistoryTable.VIDEO_ID + " = ? ",
|
new String[]{videoInfo.getId()}, null);
|
if (cursor == null || cursor1 == null) {
|
return;
|
}
|
|
long now = System.currentTimeMillis();
|
if (cursor1.getCount() > 0) {
|
getContentResolver().delete(WatchHistoryTable.CONTENT_URI,
|
WatchHistoryTable.VIDEO_ID + " = ? ", new String[]{videoInfo.getId()});
|
}
|
cursor1.close();
|
//添加值至数据库
|
ContentValues values = new ContentValues();
|
values.put(WatchHistoryTable.VIDEO_ID, videoInfo.getId());
|
values.put(WatchHistoryTable.VIDEO_DETAIL_ID, videoDetailId);
|
values.put(WatchHistoryTable.VIDEO_THIRD_TYPE,
|
videoInfo.getThirdType());
|
Gson gson = new GsonBuilder().setFieldNamingPolicy(
|
FieldNamingPolicy.UPPER_CAMEL_CASE).create();
|
values.put(WatchHistoryTable.VIDEO_DETAIL,
|
gson.toJson(videoInfo));
|
values.put(WatchHistoryTable.WATCH_TIME, 0);
|
values.put(WatchHistoryTable.VIDEO_RESOURCE, from);
|
values.put(WatchHistoryTable.VIDEO_RESOURCE_ID, resoureID);
|
values.put(WatchHistoryTable.UPDATE_TIME, now);
|
values.put(WatchHistoryTable.CREATE_TIME, now);
|
//插入数据库值
|
try {
|
getContentResolver().insert(WatchHistoryTable.CONTENT_URI,
|
values);
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
|
cursor.close();
|
//更新数据库
|
getContentResolver().update(WatchHistoryTable.CONTENT_URI,
|
values, WatchHistoryTable.VIDEO_DETAIL_ID + " = ? ",
|
new String[]{videoDetailId});
|
|
cursor = getContentResolver().query(WatchHistoryTable.CONTENT_URI,
|
new String[]{WatchHistoryTable._ID}, null, null,
|
WatchHistoryTable._ID + " desc");
|
List<Long> longList = new ArrayList<Long>();
|
while (cursor.moveToNext()) {
|
longList.add(cursor.getLong(0));
|
}
|
cursor.close();
|
if (longList.size() > 30) {
|
int count = getContentResolver().delete(
|
WatchHistoryTable.CONTENT_URI,
|
WatchHistoryTable._ID + "<?",
|
new String[]{longList.get(30) + ""});
|
}
|
}
|
}
|
|
@Override
|
protected void onStop() {
|
super.onStop();
|
}
|
|
@Override
|
protected void onDestroy() {
|
super.onDestroy();
|
if (BeibeiConstant.AD_TYPE != null && BeibeiConstant.AD_TYPE.isVideoDetailSplashAd())
|
FullVideoAdManager.getInstance().loadAd(BeibeiVideoApplication.application, null);
|
uploadSession();
|
GoldCornUtil.removeCallbacks(fl_video_play_background, makeGoldCornRunnable);
|
}
|
}
|