package com.yeshi.video.ui;
|
|
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 android.util.Log;
|
import android.view.KeyEvent;
|
import android.view.View;
|
import android.view.View.OnClickListener;
|
import android.view.WindowManager;
|
import android.widget.FrameLayout;
|
import android.widget.ImageView;
|
import android.widget.LinearLayout;
|
import android.widget.LinearLayout.LayoutParams;
|
import android.widget.SeekBar;
|
import android.widget.TextView;
|
import android.widget.Toast;
|
|
import com.alibaba.android.arouter.facade.annotation.Route;
|
import com.alibaba.android.arouter.launcher.ARouter;
|
import com.bumptech.glide.Glide;
|
import com.bumptech.glide.request.target.SimpleTarget;
|
import com.bumptech.glide.request.transition.Transition;
|
import com.bytedance.sdk.openadsdk.TTAdSdk;
|
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.util.DialogUtils;
|
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.qq.e.ads.cfg.VideoOption;
|
import com.qq.e.ads.interstitial2.UnifiedInterstitialAD;
|
import com.qq.e.ads.interstitial2.UnifiedInterstitialADListener;
|
import com.qq.e.comm.util.AdError;
|
import com.umeng.socialize.UMShareAPI;
|
import com.yeshi.base.entity.AccumulateRule;
|
import com.yeshi.base.entity.ad.AdPositionEnum;
|
import com.yeshi.base.entity.db.WatchHistoryTable;
|
import com.yeshi.base.entity.video.Follow;
|
import com.yeshi.base.entity.video.Play;
|
import com.yeshi.base.entity.video.PlayUrl;
|
import com.yeshi.base.entity.video.VideoDetailInfo;
|
import com.yeshi.base.entity.video.VideoInfo;
|
import com.yeshi.base.entity.video.VideoResource;
|
import com.yeshi.base.ui.BaseActivity;
|
import com.yeshi.base.utils.BeibeiConstant;
|
import com.yeshi.base.utils.RouteConstant;
|
import com.yeshi.base.utils.ad.AdUtil;
|
import com.yeshi.base.utils.ad.GDTConstant;
|
import com.yeshi.base.utils.ad.TTAdManagerHolder;
|
import com.yeshi.base.utils.http.BasicTextHttpResponseHandler;
|
import com.yeshi.video.R;
|
import com.yeshi.video.entity.PushEpisode;
|
import com.yeshi.video.utils.VideoApiUtil;
|
import com.yeshi.video.utils.VideoUtil;
|
import com.yeshi.video.utils.ad.FullVideoAdManager;
|
|
import org.apache.http.Header;
|
import org.json.JSONArray;
|
import org.json.JSONObject;
|
|
import java.io.File;
|
import java.io.FileInputStream;
|
import java.io.FileOutputStream;
|
import java.io.IOException;
|
import java.io.InputStream;
|
import java.util.ArrayList;
|
import java.util.List;
|
|
import androidx.annotation.NonNull;
|
import androidx.annotation.Nullable;
|
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.FragmentManager;
|
import androidx.fragment.app.FragmentTransaction;
|
import de.greenrobot.event.EventBus;
|
|
/*
|
* 视频详情
|
*
|
* @author Administrator
|
*/
|
//
|
@Route(path = RouteConstant.PATH_VIDEO_DETAIL)
|
public class VideoDetailActivity extends BaseActivity implements
|
OnClickListener {
|
|
// private boolean mLandscape;
|
private VideoInfo videoInfo;
|
|
private ImageView iv_download_failure;
|
private ImageView iv_background;
|
|
private TextView tv_back;
|
|
private FrameLayout fl_banner;
|
|
private String resourceId = "";
|
|
private String detailid = "";
|
private Fragment mIQYVideoPlayerFragment;
|
private ProgressDialog progressDialog;
|
private SeekBar seekBar_down_so;
|
private TextView tv_progress;
|
private FunshionPlayerFragment mFunshionPlayerFragment;
|
|
private FragmentManager fm = getSupportFragmentManager();
|
|
private FrameLayout fl_pptv;
|
private LinearLayout ll_other;
|
|
private boolean adShown = false;
|
|
@Override
|
public void onCreate(Bundle savedInstanceState) {
|
super.onCreate(savedInstanceState);
|
// if (!LibsChecker.checkVitamioLibs(this))
|
// return;
|
// mLandscape = getIntent()
|
// .getBooleanExtra("orientation_landscape", false);
|
// if (mLandscape) {
|
// setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
|
// }
|
setContentView(R.layout.video_detail_activity);
|
ARouter.getInstance().inject(this);
|
seekBar_down_so = (SeekBar) findViewById(R.id.seekbar_load_so);
|
tv_progress = (TextView) findViewById(R.id.tv_progrerss);
|
|
fl_pptv = findViewById(R.id.fl_pptv);
|
ll_other = findViewById(R.id.ll_other);
|
|
seekBar_down_so.setMax(100);
|
seekBar_down_so
|
.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
|
@Override
|
public void onProgressChanged(SeekBar seekBar,
|
int progress, boolean fromUser) {
|
tv_progress.setText(progress + "%");
|
}
|
|
@Override
|
public void onStartTrackingTouch(SeekBar seekBar) {
|
|
}
|
|
@Override
|
public void onStopTrackingTouch(SeekBar seekBar) {
|
|
}
|
});
|
|
progressDialog = new ProgressDialog(this, ProgressDialog.STYLE_SPINNER);
|
progressDialog.setCanceledOnTouchOutside(false);
|
progressDialog.setMessage("正在请求网络...");
|
progressDialog.show();
|
|
tv_back = (TextView) findViewById(R.id.iv_back);
|
tv_back.setOnClickListener(this);
|
iv_download_failure = (ImageView) findViewById(R.id.iv_download_failure);
|
iv_download_failure.setOnClickListener(this);
|
if (getIntent().getSerializableExtra("video_info") != null) {
|
videoInfo = (VideoInfo) getIntent().getSerializableExtra(
|
"video_info");
|
videoInfo.setVideoDetailList(new ArrayList<>());
|
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 ("1".equals(videoInfo.getShare())) {
|
// SharedPreferences preferences = getSharedPreferences("user",
|
// Context.MODE_PRIVATE);
|
// if (!preferences.getBoolean("shared", false)) {
|
// Toast.makeText(VideoDetailActivity.this, "该影片需要分享之后才能观看",
|
// Toast.LENGTH_LONG).show();
|
// startActivity(getIntent().setClass(VideoDetailActivity.this,
|
// ShareActivity.class));
|
// finish();
|
// return;
|
// }
|
// }
|
|
LayoutParams params = new LayoutParams(
|
(int) SystemCommon.getScreenWidth(this),
|
(int) ((SystemCommon.getScreenWidth(this) * 9) / 16));
|
findViewById(R.id.fragment_video_play_container1).setLayoutParams(
|
params);
|
fl_video_play_background = (FrameLayout) findViewById(R.id.fl_video_play_background);
|
iv_select_play = (ImageView) findViewById(R.id.iv_select_play);
|
iv_background = (ImageView) findViewById(R.id.iv_video_play_background);
|
FrameLayout.LayoutParams params1 = new FrameLayout.LayoutParams(
|
DimenUtils.dip2px(this, 80),
|
DimenUtils.dip2px(this, 60));
|
params1.topMargin = (int) ((SystemCommon.getScreenWidth(this) * 9 / 16f - DimenUtils
|
.dip2px(this, 60)) / 2);
|
params1.leftMargin = (int) ((SystemCommon.getScreenWidth(this) - DimenUtils
|
.dip2px(this, 80)) / 2);
|
iv_select_play.setLayoutParams(params1);
|
fl_banner = (FrameLayout) findViewById(R.id.fl_banner);
|
// initBanner();
|
iv_select_play.setOnClickListener(new OnClickListener() {
|
|
@Override
|
public void onClick(View arg0) {
|
if (videoInfo == null) {
|
return;
|
}
|
clickPlay();
|
}
|
});
|
iv_background.setOnClickListener(new OnClickListener() {
|
@Override
|
public void onClick(View v) {
|
if (videoInfo == null) {
|
return;
|
}
|
clickPlay();
|
}
|
});
|
iv_background.setClickable(false);
|
Fragment videoDetailFragment = fm
|
.findFragmentByTag("VideoDetailFragment");
|
if (videoDetailFragment == null) {
|
videoDetailFragment = new VideoDetailFragment();
|
fm.beginTransaction()
|
.add(R.id.fragment_video_detail_container,
|
videoDetailFragment, "VideoDetailFragment")
|
.commitAllowingStateLoss();
|
}
|
|
// checkConfiguration(getResources().getConfiguration());
|
// video网络数据请求
|
iNet();
|
}
|
|
private static FrameLayout fl_video_play_background;
|
private static ImageView iv_select_play;
|
|
public static void hideImage() {
|
if (iv_select_play != null) {
|
iv_select_play.setVisibility(View.GONE);
|
fl_video_play_background.setVisibility(View.GONE);
|
}
|
}
|
|
private int mPosition = 0;
|
|
// public void onEventMainThread(Playlocation location) {
|
// mPosition = location.getPosition();
|
// }
|
|
Fragment mSohuVideoFragment;
|
Fragment mLeTVVideoFragment;
|
Fragment mYoukuPlayerFragment;
|
|
// private PPTVSdkStatusListener mListener = new PPTVSdkStatusListener() {
|
//
|
// @Override
|
// public void onInitBegin() {
|
// }
|
//
|
// @Override
|
// public void onInitEnd(int error) {
|
// if (error == 0) {
|
// Log.e("pptv_sdk", "onInitEnd: " + error);
|
// Log.e("mResult", "videolist是否为空: " +
|
// (videoInfo.getVideoDetailList().size() == 0 ? true : false));
|
//
|
// }
|
// }
|
//
|
// };
|
|
/**
|
* 广点通Banner
|
*/
|
|
|
private boolean isFirst = true;
|
|
private void clickPlay() {
|
// fl_banner.setVisibility(View.GONE);
|
if (playUrl == null) {
|
SingleToast
|
.showToast(VideoDetailActivity.this, "初始化播放路径中,请稍候点击播放!");
|
return;
|
}
|
if (playUrl.getPlayType() != 1
|
&& !playUrl.getResource().getName().contains("PPTV")) {
|
setViewOrientation();
|
}
|
|
// iv_select_play.setVisibility(View.GONE);
|
// iv_background.setClickable(false);
|
// mLeTVVideoFragment = new LeTVVideoFragment();
|
// Bundle mBundle = new Bundle();
|
// mBundle.putInt(PlayerParams.KEY_PLAY_MODE,
|
// PlayerParams.VALUE_PLAYER_VOD);
|
// mBundle.putString(PlayerParams.KEY_PLAY_UUID,
|
// BeibeiConstant.LETV_SDK_ID);
|
// mBundle.putString(PlayerParams.KEY_PLAY_VUID, "300268763");
|
// mBundle.putString(PlayerParams.KEY_PLAY_BUSINESSLINE, "102");
|
// mBundle.putBoolean("saas", true);
|
// mLeTVVideoFragment.setArguments(mBundle);
|
//
|
// fm.beginTransaction()
|
// .replace(R.id.fragment_video_play_container,
|
// mLeTVVideoFragment, "LeTVVideoFragment")
|
// .commitAllowingStateLoss();
|
// // EventBus.getDefault().post(playUrl);
|
// Toast.makeText(VideoDetailActivity.this, "影片加载中...",
|
// Toast.LENGTH_LONG).show();
|
|
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);
|
}
|
}
|
if (playUrl.getResource().getName().contains("优酷")) {
|
if (playUrl.getPlayType() == 1) {
|
Intent intent = new Intent(VideoDetailActivity.this,
|
VideoPlayerBrowserActivity.class);
|
intent.putExtra("url", playUrl.getUrl());
|
startActivity(intent);
|
saveWatchHistory("优酷");
|
} else if (playUrl.getPlayType() == 2) {
|
// JSONObject object = null;
|
// try {
|
// object = new JSONObject(playUrl.getParams());
|
// } catch (JSONException e) {
|
// e.printStackTrace();
|
// }
|
// // intent.putExtra("playId", object.optString("vid"));
|
// // startActivity(intent);
|
// mYoukuPlayerFragment = new YouKuPlayerFragment();
|
// Bundle bundle = new Bundle();
|
// bundle.putSerializable("vid", object.optString("vid"));
|
// bundle.putSerializable("position", mPosition);
|
// bundle.putSerializable("videoinfo", videoInfo);
|
// mYoukuPlayerFragment.setArguments(bundle);
|
// fm.beginTransaction()
|
// .replace(R.id.fragment_video_play_container,
|
// mYoukuPlayerFragment, "YouKuPlayerFragment")
|
// .commitAllowingStateLoss();
|
}
|
} else if (playUrl.getResource().getName().contains("搜狐")) {
|
if (playUrl.getPlayType() == 1) {
|
Intent intent = new Intent(VideoDetailActivity.this,
|
VideoPlayerBrowserActivity.class);
|
intent.putExtra("url", playUrl.getUrl());
|
startActivity(intent);
|
saveWatchHistory("搜狐");
|
} else if (playUrl.getPlayType() == 2) {
|
// mSohuVideoFragment = (SohuVideoFragment) fm
|
// .findFragmentByTag("SohuVideoFragment");
|
// mSohuVideoFragment = new SohuVideoFragment();
|
// Bundle bundle = new Bundle();
|
// bundle.putSerializable("playUrl", playUrl);
|
// bundle.putSerializable("videoinfo", videoInfo);
|
// bundle.putSerializable("position", mPosition);
|
// bundle.putSerializable("resource", resource);
|
// mSohuVideoFragment.setArguments(bundle);
|
// fm.beginTransaction()
|
// .replace(R.id.fragment_video_play_container,
|
// mSohuVideoFragment, "SohuVideoFragment")
|
// .commitAllowingStateLoss();
|
// EventBus.getDefault().post(playUrl);
|
}
|
} else if (playUrl.getResource().getName().contains("爱奇艺")) {
|
if (playUrl != null) {
|
if (playUrl.getPlayType() == 0) {
|
Toast.makeText(VideoDetailActivity.this, "此节目不可播!",
|
Toast.LENGTH_LONG).show();
|
return;
|
} else if (playUrl.getPlayType() == 1) {
|
Intent intent = new Intent(VideoDetailActivity.this,
|
VideoPlayerBrowserActivity.class);
|
intent.putExtra("url", playUrl.getUrl());
|
startActivity(intent);
|
} else if (playUrl.getPlayType() == 2) {
|
iv_select_play.setVisibility(View.GONE);
|
iv_background.setClickable(false);
|
mIQYVideoPlayerFragment = (IQYVideoFragment) 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(VideoDetailActivity.this, "影片加载中...",
|
Toast.LENGTH_LONG).show();
|
}
|
saveWatchHistory("爱奇艺");
|
}
|
} else if (playUrl.getResource().getName().contains("PPTV")) {
|
|
if (playUrl.getPlayType() == 0) {
|
Toast.makeText(VideoDetailActivity.this, "此节目不可播!",
|
Toast.LENGTH_LONG).show();
|
return;
|
} else if (playUrl.getPlayType() == 1) {
|
Intent intent = new Intent(VideoDetailActivity.this,
|
VideoPlayerBrowserActivity.class);
|
intent.putExtra("url", playUrl.getUrl());
|
startActivity(intent);
|
saveWatchHistory("PPTV");
|
}
|
// else if (playUrl.getPlayType() == 2) {
|
// init();
|
// }
|
} else if (playUrl.getResource().getName().contains("乐视")) {
|
if (playUrl.getPlayType() == 0) {
|
Toast.makeText(VideoDetailActivity.this, "此节目不可播!",
|
Toast.LENGTH_LONG).show();
|
return;
|
} else if (playUrl.getPlayType() == 1) {
|
Intent intent = new Intent(VideoDetailActivity.this,
|
VideoPlayerBrowserActivity.class);
|
intent.putExtra("url", playUrl.getUrl());
|
startActivity(intent);
|
saveWatchHistory("乐视");
|
}
|
// iv_select_play.setVisibility(View.GONE);
|
// iv_background.setClickable(false);
|
// mLeTVVideoFragment = new LeTVVideoFragment();
|
// Bundle mBundle = new Bundle();
|
// mBundle.putInt(PlayerParams.KEY_PLAY_MODE,
|
// PlayerParams.VALUE_PLAYER_VOD);
|
// mBundle.putString(PlayerParams.KEY_PLAY_UUID,
|
// BeibeiConstant.LETV_SDK_ID);
|
// mBundle.putString(PlayerParams.KEY_PLAY_VUID, "300268763");
|
// mBundle.putString(PlayerParams.KEY_PLAY_BUSINESSLINE, "102");
|
// mBundle.putBoolean("saas", true);
|
// mLeTVVideoFragment.setArguments(mBundle);
|
//
|
// fm.beginTransaction()
|
// .replace(R.id.fragment_video_play_container,
|
// mLeTVVideoFragment, "LeTVVideoFragment")
|
// .commitAllowingStateLoss();
|
// // EventBus.getDefault().post(playUrl);
|
// Toast.makeText(VideoDetailActivity.this, "影片加载中...",
|
// Toast.LENGTH_LONG).show();
|
|
} else if (playUrl.getResource().getName().contains("风行")) {
|
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();
|
}
|
hideImage();
|
|
|
} else {//
|
if (playUrl.getPlayType() == 0) {
|
Toast.makeText(VideoDetailActivity.this, "此节目不可播!",
|
Toast.LENGTH_LONG).show();
|
return;
|
} else if (playUrl.getPlayType() == 1) {
|
Intent intent = new Intent(VideoDetailActivity.this,
|
VideoPlayerBrowserActivity.class);
|
intent.putExtra("url", playUrl.getUrl());
|
startActivity(intent);
|
saveWatchHistory(playUrl.getResource().getName());
|
}
|
}
|
|
|
} else {
|
if (playUrl.getPlayType() == 0) {
|
Toast.makeText(VideoDetailActivity.this, "此节目不可播!",
|
Toast.LENGTH_LONG).show();
|
return;
|
} else if (playUrl.getPlayType() == 1) {
|
Intent intent = new Intent(VideoDetailActivity.this,
|
VideoPlayerBrowserActivity.class);
|
intent.putExtra("url", playUrl.getUrl());
|
startActivity(intent);
|
saveWatchHistory(playUrl.getResource().getName());
|
}
|
}
|
|
}
|
|
private boolean copyFileFromAssets(Context context, String fileName,
|
String path) {
|
boolean copyIsFinish = false;
|
try {
|
File f = context.getExternalFilesDir("pptv");
|
if (!f.exists()) {
|
f.mkdir();
|
}
|
InputStream inStream = new FileInputStream(f.getAbsolutePath()
|
+ File.separator + fileName); // 读入原文件
|
File file = new File(path);
|
file.createNewFile();
|
FileOutputStream fos = new FileOutputStream(file);
|
byte[] temp = new byte[1024];
|
int i = 0;
|
while ((i = inStream.read(temp)) > 0) {
|
fos.write(temp, 0, i);
|
}
|
fos.close();
|
inStream.close();
|
copyIsFinish = true;
|
} catch (IOException e) {
|
e.printStackTrace();
|
Log.e("MainActivity",
|
"[copyFileFromAssets] IOException " + e.toString());
|
}
|
return copyIsFinish;
|
}
|
|
private void setViewOrientation() {
|
findViewById(R.id.fl_video_detail).setVisibility(View.GONE);
|
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
|
LayoutParams params = new LayoutParams(
|
LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
|
findViewById(R.id.fragment_video_play_container1).setLayoutParams(
|
params);
|
findViewById(R.id.iv_select_play).postDelayed(new Runnable() {
|
|
@Override
|
public void run() {
|
checkConfiguration(getResources().getConfiguration());
|
}
|
}, 1000);
|
}
|
|
// private PlayUrl info;
|
//
|
// public void onEventMainThread(PlayUrl info) {
|
// this.info = info;
|
// }
|
|
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 onBackPressed() {
|
// if (mLandscape
|
// || 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 && event.getRepeatCount() == 0) { //
|
* 按下的如果是BACK,同时没有重复 if (mLandscape ||
|
* this.getResources().getConfiguration().orientation ==
|
* Configuration.ORIENTATION_PORTRAIT) { return true; //
|
* super.onBackPressed(); } else {
|
* setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); return
|
* false; } }
|
*
|
* return super.onKeyDown(keyCode, event); }
|
*/
|
@Override
|
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
if (keyCode == KeyEvent.KEYCODE_BACK
|
&& getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
|
clickBack();
|
return false;
|
} else if (keyCode == KeyEvent.KEYCODE_BACK
|
&& getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
|
finish();
|
return true;
|
} else {
|
return super.onKeyDown(keyCode, event);
|
}
|
}
|
|
public void onEventMainThread(AccumulateRule info) {// 播放界面返回替代使用
|
clickBack();
|
}
|
|
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() {
|
// fl_banner.setVisibility(View.VISIBLE);
|
// MOGOBanner.initAdvertisement(this, BeibeiConstant.MOGO_PLAYER_BANNER,
|
// fl_banner);
|
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
|
checkConfiguration(getResources().getConfiguration());
|
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();
|
}
|
LayoutParams params = new 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);
|
checkConfiguration(newConfig);
|
}
|
|
private void checkConfiguration(Configuration newConfig) {
|
if (newConfig == null)
|
return;
|
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
|
findViewById(R.id.fl_video_detail).setVisibility(View.GONE);
|
// 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) {
|
// ((VideoPlayerFragment)
|
// videoPlayerFragment).setVideoLayout(
|
// VideoView.VIDEO_LAYOUT_SCALE, 0);
|
((VideoPlayerFragment) videoPlayerFragment)
|
.onConfigurationChanged(newConfig);
|
}
|
}
|
|
android.view.ViewGroup.LayoutParams layoutParams = findViewById(
|
R.id.fragment_video_play_container1).getLayoutParams();
|
layoutParams.height = android.view.ViewGroup.LayoutParams.MATCH_PARENT;
|
findViewById(R.id.fragment_video_play_container1).requestLayout();
|
if (mFunshionPlayerFragment != null)
|
mFunshionPlayerFragment.requestLayout();
|
} else {
|
findViewById(R.id.fl_video_detail).setVisibility(View.VISIBLE);
|
// 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");
|
if (videoPlayerFragment != null) {
|
// ((VideoPlayerFragment)
|
// videoPlayerFragment).setVideoLayout(
|
// VideoView.VIDEO_LAYOUT_SCALE, 0);
|
((VideoPlayerFragment) videoPlayerFragment)
|
.onConfigurationChanged(newConfig);
|
}
|
}
|
|
FrameLayout layout = findViewById(R.id.fragment_video_play_container1);
|
if (layout == null)
|
return;
|
|
int screenWidth = (int) SystemCommon.getScreenWidth(getApplicationContext());
|
android.view.ViewGroup.LayoutParams layoutParams = layout
|
.getLayoutParams();
|
layoutParams.height = (int) (screenWidth * 0.5625f);
|
layout.requestLayout();
|
if (mFunshionPlayerFragment != null)
|
mFunshionPlayerFragment.requestLayout();
|
|
}
|
}
|
|
@Override
|
public void onResume() {
|
super.onResume();
|
EventBus.getDefault().register(this);
|
}
|
|
@Override
|
public void onPause() {
|
super.onPause();
|
EventBus.getDefault().unregister(this);
|
}
|
|
public void onEventMainThread(ChangeVideoEvent changeVideoEvent) {
|
VideoInfo videoInfo = changeVideoEvent.getVideoInfo();
|
resourceId = "";
|
if (!progressDialog.isShowing()) {
|
progressDialog.show();
|
}
|
getVideoDetail(this, videoInfo.getId(), videoInfo.getThirdType(), true);
|
}
|
|
public void onEventMainThread(Play info) {
|
Log.i("mResult", "VideoDetailActivity-----onEventMainThread----开始播放");
|
playUrl = info.getPlayUrl();
|
if (videoInfo == null) {
|
return;
|
}
|
try {
|
clickPlay();
|
} catch (IndexOutOfBoundsException e) {
|
e.printStackTrace();
|
}
|
|
}
|
|
public void onEventMainThread(VideoInfo info) {
|
videoInfo = info;
|
}
|
|
@Override
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
super.onActivityResult(requestCode, resultCode, data);
|
UMShareAPI.get(this).onActivityResult(requestCode, resultCode, data);
|
}
|
|
private void getVideoDetail(final Context context, String videoId,
|
String videoThirdType, final boolean isSetup) {
|
SharedPreferences preferences = context.getSharedPreferences("user",
|
Context.MODE_PRIVATE);
|
String uid = preferences.getString("uid", "");
|
String loginid = preferences.getString("LoginUid", "");
|
VideoApiUtil.getVideoDetail(context, uid, resourceId, videoId,
|
loginid, videoThirdType, new BasicTextHttpResponseHandler() {
|
|
@Override
|
public void onStart() {
|
super.onStart();
|
// if (BeibeiConstant.DEBUG)
|
// Toast.makeText(VideoDetailActivity.this, "onStart",
|
// Toast.LENGTH_SHORT).show();
|
}
|
|
@Override
|
public void onFailure(int statusCode, Header[] headers,
|
String responseString, Throwable throwable) {
|
super.onFailure(statusCode, headers, responseString,
|
throwable);
|
// if (BeibeiConstant.DEBUG)
|
// Toast.makeText(VideoDetailActivity.this, "onFailure",
|
// Toast.LENGTH_SHORT).show();
|
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 onFinish() {
|
super.onFinish();
|
if (progressDialog.isShowing()) {
|
progressDialog.dismiss();
|
}
|
}
|
|
@Override
|
public void onSuccessPerfect(int statusCode,
|
Header[] headers, JSONObject jsonObject)
|
throws Exception {
|
// if (BeibeiConstant.DEBUG)
|
// Toast.makeText(VideoDetailActivity.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")) {
|
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();
|
}
|
|
JSONObject data = jsonObject.optJSONObject("Data");
|
boolean pptv = data.optBoolean("pptv", false);
|
if (pptv) {
|
String playUrl = data.optString("playUrl");
|
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"));
|
bundle.putBoolean("vip", data.optBoolean("vip", false));
|
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);
|
}
|
|
|
Gson gson = new GsonBuilder().setFieldNamingPolicy(
|
FieldNamingPolicy.UPPER_CAMEL_CASE)
|
.create();
|
final VideoInfo videoInfo = gson
|
.fromJson(jsonObject.getJSONObject("Data")
|
.toString(),
|
new TypeToken<VideoInfo>() {
|
}.getType());
|
if (videoInfo != null) {
|
VideoUtil.saveVideoEpisodeList(getApplicationContext(), videoInfo.getVideoDetailList(), false);
|
}
|
// 附加字段
|
if (jsonObject.optJSONObject("Extra1") != null) {
|
if (jsonObject.optJSONObject("Extra1")
|
.optJSONObject("Attention") != null) {
|
JSONObject obj = jsonObject.optJSONObject(
|
"Extra1")
|
.optJSONObject("Attention");
|
Follow attention = new Follow();
|
attention.setMovieName(obj
|
.optString("Name"));
|
attention.setMoviePicture(obj
|
.optString("Picture"));
|
attention.setUpdateInfo(obj
|
.optString("UpdateInfo"));
|
attention.setAttention(Boolean
|
.parseBoolean(obj
|
.optString("IsAttention")));
|
videoInfo.setAttention(attention);
|
}
|
}
|
VideoDetailActivity.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 (videoInfo.getVideoDetailList() == null
|
|| videoInfo.getVideoDetailList().isEmpty()) {
|
Toast.makeText(VideoDetailActivity.this,
|
"影片已删除", Toast.LENGTH_LONG).show();
|
finish();
|
return;
|
}
|
Glide.with(getApplicationContext())
|
.load(videoInfo.getPlayPicture())
|
.centerCrop().into(target);
|
// videoInfo.setSave(jsonObject.getJSONObject("Data").optBoolean("Save"));
|
if (isSetup) {
|
int position = getIntent().getIntExtra(
|
"playing_position", 0);
|
boolean isFromWatchHistory = getIntent()
|
.getBooleanExtra("isFromWatchHistory",
|
false);// 是否从观看记录点击过来
|
Log.i("mResult", "是否是从观看记录点击进来的:"
|
+ isFromWatchHistory);
|
if (isFromWatchHistory) {
|
mPosition = getIntent().getIntExtra(
|
"playing_position", 0);
|
EventBus.getDefault().post(videoInfo);
|
getUrl(videoInfo.getVideoDetailList().get(
|
mPosition), isSetup);
|
EventBus.getDefault().post(
|
videoInfo.getVideoDetailList().get(
|
mPosition));
|
} else {// 不是从观看记录点击过来 --跳到当前播放的集数
|
// position = VideoPlayUrlUtil
|
// .getVideoDetailPosition(context,
|
// videoInfo);
|
EventBus.getDefault().post(videoInfo);
|
if (StringUtils.isEmpty(detailid)) {
|
getUrl(videoInfo.getVideoDetailList()
|
.get(position), isSetup);
|
EventBus.getDefault().post(
|
videoInfo.getVideoDetailList()
|
.get(position));
|
} else {
|
if (videoInfo.getVideoDetailList() != null)
|
for (int i = 0; i < videoInfo
|
.getVideoDetailList()
|
.size(); i++) {
|
if (detailid
|
.equalsIgnoreCase(videoInfo
|
.getVideoDetailList()
|
.get(i).getId())) {
|
getUrl(videoInfo
|
.getVideoDetailList()
|
.get(i), false);
|
PushEpisode info = new PushEpisode();
|
info.setEpisodeNum(i);
|
EventBus.getDefault()
|
.post(videoInfo
|
.getVideoDetailList()
|
.get(i));
|
}
|
}
|
}
|
}
|
} else {
|
for (int i = 0; i < videoInfo.getResourceList()
|
.size(); i++) {
|
if (videoInfo.getResourceList().get(i)
|
.isChecked()) {
|
resource = videoInfo.getResourceList()
|
.get(i);
|
}
|
}
|
getUrl(videoInfo.getVideoDetailList().get(0),
|
isSetup);
|
findViewById(android.R.id.content).postDelayed(
|
new Runnable() {
|
|
@Override
|
public void run() {
|
EventBus.getDefault().post(
|
videoInfo);
|
EventBus.getDefault()
|
.post(videoInfo
|
.getVideoDetailList()
|
.get(0));
|
}
|
}, 200);
|
}
|
loadFullVideoAd();
|
} 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();
|
}
|
}
|
});
|
}
|
|
private PlayUrl playUrl;
|
|
private void getUrl(VideoDetailInfo info, final boolean isSetup) {
|
SharedPreferences preferences = getSharedPreferences("user",
|
Context.MODE_PRIVATE);
|
String uid = preferences.getString("uid", "");
|
VideoApiUtil.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);
|
info.setPlayType(Integer.parseInt(jsonObject
|
.getJSONObject("Data")
|
.optString("PlayType")));
|
info.setUrl(jsonObject.getJSONObject("Data")
|
.optString("Url"));
|
info.setParams(jsonObject.getJSONObject("Data")
|
.optString("Params"));
|
info.setCode(jsonObject.getJSONObject("Data")
|
.optString("Code"));
|
playUrl = info;
|
if (videoInfo == null) {
|
return;
|
}
|
if (!isSetup) {
|
clickPlay();
|
}
|
}
|
}
|
});
|
}
|
|
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());
|
}
|
|
public static class ChangeVideoEvent {
|
private VideoInfo videoInfo;
|
|
private String tag;
|
|
public VideoInfo getVideoInfo() {
|
return videoInfo;
|
}
|
|
public void setVideoInfo(VideoInfo videoInfo) {
|
this.videoInfo = videoInfo;
|
}
|
|
public String getTag() {
|
return tag;
|
}
|
|
public void setTag(String tag) {
|
this.tag = tag;
|
}
|
|
}
|
|
@Override
|
public void onClick(View v) {
|
int id = v.getId();
|
if (id == R.id.iv_download_failure) {
|
iNet();
|
} else if (id == R.id.iv_back) {
|
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
|
clickBack();
|
} else if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
|
finish();
|
}
|
}
|
}
|
|
/**
|
* video网络数据请求
|
*/
|
private void iNet() {
|
if (videoInfo.getVideoDetailList() == null
|
|| videoInfo.getVideoDetailList().isEmpty()) {
|
getVideoDetail(this, videoInfo.getId(), videoInfo.getThirdType(),
|
true);
|
} else {
|
findViewById(android.R.id.content).postDelayed(new Runnable() {
|
|
@Override
|
public void run() {
|
EventBus.getDefault().post(videoInfo);
|
int p = getIntent().getIntExtra("playing_position",
|
0);
|
p = p >= videoInfo.getVideoDetailList().size() ? videoInfo.getVideoDetailList().size() - 1 : p;
|
EventBus.getDefault().post(
|
videoInfo.getVideoDetailList().get(
|
p));
|
}
|
}, 200);
|
}
|
}
|
|
private void saveWatchHistory(String from) {
|
if (videoInfo != null) {
|
String videoDetailId = "";
|
if (videoInfo.getVideoDetailList() == null
|
|| videoInfo.getVideoDetailList().size() == 0)
|
return;
|
if (mPosition >= videoInfo.getVideoDetailList().size()) {
|
videoDetailId = videoInfo.getVideoDetailList().get(0).getId();
|
} else {
|
videoDetailId = videoInfo.getVideoDetailList().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() {
|
// if (mInit) {
|
// PPTVSdkMgr.getInstance().unit(this);
|
// // PPTVSdkMgr.getInstance().unbindService();
|
// }
|
super.onDestroy();
|
}
|
|
/**
|
* 加载全屏视频广告
|
*/
|
private UnifiedInterstitialAD iad;
|
|
private void loadFullVideoAd() {
|
if (adShown)
|
return;
|
adShown = true;
|
|
if (AdUtil.getAdType(getApplicationContext(), AdPositionEnum.videoDetailFullVideo) != null) {
|
|
if (TTAdSdk.isInitSuccess()) {
|
FullVideoAdManager.getInstance().loadAd(getApplicationContext(), new FullVideoAdManager.IFullVideoAdListener() {
|
@Override
|
public void onSuccess(TTFullScreenVideoAd ad) {
|
FullVideoAdManager.getInstance().showAd(VideoDetailActivity.this);
|
}
|
});
|
} else {
|
iad = new UnifiedInterstitialAD(this, getString(R.string.ad_gdt_pid_video_detail_insert), new UnifiedInterstitialADListener() {
|
|
@Override
|
public void onADReceive() {
|
iad.showAsPopupWindow(VideoDetailActivity.this);
|
}
|
|
@Override
|
public void onVideoCached() {
|
|
}
|
|
@Override
|
public void onNoAD(AdError adError) {
|
|
Log.i("gdt", adError.toString());
|
}
|
|
@Override
|
public void onADOpened() {
|
|
}
|
|
@Override
|
public void onADExposure() {
|
|
}
|
|
@Override
|
public void onADClicked() {
|
|
}
|
|
@Override
|
public void onADLeftApplication() {
|
|
}
|
|
@Override
|
public void onADClosed() {
|
|
}
|
|
@Override
|
public void onRenderSuccess() {
|
|
}
|
|
@Override
|
public void onRenderFail() {
|
|
}
|
});
|
VideoOption.Builder builder = new VideoOption.Builder();
|
VideoOption
|
option = builder.setAutoPlayMuted(true)
|
.setAutoPlayPolicy(VideoOption.AutoPlayPolicy.WIFI).build();
|
iad.setVideoOption(option);
|
iad.loadAD();
|
}
|
}
|
}
|
}
|