fix bug https://github.com/AriaLyy/Aria/issues/508
fix bug https://github.com/AriaLyy/Aria/issues/503
修复m3u8创建索引不成功的问题
This commit is contained in:
laoyuyu
2019-11-10 13:25:21 +08:00
parent 012f94511b
commit 5ad485890c
44 changed files with 753 additions and 242 deletions

View File

@@ -58,11 +58,6 @@ public class M3U8Entity extends DbEntity implements Parcelable {
*/
private String cacheDir;
/**
* 生成索引
*/
private boolean generateIndexFile;
/**
* 加密key保存地址
*/
@@ -115,14 +110,6 @@ public class M3U8Entity extends DbEntity implements Parcelable {
this.iv = iv;
}
public boolean isGenerateIndexFile() {
return generateIndexFile;
}
public void setGenerateIndexFile(boolean generateIndexFile) {
this.generateIndexFile = generateIndexFile;
}
public boolean isLive() {
return isLive;
}
@@ -248,7 +235,6 @@ public class M3U8Entity extends DbEntity implements Parcelable {
dest.writeInt(this.peerNum);
dest.writeByte(this.isLive ? (byte) 1 : (byte) 0);
dest.writeString(this.cacheDir);
dest.writeByte(this.generateIndexFile ? (byte) 1 : (byte) 0);
dest.writeString(this.keyPath);
dest.writeString(this.keyUrl);
dest.writeString(this.method);
@@ -261,7 +247,6 @@ public class M3U8Entity extends DbEntity implements Parcelable {
this.peerNum = in.readInt();
this.isLive = in.readByte() != 0;
this.cacheDir = in.readString();
this.generateIndexFile = in.readByte() != 0;
this.keyPath = in.readString();
this.keyUrl = in.readString();
this.method = in.readString();

View File

@@ -80,7 +80,7 @@ public abstract class AbsGroupUtil implements IUtil, Runnable {
/**
* 初始化组合任务状态
*/
protected void initState() {
private void initState() {
mState = new GroupRunState(getWrapper().getKey(), mListener,
mGTWrapper.getSubTaskWrapper().size(), mSubQueue);
for (DTaskWrapper wrapper : mGTWrapper.getSubTaskWrapper()) {

View File

@@ -200,8 +200,7 @@ public class NormalLoader extends AbsLoader {
ALog.d(TAG, String.format("进度修正,当前进度:%s", currentProgress));
getEntity().setCurrentProgress(currentProgress);
}
mStateHandler.obtainMessage(IThreadState.STATE_UPDATE_PROGRESS, currentProgress)
.sendToTarget();
mStateManager.updateProgress(currentProgress);
startThreadTask();
}

View File

@@ -19,9 +19,9 @@ import android.os.Bundle;
import android.os.Looper;
import android.os.Message;
import com.arialyy.aria.core.TaskRecord;
import com.arialyy.aria.core.listener.IEventListener;
import com.arialyy.aria.core.inf.IRecordHandler;
import com.arialyy.aria.core.inf.IThreadState;
import com.arialyy.aria.core.listener.IEventListener;
import com.arialyy.aria.exception.BaseException;
import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.FileUtil;
@@ -59,6 +59,13 @@ public class ThreadStateManager implements IThreadState {
mListener = listener;
}
/**
* 不要使用handle更新启动线程的进度因为有延迟
*/
void updateProgress(long curProgress) {
mProgress = curProgress;
}
@Override public boolean handleMessage(Message msg) {
switch (msg.what) {
case STATE_STOP:

View File

@@ -22,7 +22,7 @@ import com.arialyy.aria.util.CommonUtil;
import java.io.File;
/**
* 文件任务适配器
* 文件任务适配器
*
* @Author lyy
* @Date 2019-09-19

View File

@@ -97,7 +97,7 @@ public abstract class AbsThreadTaskAdapter implements IThreadTaskAdapter {
return mThreadConfig;
}
@Override public void setThreadStateObserver(IThreadTaskObserver observer) {
@Override public void attach(IThreadTaskObserver observer) {
mObserver = observer;
}

View File

@@ -36,7 +36,7 @@ public interface IThreadTaskAdapter {
void setMaxSpeed(int speed);
/**
* 设置线程任务状态观察者
* 注册观察者
*/
void setThreadStateObserver(IThreadTaskObserver observer);
void attach(IThreadTaskObserver observer);
}

View File

@@ -33,6 +33,7 @@ import com.arialyy.aria.core.wrapper.ITaskWrapper;
import com.arialyy.aria.exception.BaseException;
import com.arialyy.aria.util.ALog;
import com.arialyy.aria.util.BufferedRandomAccessFile;
import com.arialyy.aria.util.CommonUtil;
import com.arialyy.aria.util.ErrorHelp;
import com.arialyy.aria.util.FileUtil;
import com.arialyy.aria.util.NetUtils;
@@ -49,7 +50,7 @@ public class ThreadTask implements IThreadTask, IThreadTaskObserver {
* 线程重试次数
*/
private final int RETRY_NUM = 2;
private final String TAG = "AbsThreadTask";
private final String TAG = CommonUtil.getClassName(getClass());
private IEntity mEntity;
protected AbsTaskWrapper mTaskWrapper;
private int mFailTimes = 0;
@@ -94,7 +95,7 @@ public class ThreadTask implements IThreadTask, IThreadTaskObserver {
*/
public void setAdapter(IThreadTaskAdapter adapter) {
mAdapter = adapter;
mAdapter.setThreadStateObserver(this);
mAdapter.attach(this);
}
/**
@@ -335,7 +336,7 @@ public class ThreadTask implements IThreadTask, IThreadTaskObserver {
*/
protected void fail(final long subCurrentLocation, BaseException ex, boolean needRetry) {
if (ex != null) {
ALog.e(TAG, ALog.getExceptionString(ex));
ex.printStackTrace();
}
if (mTaskWrapper.getRequestType() == ITaskWrapper.M3U8_VOD) {
writeConfig(false, 0);

View File

@@ -17,6 +17,9 @@
package com.arialyy.aria.util;
import android.text.TextUtils;
import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.inf.IRecordHandler;
import com.arialyy.aria.orm.DbEntity;
import java.lang.reflect.Modifier;
import java.util.List;
@@ -27,6 +30,27 @@ import java.util.List;
public class CheckUtil {
private static final String TAG = "CheckUtil";
/**
* 检查和处理路径冲突
*
* @param isForceDownload true如果路径冲突将删除其它任务的记录的
* @param filePath 文件保存路径
* @return false 任务不再执行true 任务继续执行
*/
public static boolean checkAndHandlePathConflicts(boolean isForceDownload, String filePath) {
if (DbEntity.checkDataExist(DownloadEntity.class, "downloadPath=?", filePath)) {
if (!isForceDownload) {
ALog.e(TAG, String.format("下载失败,保存路径【%s】已经被其它任务占用请设置其它保存路径", filePath));
return false;
} else {
ALog.w(TAG, String.format("保存路径【%s】已经被其它任务占用当前任务将覆盖该路径的文件", filePath));
RecordUtil.delTaskRecord(filePath, IRecordHandler.TYPE_DOWNLOAD);
return true;
}
}
return true;
}
/**
* 检查成员类是否是静态和public
*/

View File

@@ -295,7 +295,7 @@ public class RecordUtil {
}
/**
* 删除ts文件
* 删除ts文件,和索引文件(如果有的话)
*/
private static void removeTsCache(File targetFile, long bandWidth) {
@@ -321,6 +321,12 @@ public class RecordUtil {
cDir.delete();
}
}
File indexFile = new File(String.format("%s.index", targetFile.getPath()));
if (indexFile.exists()) {
indexFile.delete();
}
}
/**