修复组件出现的几个问题
This commit is contained in:
@@ -24,7 +24,6 @@ import com.arialyy.aria.core.listener.BaseDListener;
|
||||
import com.arialyy.aria.core.listener.IDLoadListener;
|
||||
import com.arialyy.aria.core.listener.ISchedulers;
|
||||
import com.arialyy.aria.core.task.AbsTask;
|
||||
import com.arialyy.aria.core.task.DownloadTask;
|
||||
import com.arialyy.aria.util.CommonUtil;
|
||||
|
||||
/**
|
||||
@@ -32,7 +31,7 @@ import com.arialyy.aria.util.CommonUtil;
|
||||
*/
|
||||
public class M3U8Listener extends BaseDListener implements IDLoadListener {
|
||||
|
||||
M3U8Listener(AbsTask<DTaskWrapper> task, Handler outHandler) {
|
||||
public M3U8Listener(AbsTask<DTaskWrapper> task, Handler outHandler) {
|
||||
super(task, outHandler);
|
||||
}
|
||||
|
||||
|
||||
@@ -15,10 +15,10 @@
|
||||
*/
|
||||
package com.arialyy.aria.m3u8;
|
||||
|
||||
import com.arialyy.aria.core.processor.IBandWidthUrlConverter;
|
||||
import com.arialyy.aria.core.inf.ITaskOption;
|
||||
import com.arialyy.aria.core.processor.ITsMergeHandler;
|
||||
import com.arialyy.aria.core.processor.IBandWidthUrlConverter;
|
||||
import com.arialyy.aria.core.processor.ILiveTsUrlConverter;
|
||||
import com.arialyy.aria.core.processor.ITsMergeHandler;
|
||||
import com.arialyy.aria.core.processor.IVodTsUrlConverter;
|
||||
import java.lang.ref.SoftReference;
|
||||
import java.util.List;
|
||||
@@ -101,7 +101,7 @@ public class M3U8TaskOption implements ITaskOption {
|
||||
/**
|
||||
* 生成索引占位字段
|
||||
*/
|
||||
private boolean generateIndexFileTemp;
|
||||
private boolean generateIndexFileTemp = false;
|
||||
|
||||
public boolean isGenerateIndexFileTemp() {
|
||||
return generateIndexFileTemp;
|
||||
|
||||
@@ -60,7 +60,7 @@ public class M3U8ThreadTaskAdapter extends AbsThreadTaskAdapter {
|
||||
HttpURLConnection conn = null;
|
||||
BufferedInputStream is = null;
|
||||
try {
|
||||
URL url = ConnectionHelp.handleUrl(getConfig().url, mHttpTaskOption);
|
||||
URL url = ConnectionHelp.handleUrl(getThreadConfig().url, mHttpTaskOption);
|
||||
conn = ConnectionHelp.handleConnection(url, mHttpTaskOption);
|
||||
ALog.d(TAG, String.format("分片【%s】开始下载", getThreadRecord().threadId));
|
||||
ConnectionHelp.setConnectParam(mHttpTaskOption, conn);
|
||||
@@ -92,21 +92,21 @@ public class M3U8ThreadTaskAdapter extends AbsThreadTaskAdapter {
|
||||
is = new BufferedInputStream(ConnectionHelp.convertInputStream(conn));
|
||||
if (mHttpTaskOption.isChunked()) {
|
||||
readChunked(is);
|
||||
} else if (getConfig().isOpenDynamicFile) {
|
||||
} else if (getThreadConfig().isOpenDynamicFile) {
|
||||
readDynamicFile(is);
|
||||
}
|
||||
} catch (MalformedURLException e) {
|
||||
fail(new TaskException(TAG,
|
||||
String.format("分片【%s】下载失败,filePath: %s, url: %s", getThreadRecord().threadId,
|
||||
getConfig().tempFile.getPath(), getEntity().getUrl()), e), false);
|
||||
getThreadConfig().tempFile.getPath(), getEntity().getUrl()), e), false);
|
||||
} catch (IOException e) {
|
||||
fail(new TaskException(TAG,
|
||||
String.format("分片【%s】下载失败,filePath: %s, url: %s", getThreadRecord().threadId,
|
||||
getConfig().tempFile.getPath(), getEntity().getUrl()), e), true);
|
||||
getThreadConfig().tempFile.getPath(), getEntity().getUrl()), e), true);
|
||||
} catch (Exception e) {
|
||||
fail(new TaskException(TAG,
|
||||
String.format("分片【%s】下载失败,filePath: %s, url: %s", getThreadRecord().threadId,
|
||||
getConfig().tempFile.getPath(), getEntity().getUrl()), e), false);
|
||||
getThreadConfig().tempFile.getPath(), getEntity().getUrl()), e), false);
|
||||
} finally {
|
||||
try {
|
||||
if (is != null) {
|
||||
@@ -127,7 +127,7 @@ public class M3U8ThreadTaskAdapter extends AbsThreadTaskAdapter {
|
||||
private void readChunked(InputStream is) {
|
||||
FileOutputStream fos = null;
|
||||
try {
|
||||
fos = new FileOutputStream(getConfig().tempFile, true);
|
||||
fos = new FileOutputStream(getThreadConfig().tempFile, true);
|
||||
byte[] buffer = new byte[getTaskConfig().getBuffSize()];
|
||||
int len;
|
||||
while (getThreadTask().isLive() && (len = is.read(buffer)) != -1) {
|
||||
@@ -143,8 +143,8 @@ public class M3U8ThreadTaskAdapter extends AbsThreadTaskAdapter {
|
||||
handleComplete();
|
||||
} catch (IOException e) {
|
||||
fail(new AriaIOException(TAG,
|
||||
String.format("文件下载失败,savePath: %s, url: %s", getConfig().tempFile.getPath(),
|
||||
getConfig().url), e), true);
|
||||
String.format("文件下载失败,savePath: %s, url: %s", getThreadConfig().tempFile.getPath(),
|
||||
getThreadConfig().url), e), true);
|
||||
} finally {
|
||||
if (fos != null) {
|
||||
try {
|
||||
@@ -165,7 +165,7 @@ public class M3U8ThreadTaskAdapter extends AbsThreadTaskAdapter {
|
||||
ReadableByteChannel fic = null;
|
||||
try {
|
||||
int len;
|
||||
fos = new FileOutputStream(getConfig().tempFile, true);
|
||||
fos = new FileOutputStream(getThreadConfig().tempFile, true);
|
||||
foc = fos.getChannel();
|
||||
fic = Channels.newChannel(is);
|
||||
ByteBuffer bf = ByteBuffer.allocate(getTaskConfig().getBuffSize());
|
||||
@@ -186,8 +186,8 @@ public class M3U8ThreadTaskAdapter extends AbsThreadTaskAdapter {
|
||||
handleComplete();
|
||||
} catch (IOException e) {
|
||||
fail(new AriaIOException(TAG,
|
||||
String.format("文件下载失败,savePath: %s, url: %s", getConfig().tempFile.getPath(),
|
||||
getConfig().url), e), true);
|
||||
String.format("文件下载失败,savePath: %s, url: %s", getThreadConfig().tempFile.getPath(),
|
||||
getThreadConfig().url), e), true);
|
||||
} finally {
|
||||
try {
|
||||
if (fos != null) {
|
||||
|
||||
@@ -19,13 +19,15 @@ import android.text.TextUtils;
|
||||
import com.arialyy.aria.core.common.AbsEntity;
|
||||
import com.arialyy.aria.core.common.CompleteInfo;
|
||||
import com.arialyy.aria.core.download.DTaskWrapper;
|
||||
import com.arialyy.aria.core.download.DownloadEntity;
|
||||
import com.arialyy.aria.core.processor.ILiveTsUrlConverter;
|
||||
import com.arialyy.aria.core.inf.OnFileInfoCallback;
|
||||
import com.arialyy.aria.core.listener.IEventListener;
|
||||
import com.arialyy.aria.core.loader.AbsLoader;
|
||||
import com.arialyy.aria.core.loader.AbsNormalLoaderUtil;
|
||||
import com.arialyy.aria.core.processor.ILiveTsUrlConverter;
|
||||
import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
|
||||
import com.arialyy.aria.exception.BaseException;
|
||||
import com.arialyy.aria.exception.M3U8Exception;
|
||||
import com.arialyy.aria.http.HttpTaskOption;
|
||||
import com.arialyy.aria.m3u8.M3U8InfoThread;
|
||||
import com.arialyy.aria.m3u8.M3U8Listener;
|
||||
import com.arialyy.aria.m3u8.M3U8TaskOption;
|
||||
@@ -54,23 +56,28 @@ public class M3U8LiveUtil extends AbsNormalLoaderUtil {
|
||||
private List<String> mPeerUrls = new ArrayList<>();
|
||||
private M3U8TaskOption mM3U8Option;
|
||||
|
||||
protected M3U8LiveUtil(DTaskWrapper wrapper, M3U8Listener listener) {
|
||||
public M3U8LiveUtil(AbsTaskWrapper wrapper, IEventListener listener) {
|
||||
super(wrapper, listener);
|
||||
wrapper.generateM3u8Option(M3U8TaskOption.class);
|
||||
mM3U8Option = (M3U8TaskOption) wrapper.getM3u8Option();
|
||||
}
|
||||
|
||||
@Override public DTaskWrapper getTaskWrapper() {
|
||||
return (DTaskWrapper) super.getTaskWrapper();
|
||||
}
|
||||
|
||||
@Override protected AbsLoader createLoader() {
|
||||
return new M3U8LiveLoader((M3U8Listener) getListener(), (DTaskWrapper) getTaskWrapper());
|
||||
getTaskWrapper().generateM3u8Option(M3U8TaskOption.class);
|
||||
getTaskWrapper().generateTaskOption(HttpTaskOption.class);
|
||||
mM3U8Option = (M3U8TaskOption) getTaskWrapper().getM3u8Option();
|
||||
return new M3U8LiveLoader((M3U8Listener) getListener(), getTaskWrapper());
|
||||
}
|
||||
|
||||
@Override protected Runnable createInfoThread() {
|
||||
return null;
|
||||
}
|
||||
|
||||
private Runnable createLiveInfoThread(){
|
||||
private Runnable createLiveInfoThread() {
|
||||
M3U8InfoThread infoThread =
|
||||
new M3U8InfoThread((DTaskWrapper) getTaskWrapper(), new OnFileInfoCallback() {
|
||||
new M3U8InfoThread(getTaskWrapper(), new OnFileInfoCallback() {
|
||||
@Override public void onComplete(String key, CompleteInfo info) {
|
||||
ALog.d(TAG, "更新直播的m3u8文件");
|
||||
}
|
||||
@@ -88,7 +95,7 @@ public class M3U8LiveUtil extends AbsNormalLoaderUtil {
|
||||
ILiveTsUrlConverter converter = mM3U8Option.getLiveTsUrlConverter();
|
||||
if (converter != null) {
|
||||
if (TextUtils.isEmpty(mM3U8Option.getBandWidthUrl())) {
|
||||
url = converter.convert(((DownloadEntity) getTaskWrapper().getEntity()).getUrl(), url);
|
||||
url = converter.convert(getTaskWrapper().getEntity().getUrl(), url);
|
||||
} else {
|
||||
url = converter.convert(mM3U8Option.getBandWidthUrl(), url);
|
||||
}
|
||||
|
||||
@@ -19,13 +19,15 @@ import android.text.TextUtils;
|
||||
import com.arialyy.aria.core.common.AbsEntity;
|
||||
import com.arialyy.aria.core.common.CompleteInfo;
|
||||
import com.arialyy.aria.core.download.DTaskWrapper;
|
||||
import com.arialyy.aria.core.download.DownloadEntity;
|
||||
import com.arialyy.aria.core.processor.IVodTsUrlConverter;
|
||||
import com.arialyy.aria.core.inf.OnFileInfoCallback;
|
||||
import com.arialyy.aria.core.listener.IEventListener;
|
||||
import com.arialyy.aria.core.loader.AbsLoader;
|
||||
import com.arialyy.aria.core.loader.AbsNormalLoaderUtil;
|
||||
import com.arialyy.aria.core.processor.IVodTsUrlConverter;
|
||||
import com.arialyy.aria.core.wrapper.AbsTaskWrapper;
|
||||
import com.arialyy.aria.exception.BaseException;
|
||||
import com.arialyy.aria.exception.M3U8Exception;
|
||||
import com.arialyy.aria.http.HttpTaskOption;
|
||||
import com.arialyy.aria.m3u8.M3U8InfoThread;
|
||||
import com.arialyy.aria.m3u8.M3U8Listener;
|
||||
import com.arialyy.aria.m3u8.M3U8TaskOption;
|
||||
@@ -43,28 +45,32 @@ import java.util.List;
|
||||
*/
|
||||
public class M3U8VodUtil extends AbsNormalLoaderUtil {
|
||||
|
||||
private M3U8Listener mListener;
|
||||
private List<String> mUrls = new ArrayList<>();
|
||||
private M3U8TaskOption mM3U8Option;
|
||||
|
||||
public M3U8VodUtil(DTaskWrapper wrapper, M3U8Listener listener) {
|
||||
public M3U8VodUtil(AbsTaskWrapper wrapper, IEventListener listener) {
|
||||
super(wrapper, listener);
|
||||
wrapper.generateM3u8Option(M3U8TaskOption.class);
|
||||
mListener = listener;
|
||||
mM3U8Option = (M3U8TaskOption) wrapper.getM3u8Option();
|
||||
}
|
||||
|
||||
@Override public DTaskWrapper getTaskWrapper() {
|
||||
return (DTaskWrapper) super.getTaskWrapper();
|
||||
}
|
||||
|
||||
@Override protected AbsLoader createLoader() {
|
||||
return new M3U8VodLoader((M3U8Listener) getListener(), (DTaskWrapper) getTaskWrapper());
|
||||
getTaskWrapper().generateM3u8Option(M3U8TaskOption.class);
|
||||
getTaskWrapper().generateTaskOption(HttpTaskOption.class);
|
||||
mM3U8Option = (M3U8TaskOption) getTaskWrapper().getM3u8Option();
|
||||
return new M3U8VodLoader((M3U8Listener) getListener(), getTaskWrapper());
|
||||
}
|
||||
|
||||
@Override protected Runnable createInfoThread() {
|
||||
return new M3U8InfoThread((DTaskWrapper) getTaskWrapper(), new OnFileInfoCallback() {
|
||||
return new M3U8InfoThread(getTaskWrapper(), new OnFileInfoCallback() {
|
||||
@Override public void onComplete(String key, CompleteInfo info) {
|
||||
IVodTsUrlConverter converter = mM3U8Option.getVodUrlConverter();
|
||||
if (converter != null) {
|
||||
if (TextUtils.isEmpty(mM3U8Option.getBandWidthUrl())) {
|
||||
mUrls.addAll(converter.convert(getEntity().getUrl(), (List<String>) info.obj));
|
||||
mUrls.addAll(
|
||||
converter.convert(getTaskWrapper().getEntity().getUrl(), (List<String>) info.obj));
|
||||
} else {
|
||||
mUrls.addAll(
|
||||
converter.convert(mM3U8Option.getBandWidthUrl(), (List<String>) info.obj));
|
||||
@@ -81,7 +87,7 @@ public class M3U8VodUtil extends AbsNormalLoaderUtil {
|
||||
}
|
||||
mM3U8Option.setUrls(mUrls);
|
||||
if (isStop()) {
|
||||
getListener().onStop(getEntity().getCurrentProgress());
|
||||
getListener().onStop(getTaskWrapper().getEntity().getCurrentProgress());
|
||||
} else if (isCancel()) {
|
||||
getListener().onCancel();
|
||||
} else {
|
||||
@@ -94,8 +100,4 @@ public class M3U8VodUtil extends AbsNormalLoaderUtil {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private DownloadEntity getEntity() {
|
||||
return (DownloadEntity) getTaskWrapper().getEntity();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user