Commit 0261dce1 authored by Hanruisong's avatar Hanruisong
Browse files

feat: 更新到v3.15.0

1.添加字幕自适应功能
parent 7219c362
File deleted
*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
.externalNativeBuild
apply plugin: 'com.android.application'
apply plugin: 'io.objectbox'
android {
compileSdkVersion 29
defaultConfig {
applicationId "com.bokecc.vod"
minSdkVersion 17
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
//使用投屏功能时需要添加此配置
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/beans.xml'
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
//noinspection GradleCompatible
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
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.14.0'
//必须引用commonLib
implementation 'com.bokecc:commonLib:0.1.12'
//必须引用
implementation 'com.bokecc:drm:1.2.1'
//使用DWIjkMediaPlayer 倍速播放器引入
implementation 'com.bokecc:hdplayer:1.1.0_lite'
//上传视频时使用压缩功能时需要引用
implementation 'com.bokecc:compressvideo:1.0.0'
//使用Vr播放功能时需要引入
implementation 'com.bokecc:vrplay:1.0.0'
//使用投屏功能需要引用
implementation 'com.bokecc:projection:1.7.0'
//弹幕
implementation 'com.github.ctiao:DanmakuFlameMaster:0.9.25'
//noinspection GradleCompatible
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.github.bumptech.glide:glide:4.9.0'
implementation 'com.squareup.picasso:picasso:2.5.2'
}
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
package com.bokecc.vod;
import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.*;
/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();
assertEquals("com.bokecc.vod", appContext.getPackageName());
}
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.bokecc.vod">
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE" />
<uses-permission android:name="android.permission.VIBRATE"/>
<application
android:name=".HuodeApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.AppCompat.DayNight.NoActionBar"
android:usesCleartextTraffic="true"
android:requestLegacyExternalStorage="true">
<activity
android:name=".MainActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".play.SpeedPlayActivity"
android:configChanges="orientation|keyboardHidden|screenSize|smallestScreenSize|screenLayout"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan|stateHidden|adjustResize"
android:supportsPictureInPicture="true" />
<activity
android:name=".play.MediaPlayActivity"
android:configChanges="orientation|keyboardHidden|screenSize|smallestScreenSize|screenLayout"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan|stateHidden|adjustResize"
android:supportsPictureInPicture="true" />
<activity
android:name=".play.VrPlayActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:screenOrientation="portrait" />
<activity
android:name=".AccountInfoActivity"
android:screenOrientation="portrait" />
<service android:name=".download.DownloadService" />
<activity
android:name=".download.DownloadListActivity"
android:screenOrientation="portrait" />
<activity
android:name=".upload.UploadManageActivity"
android:screenOrientation="portrait" />
<activity
android:name=".upload.EditVideoInfoActivity"
android:screenOrientation="portrait" />
<service android:name=".upload.UploadService" />
<!--使用投屏功能时需要配置ProjectionUpnpService-->
<service
android:name="com.bokecc.projection.ProjectionUpnpService"
android:exported="false" />
<!--使用投屏功能时需要配置ProjectionSystemService-->
<service
android:name="com.bokecc.projection.ProjectionSystemService"
android:exported="false" />
</application>
</manifest>
\ No newline at end of file
package com.bokecc.vod;
import android.app.Activity;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import com.bokecc.vod.utils.MultiUtils;
public class AccountInfoActivity extends AppCompatActivity {
private Activity activity;
private TextView tv_user_id, tv_api_key;
private EditText et_verification_code;
private ImageView iv_back;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_account_info);
MultiUtils.setStatusBarColor(this, R.color.transparent, true);
activity = this;
initView();
}
private void initView() {
tv_user_id = findViewById(R.id.tv_user_id);
tv_api_key = findViewById(R.id.tv_api_key);
et_verification_code = findViewById(R.id.et_verification_code);
iv_back = findViewById(R.id.iv_back);
if (!TextUtils.isEmpty(MultiUtils.getVerificationCode())) {
et_verification_code.setText(MultiUtils.getVerificationCode());
}
tv_user_id.setText(ConfigUtil.USERID);
tv_api_key.setText(ConfigUtil.API_KEY);
iv_back.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
}
@Override
protected void onDestroy() {
super.onDestroy();
String code = et_verification_code.getText().toString().trim();
MultiUtils.setVerificationCode(code);
}
}
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";
// 配置下载文件路径
public final static String DOWNLOAD_PATH = "HuodeDownload";
//下载重试次数
public final static int DOWNLOAD_RECONNECT_LIMIT = 60;
// 配置同时下载个数
public final static int DOWNLOADING_MAX = 2;
// 配置同时上传个数
public final static int UPLOADING_MAX = 2;
public final static int DOWNLOAD_FRAGMENT_MAX_TAB_SIZE = 2;
public final static String ACTION_UPLOAD = "video.upload";
// 配置视频回调地址
public final static String NOTIFY_URL = "http://www.example.com";
}
package com.bokecc.vod;
import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;
import android.util.Log;
import android.widget.Toast;
import com.bokecc.sdk.mobile.download.VodDownloadManager;
import com.bokecc.sdk.mobile.drm.DRMServer;
import com.bokecc.sdk.mobile.util.DWSdkStorage;
import com.bokecc.sdk.mobile.util.DWStorageUtil;
import com.bokecc.sdk.mobile.util.HttpUtil;
import com.bokecc.vod.data.ObjectBox;
import com.bokecc.vod.utils.MultiUtils;
public class HuodeApplication extends Application {
private static DRMServer drmServer;
public static Context context;
private static int drmServerPort;
public static SharedPreferences sp;
@Override
public void onCreate() {
super.onCreate();
context = this;
sp = getSharedPreferences("AccountSettings", Context.MODE_PRIVATE);
//初始化本地数据库
ObjectBox.init(this);
initDWStorage();
startDRMServer();
//初始化VodDownloadManager
String downloadPath = MultiUtils.createDownloadPath();
//使用VodDownloadManager需要以单例VodDownloadManager.getInstance()的形式调用
VodDownloadManager.getInstance().init(HuodeApplication.getContext(), ConfigUtil.USERID, ConfigUtil.API_KEY, downloadPath);
}
public static Context getContext() {
return context;
}
public static SharedPreferences getSp(){
return sp;
}
// 启动DRMServer
public void startDRMServer() {
if (drmServer == null) {
drmServer = new DRMServer();
drmServer.setRequestRetryCount(20);
}
try {
drmServer.start();
setDrmServerPort(drmServer.getPort());
} catch (Exception e) {
Toast.makeText(getApplicationContext(), "启动解密服务失败,请检查网络限制情况:"+e.getMessage(), Toast.LENGTH_LONG).show();
}
}
private void initDWStorage() {
DWSdkStorage myDWSdkStorage = new DWSdkStorage() {
private SharedPreferences sp = getApplicationContext().getSharedPreferences("mystorage", MODE_PRIVATE);
@Override
public void put(String key, String value) {
SharedPreferences.Editor editor = sp.edit();
editor.putString(key, value);
editor.commit();
}
@Override
public String get(String key) {
return sp.getString(key, "");
}
};
DWStorageUtil.setDWSdkStorage(myDWSdkStorage);
}
@Override
public void onTerminate() {
if (drmServer != null) {
drmServer.stop();
}
super.onTerminate();
}
public static int getDrmServerPort() {
return drmServerPort;
}
public void setDrmServerPort(int drmServerPort) {
this.drmServerPort = drmServerPort;
}
public static DRMServer getDRMServer() {
return drmServer;
}
}
package com.bokecc.vod;
import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import com.bokecc.sdk.mobile.download.DownloadOperator;
import com.bokecc.sdk.mobile.download.VodDownloadBean;
import com.bokecc.sdk.mobile.download.VodDownloadManager;
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.DownloadListActivity;
import com.bokecc.vod.download.DownloadService;
import com.bokecc.vod.inter.SelectPlayer;
import com.bokecc.vod.play.MediaPlayActivity;
import com.bokecc.vod.play.SpeedPlayActivity;
import com.bokecc.vod.play.VrPlayActivity;
import com.bokecc.vod.upload.UploadController;
import com.bokecc.vod.upload.UploadManageActivity;
import com.bokecc.vod.upload.UploadService;
import com.bokecc.vod.utils.MultiUtils;
import com.bokecc.vod.view.HeadGridView;
import com.bokecc.vod.view.SelectPlayerDialog;
import org.json.JSONArray;
import org.json.JSONObject;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
public class MainActivity extends AppCompatActivity {
private HeadGridView gv_video_list;
private PlayVideoAdapter playVideoAdapter;
private ImageView iv_account_info, iv_upload, iv_download, iv_main_img;
private View headView;
private LinearLayout ll_retry;
private String verificationCode;
private Button btn_retry;
private static String[] PERMISSIONS_STORAGE = {
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE};
private ArrayList<HuodeVideoInfo> videoDatas;
/**
* @param savedInstanceState
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
MultiUtils.setStatusBarColor(this, R.color.transparent, true);
initView();
//初始化数据库和下载数据 没有开通授权播放和下载功能的账号 verificationCode可为空值
verificationCode = MultiUtils.getVerificationCode();
//初始化上传数据库
UploadController.init();
//申请存储权限
if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, PERMISSIONS_STORAGE, 1);
}else {
MultiUtils.createDownloadPath();
}
//启动下载service
Intent intent = new Intent(this, DownloadService.class);
startService(intent);
//启动上传service
Intent uploadIntent = new Intent(this, UploadService.class);
startService(uploadIntent);
//请求数据
initData();
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == 1 && grantResults.length == 2 && grantResults[0] == PackageManager.PERMISSION_GRANTED && grantResults[1] == PackageManager.PERMISSION_GRANTED) {
MultiUtils.createDownloadPath();
}
}
private void initView() {
gv_video_list = findViewById(R.id.gv_video_list);
iv_account_info = findViewById(R.id.iv_account_info);
iv_upload = findViewById(R.id.iv_upload);
iv_download = findViewById(R.id.iv_download);
ll_retry = findViewById(R.id.ll_retry);
btn_retry = findViewById(R.id.btn_retry);
headView = LayoutInflater.from(MainActivity.this).inflate(R.layout.headview_main, null);
iv_main_img = headView.findViewById(R.id.iv_main_img);
gv_video_list.addHeaderView(headView);
videoDatas = new ArrayList<>();
//配置自己的视频时取消这行注释
// videoDatas = DataUtil.getVideoList();
playVideoAdapter = new PlayVideoAdapter(MainActivity.this, videoDatas);
gv_video_list.setAdapter(playVideoAdapter);
iv_main_img.setImageResource(R.mipmap.iv_default_img);
gv_video_list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
final HuodeVideoInfo item = (HuodeVideoInfo) playVideoAdapter.getItem(position);
selectPlayer(item);
}
});
iv_main_img.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (videoDatas != null && videoDatas.size() > 0) {
HuodeVideoInfo huodeVideoInfo = videoDatas.get(0);
selectPlayer(huodeVideoInfo);
}
}
});
iv_account_info.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(MainActivity.this, AccountInfoActivity.class));
}
});
iv_download.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(MainActivity.this, DownloadListActivity.class));
}
});
iv_upload.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(MainActivity.this, UploadManageActivity.class));
}
});
btn_retry.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ll_retry.setVisibility(View.GONE);
initData();
}
});
}
private void selectPlayer(final HuodeVideoInfo item) {
String videoId = item.getVideoId();
if (TextUtils.isEmpty(videoId)) {
return;
}
SelectPlayerDialog selectPlayerDialog = new SelectPlayerDialog(MainActivity.this, new SelectPlayer() {
@Override
public void selectDWIjkMediaPlayer() {
closeSmallWindow();
Intent playIntent = new Intent(MainActivity.this, SpeedPlayActivity.class);
playIntent.putExtra("videoId", item.getVideoId());
playIntent.putExtra("videoTitle", item.getVideoTitle());