Commit a80afec2 authored by Hanruisong's avatar Hanruisong
Browse files

feat: 更新到v3.11.0

1.新增离线字幕功能。
parent ea1cb49a
No preview for this file type
......@@ -33,7 +33,7 @@ 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.10.0'
implementation 'com.bokecc:vod:3.11.0'
//必须引用commonLib
implementation 'com.bokecc:commonLib:0.1.12'
//必须引用
......
......@@ -51,6 +51,7 @@ public class DownloadedViewAdapter extends BaseAdapter{
holder.tv_filesize = convertView.findViewById(R.id.tv_filesize);
holder.titleView = convertView.findViewById(R.id.downloaded_title);
holder.iv_video_cover = convertView.findViewById(R.id.iv_video_cover);
holder.tv_subtitle_state = convertView.findViewById(R.id.tv_subtitle_state);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
......@@ -65,12 +66,20 @@ public class DownloadedViewAdapter extends BaseAdapter{
holder.tv_filesize.setVisibility(View.INVISIBLE);
}
MultiUtils.showVideoCover(holder.iv_video_cover,wrapper.getDownloadInfo().getVideoCover());
int firstSubtitleStatus = wrapper.getDownloadInfo().getFirstSubtitleStatus();
if (firstSubtitleStatus==2){
holder.tv_subtitle_state.setVisibility(View.VISIBLE);
holder.tv_subtitle_state.setText("下载字幕失败");
}else {
holder.tv_subtitle_state.setVisibility(View.INVISIBLE);
}
return convertView;
}
public class ViewHolder {
public TextView titleView;
public TextView tv_filesize;
public TextView tv_subtitle_state;
public ImageView iv_video_cover;
}
}
......@@ -31,6 +31,13 @@ public class DownloadInfo {
private int definition;
private int firstSubtitleStatus;
private int secondSubtitleStatus;
private int subtitleNum;
public DownloadInfo() {
}
......@@ -138,4 +145,28 @@ public class DownloadInfo {
public void setVideoCover(String videoCover) {
this.videoCover = videoCover;
}
public int getFirstSubtitleStatus() {
return firstSubtitleStatus;
}
public void setFirstSubtitleStatus(int firstSubtitleStatus) {
this.firstSubtitleStatus = firstSubtitleStatus;
}
public int getSecondSubtitleStatus() {
return secondSubtitleStatus;
}
public void setSecondSubtitleStatus(int secondSubtitleStatus) {
this.secondSubtitleStatus = secondSubtitleStatus;
}
public int getSubtitleNum() {
return subtitleNum;
}
public void setSubtitleNum(int subtitleNum) {
this.subtitleNum = subtitleNum;
}
}
......@@ -6,8 +6,10 @@ import android.util.Log;
import com.bokecc.sdk.mobile.download.DownloadListener;
import com.bokecc.sdk.mobile.download.Downloader;
import com.bokecc.sdk.mobile.download.OnDownloadSubtitleListener;
import com.bokecc.sdk.mobile.exception.HuodeException;
import com.bokecc.sdk.mobile.play.MediaMode;
import com.bokecc.sdk.mobile.util.HttpUtil;
import com.bokecc.vod.ConfigUtil;
import com.bokecc.vod.data.DataSet;
import com.bokecc.vod.data.DownloadInfo;
......@@ -29,20 +31,22 @@ public class DownloadWrapper {
lastStart = downloadInfo.getStart();
String downloadPath = MultiUtils.createDownloadPath();
downloader = new Downloader(downloadPath,downloadInfo.getTitle(),downloadInfo.getVideoId(), ConfigUtil.USERID, ConfigUtil.API_KEY,verificationCode);
downloader = new Downloader(downloadPath, downloadInfo.getTitle(), downloadInfo.getVideoId(), ConfigUtil.USERID, ConfigUtil.API_KEY, verificationCode);
//设置下载重连次数 取值范围(0--100),Demo设置的是重试60次
downloader.setReconnectLimit(ConfigUtil.DOWNLOAD_RECONNECT_LIMIT);
//设置下载重连间隔,单位ms,demo设置是3000ms
downloader.setDownloadRetryPeriod(3 * 1000);
downloader.setDownloadDefinition(downloadInfo.getDefinition());
//设置下载字幕,视频有字幕资源文件时才会下载
downloader.setDownloadSubtitle(downloadPath, downloadInfo.getTitle());
//下载模式
int downloadMode = downloadInfo.getDownloadMode();
if (downloadMode==0){
if (downloadMode == 0) {
downloader.setDownloadMode(MediaMode.VIDEOAUDIO);
}else if (downloadMode==1){
} else if (downloadMode == 1) {
downloader.setDownloadMode(MediaMode.VIDEO);
}else if (downloadMode==2){
} else if (downloadMode == 2) {
downloader.setDownloadMode(MediaMode.AUDIO);
}
......@@ -60,15 +64,16 @@ public class DownloadWrapper {
@Override
public void handleStatus(String videoId, int status) {
if (status == downloadInfo.getStatus()) {
return;
return;
} else {
downloadInfo.setStatus(status);
DataSet.updateDownloadInfo(downloadInfo);
downloadInfo.setStatus(status);
DataSet.updateDownloadInfo(downloadInfo);
}
}
@Override
public void handleCancel(String videoId) {}
public void handleCancel(String videoId) {
}
@Override
public void getFormat(String format) {
......@@ -80,6 +85,50 @@ public class DownloadWrapper {
if (downloadInfo.getStatus() == Downloader.DOWNLOAD) {
downloader.start();
}
//字幕回调
downloader.setOnDownloadSubtitleListener(new OnDownloadSubtitleListener() {
@Override
public void onSubtitleNum(int subtitleNum) {
downloadInfo.setSubtitleNum(subtitleNum);
DataSet.updateDownloadInfo(downloadInfo);
}
@Override
public void onDownloadFirstSubtitleSuccess(String subtitlePath) {
downloadInfo.setFirstSubtitleStatus(1);
DataSet.updateDownloadInfo(downloadInfo);
}
@Override
public void onDownloadFirstSubtitleFail(String subtitlePath, String subtitleUrl) {
downloadInfo.setFirstSubtitleStatus(2);
DataSet.updateDownloadInfo(downloadInfo);
}
@Override
public void onDownloadSecondSubtitleSuccess(String subtitlePath) {
downloadInfo.setSecondSubtitleStatus(1);
DataSet.updateDownloadInfo(downloadInfo);
}
@Override
public void onDownloadSecondSubtitleFail(String subtitlePath, String subtitleUrl) {
downloadInfo.setSecondSubtitleStatus(2);
DataSet.updateDownloadInfo(downloadInfo);
}
@Override
public void onSaveSubtitleSetSuccess(String subtitleSetPath) {
}
@Override
public void onSaveSubtitleSetFail(String subtitleSetInfo) {
}
});
}
public DownloadInfo getDownloadInfo() {
......@@ -104,7 +153,7 @@ public class DownloadWrapper {
return downloadInfo.getStart() * 100 / downloadInfo.getEnd();
}
}
public String getSpeed(Context context) {
String speed = Formatter.formatFileSize(context, downloadInfo.getStart() - lastStart) + "/s";
lastStart = downloadInfo.getStart();
......@@ -112,27 +161,27 @@ public class DownloadWrapper {
}
public void start() {
downloadInfo.setStatus(Downloader.DOWNLOAD);
downloadInfo.setStatus(Downloader.DOWNLOAD);
downloader.start();
}
public void resume() {
downloadInfo.setStatus(Downloader.DOWNLOAD);
downloadInfo.setStatus(Downloader.DOWNLOAD);
downloader.resume();
}
public void setToWait() {
downloadInfo.setStatus(Downloader.WAIT);
downloadInfo.setStatus(Downloader.WAIT);
downloader.setToWaitStatus();
}
public void pause() {
downloadInfo.setStatus(Downloader.PAUSE);
downloadInfo.setStatus(Downloader.PAUSE);
downloader.pause();
}
public void cancel() {
downloadInfo.setStatus(Downloader.PAUSE);
downloadInfo.setStatus(Downloader.PAUSE);
downloader.cancel();
}
}
......@@ -102,6 +102,18 @@ public class DownloadedFragment extends Fragment implements DownloadController.O
Log.i("dwdemo", "删除已下载视频成功:" + file.getAbsolutePath());
file.delete();
}
File subtitle = new File(Environment.getExternalStorageDirectory() + "/" + ConfigUtil.DOWNLOAD_PATH, wrapper.getDownloadInfo().getTitle() + "subtitle.srt");
if (subtitle.exists()){
subtitle.delete();
}
File subtitle2 = new File(Environment.getExternalStorageDirectory() + "/" + ConfigUtil.DOWNLOAD_PATH, wrapper.getDownloadInfo().getTitle() + "subtitle2.srt");
if (subtitle2.exists()){
subtitle2.delete();
}
File subtitleSet = new File(Environment.getExternalStorageDirectory() + "/" + ConfigUtil.DOWNLOAD_PATH, wrapper.getDownloadInfo().getTitle() + "subtitleSet.json");
if (subtitleSet.exists()){
subtitleSet.delete();
}
updateView();
}
......
......@@ -14,6 +14,7 @@ import android.widget.Button;
import android.widget.ListView;
import com.bokecc.sdk.mobile.util.HttpUtil;
import com.bokecc.vod.ConfigUtil;
import com.bokecc.vod.R;
import com.bokecc.vod.adapter.DownloadViewAdapter;
......@@ -74,6 +75,19 @@ public class DownloadingFragment extends Fragment implements DownloadController.
if (file.exists()) {
file.delete();
}
File subtitle = new File(Environment.getExternalStorageDirectory() + "/" + ConfigUtil.DOWNLOAD_PATH, title + "subtitle.srt");
if (subtitle.exists()){
subtitle.delete();
}
File subtitle2 = new File(Environment.getExternalStorageDirectory() + "/" + ConfigUtil.DOWNLOAD_PATH, title + "subtitle2.srt");
if (subtitle2.exists()){
subtitle2.delete();
}
File subtitleSet = new File(Environment.getExternalStorageDirectory() + "/" + ConfigUtil.DOWNLOAD_PATH, title + "subtitleSet.json");
if (subtitleSet.exists()){
subtitleSet.delete();
}
DownloadController.deleteDownloadingInfo(position);
updateListView();
initAllPause();
......
......@@ -1182,7 +1182,22 @@ public class MediaPlayActivity extends Activity implements View.OnClickListener,
if (!new File(path).exists()) {
return;
}
//离线字幕
String subtitlePath = Environment.getExternalStorageDirectory() + "/".concat(ConfigUtil.DOWNLOAD_PATH).concat("/").concat(videoTitle).concat("subtitle.srt");
if (new File(subtitlePath).exists()) {
sv_subtitle.initFirstOfflineSubtitleInfo(subtitlePath);
}
String subtitlePath2 = Environment.getExternalStorageDirectory() + "/".concat(ConfigUtil.DOWNLOAD_PATH).concat("/").concat(videoTitle).concat("subtitle2.srt");
if (new File(subtitlePath2).exists()) {
sv_subtitle.initSecondOfflineSubtitleInfo(subtitlePath2);
}
String subtitleSetPath = Environment.getExternalStorageDirectory() + "/".concat(ConfigUtil.DOWNLOAD_PATH).concat("/").concat(videoTitle).concat("subtitleSet.json");
if (new File(subtitleSetPath).exists()) {
sv_subtitle.initOfflineSubtitleSet(activity, subtitleSetPath);
}
}
try {
player.setOfflineVideoPath(path, activity);
hideOnlineOperation();
......@@ -2888,6 +2903,7 @@ public class MediaPlayActivity extends Activity implements View.OnClickListener,
}
if (!isFullScreen) {
setPortVideo();
sv_subtitle.setLandScape(false);
} else {
//重置画面大小
setSize(1);
......@@ -3437,6 +3453,7 @@ public class MediaPlayActivity extends Activity implements View.OnClickListener,
iv_portrait_screenshot.setVisibility(View.VISIBLE);
}
iv_portrait_projection.setVisibility(View.VISIBLE);
sv_subtitle.setLandScape(false);
//小屏播放隐藏打点信息
sb_progress.setHotspotShown(false);
sb_portrait_progress.setHotspotShown(false);
......@@ -3489,6 +3506,7 @@ public class MediaPlayActivity extends Activity implements View.OnClickListener,
iv_landscape_screenshot.setVisibility(View.GONE);
iv_more_settings.setVisibility(View.GONE);
}
sv_subtitle.setLandScape(true);
//全屏播放展示打点信息
sb_progress.setHotspotShown(true);
sb_portrait_progress.setHotspotShown(true);
......@@ -3613,7 +3631,7 @@ public class MediaPlayActivity extends Activity implements View.OnClickListener,
//展示课堂练习
if (isShowExercise((int) currentPosition)) {
if (!isShowExercise){
if (!isShowExercise) {
return;
}
if (exeDialog != null && exeDialog.isShowing()) {
......@@ -3877,11 +3895,11 @@ public class MediaPlayActivity extends Activity implements View.OnClickListener,
}
@Override
public void backPlay(int backPlayTime, boolean isExerciseBackPlay,boolean isRemoveExercise) {
public void backPlay(int backPlayTime, boolean isExerciseBackPlay, boolean isRemoveExercise) {
if (isExerciseBackPlay) {
doExerciseDialog = null;
}
if (isRemoveExercise){
if (isRemoveExercise) {
exercises.remove(0);
}
isShowConfirmExerciseDialog = false;
......
......@@ -1183,6 +1183,19 @@ public class SpeedPlayActivity extends Activity implements View.OnClickListener,
return;
}
//离线字幕
String subtitlePath = Environment.getExternalStorageDirectory() + "/".concat(ConfigUtil.DOWNLOAD_PATH).concat("/").concat(videoTitle).concat("subtitle.srt");
if (new File(subtitlePath).exists()) {
sv_subtitle.initFirstOfflineSubtitleInfo(subtitlePath);
}
String subtitlePath2 = Environment.getExternalStorageDirectory() + "/".concat(ConfigUtil.DOWNLOAD_PATH).concat("/").concat(videoTitle).concat("subtitle2.srt");
if (new File(subtitlePath2).exists()) {
sv_subtitle.initSecondOfflineSubtitleInfo(subtitlePath2);
}
String subtitleSetPath = Environment.getExternalStorageDirectory() + "/".concat(ConfigUtil.DOWNLOAD_PATH).concat("/").concat(videoTitle).concat("subtitleSet.json");
if (new File(subtitleSetPath).exists()) {
sv_subtitle.initOfflineSubtitleSet(activity,subtitleSetPath);
}
}
try {
player.setOfflineVideoPath(path, activity);
......@@ -2906,6 +2919,7 @@ public class SpeedPlayActivity extends Activity implements View.OnClickListener,
if (!isFullScreen) {
setPortVideo();
sv_subtitle.setLandScape(false);
} else {
//重置画面大小
setSize(1);
......@@ -3463,6 +3477,7 @@ public class SpeedPlayActivity extends Activity implements View.OnClickListener,
iv_portrait_screenshot.setVisibility(View.VISIBLE);
}
iv_portrait_projection.setVisibility(View.VISIBLE);
sv_subtitle.setLandScape(false);
//小屏播放隐藏打点信息
sb_progress.setHotspotShown(false);
sb_portrait_progress.setHotspotShown(false);
......@@ -3514,6 +3529,7 @@ public class SpeedPlayActivity extends Activity implements View.OnClickListener,
iv_landscape_screenshot.setVisibility(View.GONE);
iv_more_settings.setVisibility(View.GONE);
}
sv_subtitle.setLandScape(true);
//全屏播放展示打点信息
sb_progress.setHotspotShown(true);
sb_portrait_progress.setHotspotShown(true);
......
......@@ -806,6 +806,20 @@ public class VrPlayActivity extends Activity implements View.OnClickListener,
if (!new File(path).exists()) {
return;
}
//离线字幕
String subtitlePath = Environment.getExternalStorageDirectory() + "/".concat(ConfigUtil.DOWNLOAD_PATH).concat("/").concat(videoTitle).concat("subtitle.srt");
if (new File(subtitlePath).exists()) {
sv_subtitle.initFirstOfflineSubtitleInfo(subtitlePath);
}
String subtitlePath2 = Environment.getExternalStorageDirectory() + "/".concat(ConfigUtil.DOWNLOAD_PATH).concat("/").concat(videoTitle).concat("subtitle2.srt");
if (new File(subtitlePath2).exists()) {
sv_subtitle.initSecondOfflineSubtitleInfo(subtitlePath2);
}
String subtitleSetPath = Environment.getExternalStorageDirectory() + "/".concat(ConfigUtil.DOWNLOAD_PATH).concat("/").concat(videoTitle).concat("subtitleSet.json");
if (new File(subtitleSetPath).exists()) {
sv_subtitle.initOfflineSubtitleSet(activity,subtitleSetPath);
}
}
try {
player.setOfflineVideoPath(path, activity);
......@@ -2060,6 +2074,7 @@ public class VrPlayActivity extends Activity implements View.OnClickListener,
if (!isFullScreen) {
setPortVideo();
sv_subtitle.setLandScape(false);
} else {
//重置画面大小
setSize(1);
......@@ -2600,6 +2615,7 @@ public class VrPlayActivity extends Activity implements View.OnClickListener,
iv_switch_mt.setVisibility(View.GONE);
iv_switch_sd.setVisibility(View.GONE);
iv_portrait_projection.setVisibility(View.VISIBLE);
sv_subtitle.setLandScape(false);
//小屏播放隐藏打点信息
sb_progress.setHotspotShown(false);
iv_more_settings.setVisibility(View.GONE);
......@@ -2643,6 +2659,7 @@ public class VrPlayActivity extends Activity implements View.OnClickListener,
iv_lock_or_unlock.setVisibility(View.GONE);
iv_more_settings.setVisibility(View.GONE);
}
sv_subtitle.setLandScape(true);
//全屏播放展示打点信息
sb_progress.setHotspotShown(true);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
......
......@@ -2,7 +2,12 @@ package com.bokecc.vod.view;
import android.util.Log;
import com.bokecc.sdk.mobile.util.HttpUtil;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
......@@ -14,150 +19,189 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
*
* 字幕处理类
*
* @author 获得场景视频
*
* @author 获得场景视频
*/
public class Subtitle {
private final String REG = "\\d+\\r\\n(\\d{2}:\\d{2}:\\d{2},\\d{3}) --> (\\d{2}:\\d{2}:\\d{2},\\d{3})\\r\\n(.*?)\\r\\n\\r\\n";
private int start;
private int end;
private String content;
private List<Subtitle> subtitles;
/**
* 字幕初始化监听器
*
*/
public interface OnSubtitleInitedListener {
public void onInited(Subtitle subtitle);
}
private OnSubtitleInitedListener onSubtitleInitedListener;
private Subtitle() {
}
public Subtitle(OnSubtitleInitedListener onSubtitleInitedListener) {
this.onSubtitleInitedListener = onSubtitleInitedListener;
this.subtitles = new ArrayList<Subtitle>();
}
public int getStart() {
return start;
}
public void setStart(int start) {
this.start = start;
}
public int getEnd() {
return end;
}
public void setEnd(int end) {
this.end = end;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public void setResource() {
}
public void initSubtitleResource(final String subtitleUrl) {
new Thread(new Runnable() {
@Override
public void run() {
HttpURLConnection connection = null;
BufferedReader reader = null;
try {
URL url = new URL(subtitleUrl);
connection = (HttpURLConnection) url.openConnection();
//设置请求方法
connection.setRequestMethod("GET");
//设置连接超时时间(毫秒)
connection.setConnectTimeout(5000);
//设置读取超时时间(毫秒)
connection.setReadTimeout(5000);
//返回输入流
InputStream in = connection.getInputStream();
//读取输入流
reader = new BufferedReader(new InputStreamReader(in));
StringBuilder sb = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
sb.append(line+ "\r\n");
}
String result = sb.toString();
parseSubtitleStr(result);
} catch (Exception e) {
Log.e("CCVideoViewDemo", "" + e.getMessage());
}finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (connection != null) {//关闭连接
connection.disconnect();
}
}
}
}).start();
}
public String getSubtitleByTime(long time) {
for (Subtitle subtitle : subtitles) {
if (subtitle.getStart() <= time && time <= subtitle.getEnd()) {
return subtitle.getContent();