m3u8增加了`ignoreFailureTs`方法,忽略虾类失败的ts切片

修复在dialogFragment的`onCreateDialog()`注册导致的注解不生效问题
pull/617/head
laoyuyu 5 years ago
parent d9ed7f87d2
commit f3d5e0135a
  1. 8
      Aria/src/main/java/com/arialyy/aria/core/WidgetLiftManager.java
  2. 63
      Aria/src/main/java/com/arialyy/aria/core/common/ProxyHelper.java
  3. 9
      Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8Option.java
  4. 3
      DEV_LOG.md
  5. 4
      M3U8Component/src/main/java/com/arialyy/aria/m3u8/M3U8InfoThread.java
  6. 14
      M3U8Component/src/main/java/com/arialyy/aria/m3u8/M3U8TaskOption.java
  7. 14
      M3U8Component/src/main/java/com/arialyy/aria/m3u8/vod/M3U8VodLoader.java
  8. 28
      PublicComponent/src/main/java/com/arialyy/aria/core/download/M3U8Entity.java
  9. 27
      app/src/main/java/com/arialyy/simple/core/download/KotlinDownloadActivity.kt
  10. 2
      build.gradle

@ -73,8 +73,16 @@ final class WidgetLiftManager {
/** /**
* 处理对话框取消或dismiss * 处理对话框取消或dismiss
*
* @return true 设置了dialog的销毁事件false 没有设置dialog的销毁事件
*/ */
boolean handleDialogLift(Dialog dialog) { boolean handleDialogLift(Dialog dialog) {
if (dialog == null) {
ALog.w(TAG,
"dialog 为空,没有设置自动销毁事件,为了防止内存泄露,请在dismiss方法中调用Aria.download(this).unRegister();来注销事件\n"
+ "如果你使用的是DialogFragment,那么你需要在onDestroy()中进行销毁Aria事件操作");
return false;
}
try { try {
Field dismissField = CommonUtil.getField(dialog.getClass(), "mDismissMessage"); Field dismissField = CommonUtil.getField(dialog.getClass(), "mDismissMessage");
Message dismissMsg = (Message) dismissField.get(dialog); Message dismissMsg = (Message) dismissField.get(dialog);

@ -75,50 +75,23 @@ public class ProxyHelper {
return result; return result;
} }
result = new HashSet<>(); result = new HashSet<>();
try { if (checkProxyExist(className, TaskEnum.DOWNLOAD_GROUP.proxySuffix)) {
if (getClass().getClassLoader() result.add(PROXY_TYPE_DOWNLOAD_GROUP);
.loadClass(className.concat(TaskEnum.DOWNLOAD_GROUP.proxySuffix))
!= null) {
result.add(PROXY_TYPE_DOWNLOAD_GROUP);
}
} catch (ClassNotFoundException e) {
//e.printStackTrace();
} }
try { if (checkProxyExist(className, TaskEnum.DOWNLOAD.proxySuffix)) {
if (getClass().getClassLoader().loadClass(className.concat(TaskEnum.DOWNLOAD.proxySuffix)) result.add(PROXY_TYPE_DOWNLOAD);
!= null) {
result.add(PROXY_TYPE_DOWNLOAD);
}
} catch (ClassNotFoundException e) {
//e.printStackTrace();
} }
try { if (checkProxyExist(className, TaskEnum.UPLOAD.proxySuffix)) {
if (getClass().getClassLoader().loadClass(className.concat(TaskEnum.UPLOAD.proxySuffix)) result.add(PROXY_TYPE_UPLOAD);
!= null) {
result.add(PROXY_TYPE_UPLOAD);
}
} catch (ClassNotFoundException e) {
//e.printStackTrace();
} }
try { if (checkProxyExist(className, TaskEnum.M3U8_PEER.proxySuffix)) {
if (getClass().getClassLoader().loadClass(className.concat(TaskEnum.M3U8_PEER.proxySuffix)) result.add(PROXY_TYPE_M3U8_PEER);
!= null) {
result.add(PROXY_TYPE_M3U8_PEER);
}
} catch (ClassNotFoundException e) {
//e.printStackTrace();
} }
try { if (checkProxyExist(className, TaskEnum.DOWNLOAD_GROUP_SUB.proxySuffix)) {
if (getClass().getClassLoader() result.add(PROXY_TYPE_DOWNLOAD_GROUP_SUB);
.loadClass(className.concat(TaskEnum.DOWNLOAD_GROUP_SUB.proxySuffix))
!= null) {
result.add(PROXY_TYPE_DOWNLOAD_GROUP_SUB);
}
} catch (ClassNotFoundException e) {
//e.printStackTrace();
} }
if (!result.isEmpty()) { if (!result.isEmpty()) {
@ -126,4 +99,20 @@ public class ProxyHelper {
} }
return result; return result;
} }
private boolean checkProxyExist(String className, String proxySuffix) {
String clsName = className.concat(proxySuffix);
try {
if (getClass().getClassLoader().loadClass(clsName) != null) {
return true;
}
if (Class.forName(clsName) != null) {
return true;
}
} catch (ClassNotFoundException e) {
//e.printStackTrace();
}
return false;
}
} }

@ -33,12 +33,21 @@ public class M3U8Option<OP extends M3U8Option> extends BaseOption {
private ITsMergeHandler mergeHandler; private ITsMergeHandler mergeHandler;
private IBandWidthUrlConverter bandWidthUrlConverter; private IBandWidthUrlConverter bandWidthUrlConverter;
private IKeyUrlConverter keyUrlConverter; private IKeyUrlConverter keyUrlConverter;
private boolean ignoreFailureTs = false;
M3U8Option() { M3U8Option() {
super(); super();
ComponentUtil.getInstance().checkComponentExist(ComponentUtil.COMPONENT_TYPE_M3U8); ComponentUtil.getInstance().checkComponentExist(ComponentUtil.COMPONENT_TYPE_M3U8);
} }
/**
* 忽略下载失败的ts切片即使有失败的切片下载完成后也要合并所有切片并进入complete回调
*/
public OP ignoreFailureTs() {
this.ignoreFailureTs = true;
return (OP) this;
}
/** /**
* 生成m3u8索引文件 * 生成m3u8索引文件
* 注意创建索引文件{@link #merge(boolean)}方法设置与否都不再合并文件 * 注意创建索引文件{@link #merge(boolean)}方法设置与否都不再合并文件

@ -2,6 +2,9 @@
+ v_3.8 + v_3.8
- 移除androidx和support的依赖,现在无论是哪个版本的appcompat包都可以使用本框架 - 移除androidx和support的依赖,现在无论是哪个版本的appcompat包都可以使用本框架
- 修复一个在xml中使用fragment导致的内存泄漏问题 - 修复一个在xml中使用fragment导致的内存泄漏问题
- m3u8协议的key信息增加了`keyFormat`,`keyFormatVersion`字段
- m3u8增加了`ignoreFailureTs`方法,忽略虾类失败的ts切片
- 修复在dialogFragment的`onCreateDialog()`注册导致的注解不生效问题
+ v_3.7.10 (2019/12/3) + v_3.7.10 (2019/12/3)
- fix bug https://github.com/AriaLyy/Aria/issues/543#issuecomment-559733124 - fix bug https://github.com/AriaLyy/Aria/issues/543#issuecomment-559733124
- fix bug https://github.com/AriaLyy/Aria/issues/542 - fix bug https://github.com/AriaLyy/Aria/issues/542

@ -255,6 +255,10 @@ final public class M3U8InfoThread implements Runnable {
m3U8Entity.keyUrl) + ".key"; m3U8Entity.keyUrl) + ".key";
} else if (param.startsWith("IV")) { } else if (param.startsWith("IV")) {
m3U8Entity.iv = param.split("=")[1]; m3U8Entity.iv = param.split("=")[1];
}else if (param.startsWith("KEYFORMAT")){
m3U8Entity.keyFormat = param.split("=")[1];
}else if (param.startsWith("KEYFORMATVERSIONS")){
m3U8Entity.keyFormatVersion = param.split("=")[1];
} }
} }
downloadKey(m3U8Entity); downloadKey(m3U8Entity);

@ -109,6 +109,20 @@ public class M3U8TaskOption implements ITaskOption {
*/ */
private SoftReference<IKeyUrlConverter> keyUrlConverter; private SoftReference<IKeyUrlConverter> keyUrlConverter;
/**
* 忽略下载失败的ts切片
* true即使有失败的切片下载完成后也要合并所有切片并进入complete回调
*/
private boolean ignoreFailureTs = false;
public boolean isIgnoreFailureTs() {
return ignoreFailureTs;
}
public void setIgnoreFailureTs(boolean ignoreFailureTs) {
this.ignoreFailureTs = ignoreFailureTs;
}
public IKeyUrlConverter getKeyUrlConverter() { public IKeyUrlConverter getKeyUrlConverter() {
return keyUrlConverter == null ? null : keyUrlConverter.get(); return keyUrlConverter == null ? null : keyUrlConverter.get();
} }

@ -221,9 +221,9 @@ public class M3U8VodLoader extends BaseM3U8Loader {
} }
} }
mManager.updateStateCount(); mManager.updateStateCount();
if (mCompleteNum <= 0){ if (mCompleteNum <= 0) {
mListener.onStart(0); mListener.onStart(0);
}else { } else {
int percent = mCompleteNum * 100 / mRecord.threadRecords.size(); int percent = mCompleteNum * 100 / mRecord.threadRecords.size();
mListener.onResume(percent); mListener.onResume(percent);
} }
@ -570,9 +570,9 @@ public class M3U8VodLoader extends BaseM3U8Loader {
ALog.d(TAG, String.format("vod任务【%s】完成", mTempFile.getName())); ALog.d(TAG, String.format("vod任务【%s】完成", mTempFile.getName()));
if (mM3U8Option.isGenerateIndexFile()) { if (mM3U8Option.isGenerateIndexFile()) {
if (generateIndexFile(false)){ if (generateIndexFile(false)) {
listener.onComplete(); listener.onComplete();
}else { } else {
listener.onFail(false, new TaskException(TAG, "创建索引文件失败")); listener.onFail(false, new TaskException(TAG, "创建索引文件失败"));
} }
} else if (mM3U8Option.isMergeFile()) { } else if (mM3U8Option.isMergeFile()) {
@ -621,7 +621,11 @@ public class M3U8VodLoader extends BaseM3U8Loader {
} }
@Override public boolean isComplete() { @Override public boolean isComplete() {
return mCompleteNum == taskRecord.threadRecords.size() && !isJump; if (mM3U8Option.isIgnoreFailureTs()) {
return mCompleteNum + failNum >= taskRecord.threadRecords.size() && !isJump;
} else {
return mCompleteNum == taskRecord.threadRecords.size() && !isJump;
}
} }
@Override public long getCurrentProgress() { @Override public long getCurrentProgress() {

@ -21,6 +21,7 @@ import android.text.TextUtils;
import com.arialyy.aria.core.TaskRecord; import com.arialyy.aria.core.TaskRecord;
import com.arialyy.aria.core.ThreadRecord; import com.arialyy.aria.core.ThreadRecord;
import com.arialyy.aria.orm.DbEntity; import com.arialyy.aria.orm.DbEntity;
import com.arialyy.aria.orm.annotation.Default;
import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.DbDataHelper; import com.arialyy.aria.util.DbDataHelper;
import java.io.File; import java.io.File;
@ -78,6 +79,33 @@ public class M3U8Entity extends DbEntity implements Parcelable {
*/ */
public String iv; public String iv;
/**
* key的格式可能为空
*/
public String keyFormat;
/**
* key的格式版本默认为1如果是多个版本使用"/"分隔"1", "1/2", or "1/2/5"
*/
@Default("1")
public String keyFormatVersion = "1";
public String getKeyFormat() {
return keyFormat;
}
public void setKeyFormat(String keyFormat) {
this.keyFormat = keyFormat;
}
public String getKeyFormatVersion() {
return keyFormatVersion;
}
public void setKeyFormatVersion(String keyFormatVersion) {
this.keyFormatVersion = keyFormatVersion;
}
public String getKeyPath() { public String getKeyPath() {
return keyPath; return keyPath;
} }

@ -50,7 +50,7 @@ class KotlinDownloadActivity : BaseActivity<ActivitySingleKotlinBinding>() {
private var mUrl: String? = null private var mUrl: String? = null
private var mFilePath: String? = null private var mFilePath: String? = null
private var mModule: HttpDownloadModule? = null private var mModule: HttpDownloadModule? = null
private val mTaskId: Long = -1 private var mTaskId: Long = -1
internal var receiver: BroadcastReceiver = object : BroadcastReceiver() { internal var receiver: BroadcastReceiver = object : BroadcastReceiver() {
override fun onReceive( override fun onReceive(
@ -104,7 +104,7 @@ class KotlinDownloadActivity : BaseActivity<ActivitySingleKotlinBinding>() {
.get(HttpDownloadModule::class.java) .get(HttpDownloadModule::class.java)
mModule!!.getHttpDownloadInfo(this) mModule!!.getHttpDownloadInfo(this)
.observe(this, Observer { entity -> .observe(this, Observer { entity ->
if (entity == null || entity.id < 0) { if (entity == null) {
return@Observer return@Observer
} }
if (entity.state == IEntity.STATE_STOP) { if (entity.state == IEntity.STATE_STOP) {
@ -286,14 +286,21 @@ class KotlinDownloadActivity : BaseActivity<ActivitySingleKotlinBinding>() {
} }
private fun startD() { private fun startD() {
Aria.download(this) if (mTaskId == -1L) {
.load(mUrl!!)
//.addHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3") mTaskId = Aria.download(this)
//.addHeader("Accept-Encoding", "gzip, deflate") .load(mUrl!!)
//.addHeader("DNT", "1") //.addHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3")
//.addHeader("Cookie", "BAIDUID=648E5FF020CC69E8DD6F492D1068AAA9:FG=1; BIDUPSID=648E5FF020CC69E8DD6F492D1068AAA9; PSTM=1519099573; BD_UPN=12314753; locale=zh; BDSVRTM=0") //.addHeader("Accept-Encoding", "gzip, deflate")
.setFilePath(mFilePath!!, true) //.addHeader("DNT", "1")
.create() //.addHeader("Cookie", "BAIDUID=648E5FF020CC69E8DD6F492D1068AAA9:FG=1; BIDUPSID=648E5FF020CC69E8DD6F492D1068AAA9; PSTM=1519099573; BD_UPN=12314753; locale=zh; BDSVRTM=0")
.setFilePath(mFilePath!!, true)
.create()
} else {
Aria.download(this)
.load(mTaskId)
.resume()
}
} }
override fun onStop() { override fun onStop() {

@ -45,7 +45,7 @@ task clean(type: Delete) {
ext { ext {
versionCode = 380 versionCode = 380
versionName = '3.7.10' versionName = '3.8_pre_1'
userOrg = 'arialyy' userOrg = 'arialyy'
groupId = 'com.arialyy.aria' groupId = 'com.arialyy.aria'
publishVersion = versionName publishVersion = versionName

Loading…
Cancel
Save