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.Bitmap;
|
import android.os.Build;
|
import android.os.Bundle;
|
import android.support.v4.app.Fragment;
|
import android.support.v4.app.FragmentManager;
|
import android.support.v4.app.FragmentTransaction;
|
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.RelativeLayout;
|
import android.widget.SeekBar;
|
import android.widget.TextView;
|
import android.widget.Toast;
|
|
import com.bumptech.glide.Glide;
|
import com.bumptech.glide.request.animation.GlideAnimation;
|
import com.bumptech.glide.request.target.SimpleTarget;
|
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.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.qq.e.ads.banner.ADSize;
|
import com.qq.e.ads.banner.BannerView;
|
import com.umeng.analytics.MobclickAgent;
|
import com.weikou.beibeivideo.BasicTextHttpResponseHandler;
|
import com.weikou.beibeivideo.BeibeiVideoAPI;
|
import com.weikou.beibeivideo.db.WatchHistoryTable;
|
import com.weikou.beibeivideo.entity.AccumulateRule;
|
import com.weikou.beibeivideo.entity.AdType;
|
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.service.DownLoadFileService;
|
import com.weikou.beibeivideo.ui.BaseActivity;
|
import com.weikou.beibeivideo.ui.common.ShareActivity;
|
import com.weikou.beibeivideo.ui.mine.BrowserActivity;
|
import com.weikou.beibeivideo.ui.mine.FXBrowserActivity;
|
import com.weikou.beibeivideo.util.BeibeiConstant;
|
import com.weikou.beibeivideo.util.ad.FullVideoAdManager;
|
import com.yeshi.buwanshequ.R;
|
|
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 de.greenrobot.event.EventBus;
|
|
|
/**
|
* 视频详情
|
*
|
* @author Administrator
|
*/
|
//
|
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 boolean isClick = false;
|
|
private FragmentManager fm = getSupportFragmentManager();
|
|
@Override
|
protected void onSaveInstanceState(Bundle outState) {
|
outState.putString("flash exit", "VideoDetailActivity");
|
super.onSaveInstanceState(outState);
|
}
|
|
@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);
|
/*
|
* 计算状态栏高度并设置
|
*/
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
int result = 0;
|
int resourceId = getResources().getIdentifier("status_bar_height",
|
"dimen", "android");
|
if (resourceId > 0) {
|
result = getResources().getDimensionPixelSize(resourceId);
|
}
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
|
result);
|
findViewById(R.id.v_status_bar).setLayoutParams(params);
|
} else {
|
findViewById(R.id.v_status_bar).setVisibility(View.GONE);
|
}
|
|
seekBar_down_so = (SeekBar) findViewById(R.id.seekbar_load_so);
|
tv_progress = (TextView) findViewById(R.id.tv_progrerss);
|
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");
|
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)
|
// MobclickAgent.reportError(this,
|
// "VideoDetailActivity:传入的VideoInfo为空");
|
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(VideoDetailActivity.this, "该影片需要分享之后才能观看",
|
Toast.LENGTH_LONG).show();
|
startActivity(getIntent().setClass(VideoDetailActivity.this,
|
ShareActivity.class));
|
finish();
|
return;
|
}
|
}
|
android.widget.RelativeLayout.LayoutParams params = new android.widget.RelativeLayout.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);
|
RelativeLayout.LayoutParams params1 = new RelativeLayout.LayoutParams(com.weikou.beibeivideo.util.DimenUtils.dip2px(this, 80), com.weikou.beibeivideo.util.DimenUtils.dip2px(this, 60));
|
params1.topMargin = (int) (SystemCommon.getScreenWidth(this) * 9 / 16f - com.weikou.beibeivideo.util.DimenUtils.dip2px(this, 60) / 2f);
|
params1.leftMargin = (int) (SystemCommon.getScreenWidth(this) - com.weikou.beibeivideo.util.DimenUtils.dip2px(this, 80) * 1.25f);
|
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;
|
}
|
isClick = true;
|
clickPlay();
|
}
|
});
|
iv_background.setOnClickListener(new OnClickListener() {
|
@Override
|
public void onClick(View v) {
|
if (videoInfo == null) {
|
return;
|
}
|
isClick = true;
|
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 void loadFullVideoAd() {
|
//加载广告
|
if (BeibeiConstant.AD_TYPE.isVideoDetailSplashAd()) {
|
if (FullVideoAdManager.getInstance().isCacahed()) {
|
FullVideoAdManager.getInstance().showAd(this);
|
}
|
}
|
}
|
|
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 void initBanner() {
|
BannerView banner = new BannerView(VideoDetailActivity.this, ADSize.BANNER, BeibeiConstant.GDT_ID, BeibeiConstant.GDT_PLAYER_DETAIL);
|
banner.setRefresh(30);
|
banner.setShowClose(true);
|
fl_banner.addView(banner);
|
banner.loadAD();
|
}
|
|
private boolean isFirst = true;
|
|
public void onEventMainThread(AdType info) {
|
if (isFirst) {
|
findViewById(R.id.ll_download_so).setVisibility(View.VISIBLE);
|
if (info.getProgress() == 100)
|
isFirst = false;
|
seekBar_down_so.setProgress(info.getProgress() / 2);
|
} else {
|
seekBar_down_so.setProgress(50 + (info.getProgress() / 2));
|
if (info.getProgress() == 100) {
|
findViewById(R.id.ll_download_so).setVisibility(View.GONE);
|
fl_video_play_background.setClickable(true);
|
iv_select_play.setClickable(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();
|
// }
|
if (playUrl.getPlayType() != 1) {//测试
|
setViewOrientation();
|
}
|
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 != 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,
|
BrowserActivity.class);
|
intent.putExtra("url", playUrl.getUrl());
|
startActivity(intent);
|
} 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(VideoDetailActivity.this, "影片加载中...",
|
Toast.LENGTH_LONG).show();
|
}
|
saveWatchHistory("爱奇艺");
|
}
|
} 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,
|
FXBrowserActivity.class);
|
intent.putExtra("url", playUrl.getUrl());
|
startActivity(intent);
|
saveWatchHistory("风行");
|
}
|
} 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,
|
BrowserActivity.class);
|
intent.putExtra("url", playUrl.getUrl());
|
startActivity(intent);
|
saveWatchHistory(playUrl.getResource().getName());
|
}
|
}
|
}
|
|
private boolean mInit = false;
|
|
private void downLoadSo(String downloadurl) {
|
try {
|
Intent intent = new Intent(this,
|
DownLoadFileService.class);
|
stopService(intent);
|
} catch (Exception e) {
|
}
|
try {
|
Bundle bundle = new Bundle();
|
bundle.putString("downloadurl", downloadurl);
|
Intent intent = new Intent(this,
|
DownLoadFileService.class);
|
intent.putExtras(bundle);
|
|
startService(intent);
|
} catch (Exception e) {
|
}
|
}
|
|
|
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);
|
findViewById(R.id.v_status_bar).setVisibility(View.GONE);
|
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
|
android.widget.RelativeLayout.LayoutParams params = new android.widget.RelativeLayout.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<Bitmap> target = new SimpleTarget<Bitmap>() {
|
|
@Override
|
public void onResourceReady(Bitmap arg0,
|
GlideAnimation<? super Bitmap> arg1) {
|
((ImageView) findViewById(R.id.iv_video_play_background))
|
.setImageBitmap(arg0);
|
}
|
};
|
|
@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();
|
}
|
|
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();
|
}
|
findViewById(R.id.v_status_bar).setVisibility(View.VISIBLE);
|
android.widget.RelativeLayout.LayoutParams params = new android.widget.RelativeLayout.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) {
|
// 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.view.ViewGroup.LayoutParams layoutParams = findViewById(
|
R.id.fragment_video_play_container).getLayoutParams();
|
layoutParams.height = android.view.ViewGroup.LayoutParams.MATCH_PARENT;
|
findViewById(R.id.fragment_video_play_container).requestLayout();
|
} else {
|
// 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 = (FrameLayout) findViewById(R.id.fragment_video_play_container);
|
if (layout == null)
|
return;
|
android.view.ViewGroup.LayoutParams layoutParams = layout
|
.getLayoutParams();
|
layoutParams.height = (int) (DimenUtils.getScreenWidth(this) * 0.5625f);
|
layout.requestLayout();
|
}
|
}
|
|
@Override
|
public void onResume() {
|
super.onResume();
|
EventBus.getDefault().register(this);
|
MobclickAgent.onResume(this);
|
}
|
|
@Override
|
public void onPause() {
|
super.onPause();
|
EventBus.getDefault().unregister(this);
|
MobclickAgent.onPause(this);
|
}
|
|
public void onEventMainThread(ChangeVideoEvent changeVideoEvent) {
|
VideoInfo videoInfo = changeVideoEvent.getVideoInfo();
|
resourceId = "";
|
if (!progressDialog.isShowing()) {
|
progressDialog.show();
|
}
|
getVideoDetail(this, videoInfo.getId(), videoInfo.getThirdType(), false);
|
}
|
|
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;
|
}
|
|
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", "");
|
BeibeiVideoAPI.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 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();
|
}
|
|
Gson gson = new GsonBuilder().setFieldNamingPolicy(
|
FieldNamingPolicy.UPPER_CAMEL_CASE)
|
.create();
|
final VideoInfo videoInfo = gson
|
.fromJson(jsonObject.getJSONObject("Data")
|
.toString(),
|
new TypeToken<VideoInfo>() {
|
}.getType());
|
// 附加字段
|
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())
|
.asBitmap().centerCrop().into(target);
|
tv_back.setText(videoInfo.getName() + "");
|
// 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);
|
}
|
|
} 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();
|
}
|
|
//加载视频广告
|
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);
|
info.setPlayType(Integer.parseInt(jsonObject
|
.getJSONObject("Data")
|
.optString("PlayType")));
|
info.setUrl(jsonObject.getJSONObject("Data")
|
.optString("Url"));
|
info.setParams(jsonObject.getJSONObject("Data")
|
.optString("Params"));
|
playUrl = info;
|
if (videoInfo == null) {
|
return;
|
}
|
if (!isSetup || isClick) {
|
clickPlay();
|
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());
|
}
|
|
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) {
|
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 (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);
|
EventBus.getDefault().post(
|
videoInfo.getVideoDetailList().get(
|
getIntent().getIntExtra("playing_position",
|
0)));
|
}
|
}, 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() {
|
super.onDestroy();
|
if (BeibeiConstant.AD_TYPE.isVideoDetailSplashAd())
|
FullVideoAdManager.getInstance().loadAd(getApplicationContext(), null);
|
}
|
}
|