Commit 6be77d8f authored by Hanruisong's avatar Hanruisong
Browse files

更新到 v3.9.0

1.新增片尾广告功能。
parent cd2cc2a9
No preview for this file type
No preview for this file type
......@@ -33,9 +33,9 @@ dependencies {
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
//获得场景视频SDK,必须引入
implementation 'com.bokecc:vod:3.8.0'
implementation 'com.bokecc:vod:3.9.0'
//必须引用commonLib
implementation 'com.bokecc:commonLib:0.1.9'
implementation 'com.bokecc:commonLib:0.1.12'
//必须引用
implementation 'com.bokecc:drm:1.2.1'
//使用DWIjkMediaPlayer 倍速播放器引入
......
......@@ -32,15 +32,16 @@
<activity
android:name=".play.SpeedPlayActivity"
android:configChanges="orientation|keyboardHidden|screenSize|screenLayout"
android:configChanges="orientation|keyboardHidden|screenSize|smallestScreenSize|screenLayout"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan|stateHidden"
android:windowSoftInputMode="adjustPan|stateHidden|adjustResize"
android:supportsPictureInPicture="true" />
<activity
android:name=".play.MediaPlayActivity"
android:configChanges="orientation|keyboardHidden|screenSize|screenLayout"
android:configChanges="orientation|keyboardHidden|screenSize|smallestScreenSize|screenLayout"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan|stateHidden"
android:windowSoftInputMode="adjustPan|stateHidden|adjustResize"
android:supportsPictureInPicture="true" />
<activity
......
......@@ -3,8 +3,10 @@ package com.bokecc.vod;
public class ConfigUtil {
//账号ID 可以替换为自己的USERID
public static final String USERID = "391E6E3340A00767";
//可以替换为自己的API_KEY
public static final String API_KEY = "T8WdOUuvFEiOsou1xjDr4U73v12M7iNa";
//获取视频信息的地址
public final static String DATA_URL = "https://p.bokecc.com/demo/videoinfo.json";
// 配置下载文件路径
......
......@@ -16,9 +16,14 @@ import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import com.bokecc.sdk.mobile.download.DownloadInfo;
import com.bokecc.sdk.mobile.download.DownloadModel;
import com.bokecc.sdk.mobile.download.DownloaderHelper;
import com.bokecc.sdk.mobile.download.OnDownloadInfoListener;
import com.bokecc.sdk.mobile.util.HttpUtil;
import com.bokecc.vod.adapter.PlayVideoAdapter;
import com.bokecc.vod.data.DataSet;
import com.bokecc.vod.data.DataUtil;
import com.bokecc.vod.data.HuodeVideoInfo;
import com.bokecc.vod.download.DownloadController;
import com.bokecc.vod.download.DownloadListActivity;
......@@ -44,6 +49,7 @@ import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
public class MainActivity extends AppCompatActivity {
private HeadGridView gv_video_list;
......
package com.bokecc.vod.view;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.graphics.SurfaceTexture;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Surface;
import android.view.TextureView;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import com.bokecc.sdk.mobile.util.HttpUtil;
import com.bokecc.vod.R;
import com.bokecc.vod.utils.MultiUtils;
import java.io.IOException;
public class PauseVideoAdDialog extends Dialog implements TextureView.SurfaceTextureListener, MediaPlayer.OnPreparedListener {
private Context context;
private boolean isFullScreen;
private String material;
private String clickUrl;
private TextureView tv_video;
private MediaPlayer player;
private Surface playSurface;
private int videoHeight, videoWidth, adVideoHeight, adVideoWidth;
private boolean isVideoAdSoundOn = false, isPrepared = false;
public PauseVideoAdDialog(Context context, boolean isFullScreen, String material, String clickUrl) {
super(context, R.style.ExerciseGuideDialog);
this.context = context;
this.isFullScreen = isFullScreen;
this.material = material;
this.clickUrl = clickUrl;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
init();
}
private void init() {
LayoutInflater inflater = LayoutInflater.from(context);
View view = inflater.inflate(R.layout.dialog_pause_video_ad, null);
setContentView(view);
tv_video = view.findViewById(R.id.tv_video);
player = new MediaPlayer();
player.setOnPreparedListener(this);
player.setLooping(true);
player.setVolume(0.0f, 0.0f);
tv_video.setSurfaceTextureListener(this);
try {
player.setDataSource(material);
player.prepareAsync();
} catch (IOException e) {
e.printStackTrace();
}
final ImageView iv_video_ad_sound = view.findViewById(R.id.iv_video_ad_sound);
iv_video_ad_sound.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (isVideoAdSoundOn) {
player.setVolume(0.0f, 0.0f);
iv_video_ad_sound.setImageResource(R.mipmap.iv_video_ad_sound_off);
isVideoAdSoundOn = false;
} else {
player.setVolume(1.0f, 1.0f);
iv_video_ad_sound.setImageResource(R.mipmap.iv_video_ad_sound_on);
isVideoAdSoundOn = true;
}
}
});
ImageView iv_close_pause_video_ad = view.findViewById(R.id.iv_close_pause_video_ad);
iv_close_pause_video_ad.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
dismiss();
}
});
tv_video.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (!TextUtils.isEmpty(clickUrl)) {
Intent intent = new Intent();
intent.setAction("android.intent.action.VIEW");
Uri uri = Uri.parse(clickUrl);
intent.setData(uri);
context.startActivity(intent);
}
}
});
Window dialogWindow = getWindow();
WindowManager.LayoutParams lp = dialogWindow.getAttributes();
DisplayMetrics d = context.getResources().getDisplayMetrics();
lp.width = (int) (d.widthPixels * 0.01);
lp.height = (int) (d.heightPixels * 0.01);
lp.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
dialogWindow.setDimAmount(0f);
dialogWindow.setAttributes(lp);
if (isFullScreen) {
dialogWindow.setGravity(Gravity.CENTER);
} else {
dialogWindow.setGravity(Gravity.TOP);
}
setCanceledOnTouchOutside(false);
}
@Override
public void onDetachedFromWindow() {
super.onDetachedFromWindow();
if (player != null) {
player.pause();
player.stop();
player.release();
isPrepared = false;
}
}
@Override
public void onSurfaceTextureAvailable(SurfaceTexture surfaceTexture, int i, int i1) {
playSurface = new Surface(surfaceTexture);
player.setSurface(playSurface);
}
@Override
public void onSurfaceTextureSizeChanged(SurfaceTexture surfaceTexture, int i, int i1) {
}
@Override
public boolean onSurfaceTextureDestroyed(SurfaceTexture surfaceTexture) {
return false;
}
@Override
public void onSurfaceTextureUpdated(SurfaceTexture surfaceTexture) {
}
@Override
public void onPrepared(MediaPlayer mediaPlayer) {
isPrepared = true;
player.start();
videoWidth = player.getVideoWidth();
videoHeight = player.getVideoHeight();
updateView(isFullScreen);
}
public void updateView(boolean isFullScreen) {
if (videoHeight > 0 && videoWidth > 0) {
if (!isFullScreen) {
adVideoHeight = MultiUtils.dipToPx(context, 112);
adVideoWidth = adVideoHeight * videoWidth / videoHeight;
int maxPortVideoAdWidth = MultiUtils.dipToPx(context, 200);
if (adVideoWidth > maxPortVideoAdWidth) {
adVideoWidth = maxPortVideoAdWidth;
adVideoHeight = adVideoWidth * videoHeight / videoWidth;
}
} else {
adVideoHeight = MultiUtils.dipToPx(context, 225);
adVideoWidth = adVideoHeight * videoWidth / videoHeight;
int maxLandScapeVideoAdWidth = MultiUtils.dipToPx(context, 400);
if (adVideoWidth > maxLandScapeVideoAdWidth) {
adVideoWidth = maxLandScapeVideoAdWidth;
adVideoHeight = adVideoWidth * videoHeight / videoWidth;
}
}
ViewGroup.LayoutParams videoParams = tv_video.getLayoutParams();
videoParams.width = adVideoWidth;
videoParams.height = adVideoHeight;
tv_video.setLayoutParams(videoParams);
Window dialogWindow = getWindow();
WindowManager.LayoutParams lp = dialogWindow.getAttributes();
lp.width = adVideoWidth;
lp.height = adVideoHeight;
if (!isFullScreen) {
int offset = (MultiUtils.dipToPx(context, 200) - adVideoHeight) / 2;
lp.y = offset;
dialogWindow.setGravity(Gravity.TOP);
} else {
lp.y = 0;
dialogWindow.setGravity(Gravity.CENTER);
}
dialogWindow.setAttributes(lp);
}
}
public void pauseVideoAd() {
if (isPrepared) {
player.pause();
}
}
public void resumeVideoAd() {
if (isPrepared) {
player.start();
}
}
}
......@@ -2,6 +2,7 @@ package com.bokecc.vod.view;
import android.app.Dialog;
import android.content.Context;
import android.os.Build;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.Gravity;
......@@ -27,7 +28,7 @@ public class SelectVideoDialog extends Dialog {
private SelectVideo selectVideo;
private ArrayList<HuodeVideoInfo> videoList;
public SelectVideoDialog(Context context,ArrayList<HuodeVideoInfo> videoList,String currentVideoId,SelectVideo selectVideo) {
public SelectVideoDialog(Context context, ArrayList<HuodeVideoInfo> videoList, String currentVideoId, SelectVideo selectVideo) {
super(context, R.style.SetVideoDialog);
this.context = context;
this.currentVideoId = currentVideoId;
......@@ -48,16 +49,16 @@ public class SelectVideoDialog extends Dialog {
ListView lv_select_video = view.findViewById(R.id.lv_select_video);
List<HuodeVideoInfo> datas = new ArrayList<>();
for (int i=0;i<videoList.size();i++){
for (int i = 0; i < videoList.size(); i++) {
boolean isSelected = false;
HuodeVideoInfo videoInfo = videoList.get(i);
if (videoInfo!=null){
if (videoInfo.getVideoId().equals(currentVideoId)){
if (videoInfo != null) {
if (videoInfo.getVideoId().equals(currentVideoId)) {
isSelected = true;
}else {
} else {
isSelected = false;
}
datas.add(new HuodeVideoInfo(videoInfo.getVideoCover(),videoInfo.getVideoTitle(),videoInfo.getVideoId(),isSelected));
datas.add(new HuodeVideoInfo(videoInfo.getVideoCover(), videoInfo.getVideoTitle(), videoInfo.getVideoId(), isSelected));
}
}
......@@ -68,8 +69,8 @@ public class SelectVideoDialog extends Dialog {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
HuodeVideoInfo item = (HuodeVideoInfo) selectVideoAdapter.getItem(position);
if (selectVideo!=null && item!=null){
selectVideo.selectedVideo(item.getVideoTitle(),item.getVideoId(),item.getVideoCover());
if (selectVideo != null && item != null) {
selectVideo.selectedVideo(item.getVideoTitle(), item.getVideoId(), item.getVideoCover());
dismiss();
}
}
......@@ -82,6 +83,11 @@ public class SelectVideoDialog extends Dialog {
lp.height = (int) (d.heightPixels * 1.0);
dialogWindow.setAttributes(lp);
dialogWindow.setGravity(Gravity.RIGHT);
if (Build.VERSION.SDK_INT > 18) {
dialogWindow.setFlags(
WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
}
}
......@@ -297,97 +297,128 @@
</RelativeLayout>
<LinearLayout
android:id="@+id/ll_ad"
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="10dp"
android:visibility="gone">
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/ll_image_ad"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal">
android:layout_height="match_parent"
android:background="@color/black"
android:gravity="center"
android:orientation="vertical"
android:visibility="gone">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<ImageView
android:id="@+id/iv_image_ad"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
<TextView
android:id="@+id/tv_ad_countdown"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/ad_bac"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:text="广告剩余"
android:textColor="@color/white"
android:textSize="15sp" />
<LinearLayout
android:id="@+id/ll_ad"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="10dp"
android:visibility="gone">
<TextView
android:id="@+id/tv_skip_ad"
android:layout_width="wrap_content"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:background="@drawable/ad_bac"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:text="跳过广告"
android:textColor="@color/white"
android:textSize="15sp" />
android:gravity="center_vertical"
android:orientation="horizontal">
</LinearLayout>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<TextView
android:id="@+id/tv_ad_countdown"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/ad_bac"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:text="广告剩余"
android:textColor="@color/white"
android:textSize="15sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:id="@+id/tv_skip_ad"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:background="@drawable/ad_bac"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:text="跳过广告"
android:textColor="@color/white"
android:textSize="15sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/ad_bac"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:text="广告"
android:textColor="@color/white"
android:textSize="15sp" />
</LinearLayout>
<TextView
android:id="@+id/tv_know_more"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:background="@drawable/ad_bac"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:text="了解详情"
android:textColor="@color/white"
android:textSize="15sp" />
android:orientation="horizontal"
android:layout_marginBottom="20dp">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<TextView
android:layout_width="0dp"
<TextView
android:id="@+id/tv_know_more"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/ad_bac"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:text="了解详情"
android:textColor="@color/white"
android:textSize="15sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" />
android:gravity="center_vertical"
android:orientation="horizontal">
<ImageView
android:id="@+id/iv_ad_full_screen"
android:layout_width="30dp"
android:layout_height="30dp"
android:src="@mipmap/iv_full_screen" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/ad_bac"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:text="广告"
android:textColor="@color/white"
android:textSize="15sp" />
</LinearLayout>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
<ImageView
android:id="@+id/iv_ad_full_screen"
android:layout_width="30dp"
android:layout_height="30dp"
android:src="@mipmap/iv_full_screen" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:id="@+id/rl_pause_ad"
......@@ -401,17 +432,33 @@
android:layout_width="match_parent"
android:layout_height="match_parent" />
<TextView
android:id="@+id/tv_close_pause_ad"
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:background="@color/white"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text="关闭"
android:textColor="@android:color/black"
android:textSize="18sp" />