diff --git a/Aria/src/main/java/com/arialyy/aria/core/common/ftp/IFtpUploadInterceptor.java b/Aria/src/main/java/com/arialyy/aria/core/common/ftp/IFtpUploadInterceptor.java index 0248f22b..e61c070c 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/common/ftp/IFtpUploadInterceptor.java +++ b/Aria/src/main/java/com/arialyy/aria/core/common/ftp/IFtpUploadInterceptor.java @@ -41,7 +41,7 @@ import java.util.List; * * */ -public interface IFtpUploadInterceptor { +public class IFtpUploadInterceptor { /** * 处理拦截事件 @@ -49,5 +49,7 @@ public interface IFtpUploadInterceptor { * @param entity 上传信息实体 * @param fileList ftp服务器端remotePath下的文件列表 */ - FtpInterceptHandler onIntercept(UploadEntity entity, List fileList); + public FtpInterceptHandler onIntercept(UploadEntity entity, List fileList) { + return null; + } } diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/DNormalConfigHandler.java b/Aria/src/main/java/com/arialyy/aria/core/download/DNormalConfigHandler.java index be920abc..02e70d93 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/DNormalConfigHandler.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/DNormalConfigHandler.java @@ -118,7 +118,8 @@ class DNormalConfigHandler implements IConfigHandler wrapper.asM3U8().getBandWidth())); if (wrapper.getRequestType() == ITaskWrapper.M3U8_VOD) { if (mEntity.getFileSize() == 0) { - ALog.w(TAG, "由于m3u8协议的特殊性质,无法获取到正确到文件长度,因此你需要自行设置文件大小:asM3U8().setFileSize(xxx)"); + ALog.w(TAG, + "由于m3u8协议的特殊性质,无法有效快速获取到正确到文件长度,如果你需要显示文件中长度,你需要自行设置文件长度:.asM3U8().asVod().setFileSize(xxx)"); } } else if (wrapper.getRequestType() == ITaskWrapper.M3U8_LIVE) { if (file.exists()) { diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadEntity.java b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadEntity.java index 81445007..fe1a1696 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadEntity.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadEntity.java @@ -19,9 +19,13 @@ package com.arialyy.aria.core.download; import android.os.Parcel; import android.os.Parcelable; import android.text.TextUtils; +import com.arialyy.aria.core.download.m3u8.M3U8Entity; import com.arialyy.aria.core.inf.AbsNormalEntity; import com.arialyy.aria.core.inf.AbsTaskWrapper; +import com.arialyy.aria.orm.DbEntity; +import com.arialyy.aria.orm.annotation.Ignore; import com.arialyy.aria.orm.annotation.Unique; +import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.CommonUtil; /** @@ -52,6 +56,27 @@ public class DownloadEntity extends AbsNormalEntity implements Parcelable { */ private String serverFileName; + @Ignore + private M3U8Entity m3U8Entity; + + public M3U8Entity getM3U8Entity() { + if (TextUtils.isEmpty(downloadPath)) { + ALog.e("DownloadEntity", "文件保存路径为空,获取m3u8实体之前需要设置文件保存路径"); + return null; + } + if (m3U8Entity == null) { + m3U8Entity = DbEntity.findFirst(M3U8Entity.class, "filePath=?", downloadPath); + } + if (m3U8Entity == null) { + m3U8Entity = new M3U8Entity(); + m3U8Entity.setFilePath(downloadPath); + m3U8Entity.setPeerIndex(0); + m3U8Entity.insert(); + } + + return m3U8Entity; + } + @Override public String getKey() { return getUrl(); } @@ -124,19 +149,6 @@ public class DownloadEntity extends AbsNormalEntity implements Parcelable { return (DownloadEntity) super.clone(); } - @Override public int describeContents() { - return 0; - } - - @Override public void writeToParcel(Parcel dest, int flags) { - super.writeToParcel(dest, flags); - dest.writeString(this.downloadPath); - dest.writeString(this.groupHash); - dest.writeString(this.md5Code); - dest.writeString(this.disposition); - dest.writeString(this.serverFileName); - } - @Override public String toString() { return "DownloadEntity{" + "downloadPath='" @@ -160,6 +172,20 @@ public class DownloadEntity extends AbsNormalEntity implements Parcelable { + '}'; } + @Override public int describeContents() { + return 0; + } + + @Override public void writeToParcel(Parcel dest, int flags) { + super.writeToParcel(dest, flags); + dest.writeString(this.downloadPath); + dest.writeString(this.groupHash); + dest.writeString(this.md5Code); + dest.writeString(this.disposition); + dest.writeString(this.serverFileName); + dest.writeParcelable(this.m3U8Entity, flags); + } + protected DownloadEntity(Parcel in) { super(in); this.downloadPath = in.readString(); @@ -167,6 +193,7 @@ public class DownloadEntity extends AbsNormalEntity implements Parcelable { this.md5Code = in.readString(); this.disposition = in.readString(); this.serverFileName = in.readString(); + this.m3U8Entity = in.readParcelable(M3U8Entity.class.getClassLoader()); } public static final Creator CREATOR = new Creator() { diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpFileInfoThread.java b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpFileInfoThread.java index 65846191..0c410b30 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpFileInfoThread.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpFileInfoThread.java @@ -90,11 +90,6 @@ public class HttpFileInfoThread implements Runnable { if (conn != null) { conn.disconnect(); } - // 销毁文件长度适配器 - IHttpFileLenAdapter lenAdapter = mTaskWrapper.asHttp().getFileLenAdapter(); - if (lenAdapter != null && lenAdapter.getClass().isAnonymousClass()) { - mTaskWrapper.asHttp().setFileLenAdapter(null); - } } } @@ -336,7 +331,7 @@ public class HttpFileInfoThread implements Runnable { } } - private static class FileLenAdapter implements IHttpFileLenAdapter { + private static class FileLenAdapter extends IHttpFileLenAdapter { @Override public long handleFileLen(Map> headers) { List sLength = headers.get("Content-Length"); diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/IBandWidthUrlConverter.java b/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/IBandWidthUrlConverter.java index ffbde948..7ea2c6c0 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/IBandWidthUrlConverter.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/IBandWidthUrlConverter.java @@ -19,7 +19,7 @@ package com.arialyy.aria.core.download.m3u8; * M3U8 bandWidth 码率url转换器,对于某些服务器,返回的ts地址可以是相对地址,也可能是处理过的, * 对于这种情况,你需要使用url转换器将地址转换为可正常访问的http地址 */ -public interface IBandWidthUrlConverter { +public class IBandWidthUrlConverter { /** * 转换码率地址为可用的http地址,对于某些服务器,返回的切片信息有可能是相对地址,也可能是处理过的, @@ -28,5 +28,7 @@ public interface IBandWidthUrlConverter { * @param bandWidthUrl 原始码率地址 * @return 可正常访问的http地址 */ - String convert(String bandWidthUrl); + public String convert(String bandWidthUrl) { + return null; + } } diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/ILiveTsUrlConverter.java b/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/ILiveTsUrlConverter.java index 9618794b..bc381b8b 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/ILiveTsUrlConverter.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/ILiveTsUrlConverter.java @@ -19,7 +19,7 @@ package com.arialyy.aria.core.download.m3u8; * M3U8 直播下载,ts url转换器,对于某些服务器,返回的ts地址可以是相对地址,也可能是处理过的 * 对于这种情况,你需要使用url转换器将地址转换为可正常访问的http地址 */ -public interface ILiveTsUrlConverter { +public class ILiveTsUrlConverter { /** * 处理#EXTINF信息,对于某些服务器,返回的切片信息有可能是相对地址,因此,你需要自行转换为可下载http连接 @@ -28,5 +28,7 @@ public interface ILiveTsUrlConverter { * @param tsUrl ts文件下载地址 * @return 转换后的http地址 */ - String convert(String m3u8Url, String tsUrl); + public String convert(String m3u8Url, String tsUrl) { + return null; + } } diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/ITsMergeHandler.java b/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/ITsMergeHandler.java index cfc5633b..56a3a996 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/ITsMergeHandler.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/ITsMergeHandler.java @@ -21,7 +21,7 @@ import java.util.List; /** * Ts文件合并处理,如果你希望使用自行处理ts文件的合并,你可以实现该接口 */ -public interface ITsMergeHandler { +public class ITsMergeHandler { /** * 合并ts文件 @@ -30,5 +30,7 @@ public interface ITsMergeHandler { * @param tsPath ts文件列表 * @return {@code true} 合并成功 */ - boolean merge(@Nullable M3U8KeyInfo keyInfo, List tsPath); + public boolean merge(@Nullable M3U8KeyInfo keyInfo, List tsPath) { + return false; + } } diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/IVodTsUrlConverter.java b/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/IVodTsUrlConverter.java index 2ccfc7a6..fcf47142 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/IVodTsUrlConverter.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/IVodTsUrlConverter.java @@ -21,7 +21,7 @@ import java.util.List; * M3U8 点播文件下载,ts url转换器,对于某些服务器,返回的ts地址可以是相对地址,也可能是处理过的 * 对于这种情况,你需要使用url转换器将地址转换为可正常访问的http地址 */ -public interface IVodTsUrlConverter { +public class IVodTsUrlConverter { /** * 处理#EXTINF信息,对于某些服务器,返回的切片信息有可能是相对地址,因此,你需要自行转换为可下载http连接 @@ -30,5 +30,7 @@ public interface IVodTsUrlConverter { * @param tsUrls ts文件下载地址列表 * @return 根据切片信息转换后的http连接列表,如果你的切片信息是可以直接下载的http连接,直接返回extInf便可 */ - List convert(String m3u8Url, List tsUrls); + public List convert(String m3u8Url, List tsUrls) { + return null; + } } diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8Delegate.java b/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8Delegate.java index ce930251..5192ab02 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8Delegate.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8Delegate.java @@ -52,20 +52,6 @@ public class M3U8Delegate extends BaseDelegate return this; } - /** - * 由于m3u8协议的特殊性质,无法获取到正确到文件长度,因此你需要自行设置文件大小 - * - * @param fileSize 文件长度 - */ - public M3U8Delegate setFileSize(long fileSize) { - if (fileSize <= 0) { - ALog.e(TAG, "文件长度错误"); - return this; - } - mTaskWrapper.getEntity().setFileSize(fileSize); - return this; - } - /** * M3U8 ts 文件url转换器,对于某些服务器,返回的ts地址可以是相对地址,也可能是处理过的 * 对于这种情况,你需要使用url转换器将地址转换为可正常访问的http地址 @@ -98,6 +84,13 @@ public class M3U8Delegate extends BaseDelegate return this; } + /** + * 处理点播文件的下载参数 + */ + public M3U8VodDelegate asVod() { + return new M3U8VodDelegate<>(mTarget); + } + /** * 处理直播类的下载 */ diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8Entity.java b/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8Entity.java new file mode 100644 index 00000000..339c7102 --- /dev/null +++ b/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8Entity.java @@ -0,0 +1,109 @@ +/* + * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.arialyy.aria.core.download.m3u8; + +import android.os.Parcel; +import android.os.Parcelable; +import com.arialyy.aria.orm.DbEntity; + +/** + * M3U8实体信息 + */ +public class M3U8Entity extends DbEntity implements Parcelable { + + /** + * 文件保存路径 + */ + private String filePath; + + /** + * 当前peer的位置 + */ + private int peerIndex; + + /** + * peer总数 + */ + private int peerNum; + + /** + * 是否是直播,true 直播 + */ + private boolean isLive; + + public boolean isLive() { + return isLive; + } + + public void setLive(boolean live) { + isLive = live; + } + + public String getFilePath() { + return filePath; + } + + public void setFilePath(String filePath) { + this.filePath = filePath; + } + + public int getPeerIndex() { + return peerIndex; + } + + public void setPeerIndex(int peerIndex) { + this.peerIndex = peerIndex; + } + + public int getPeerNum() { + return peerNum; + } + + public void setPeerNum(int peerNum) { + this.peerNum = peerNum; + } + + public M3U8Entity() { + } + + @Override public int describeContents() { + return 0; + } + + @Override public void writeToParcel(Parcel dest, int flags) { + dest.writeString(this.filePath); + dest.writeInt(this.peerIndex); + dest.writeInt(this.peerNum); + dest.writeByte(this.isLive ? (byte) 1 : (byte) 0); + } + + protected M3U8Entity(Parcel in) { + this.filePath = in.readString(); + this.peerIndex = in.readInt(); + this.peerNum = in.readInt(); + this.isLive = in.readByte() != 0; + } + + public static final Creator CREATOR = new Creator() { + @Override public M3U8Entity createFromParcel(Parcel source) { + return new M3U8Entity(source); + } + + @Override public M3U8Entity[] newArray(int size) { + return new M3U8Entity[size]; + } + }; +} diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8InfoThread.java b/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8InfoThread.java index d254381d..c2731639 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8InfoThread.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8InfoThread.java @@ -25,6 +25,7 @@ import com.arialyy.aria.core.common.http.HttpTaskConfig; import com.arialyy.aria.core.download.DTaskWrapper; import com.arialyy.aria.core.download.DownloadEntity; import com.arialyy.aria.core.download.downloader.ConnectionHelp; +import com.arialyy.aria.core.inf.AbsTaskWrapper; import com.arialyy.aria.core.inf.ITaskWrapper; import com.arialyy.aria.exception.M3U8Exception; import com.arialyy.aria.exception.TaskException; @@ -75,6 +76,7 @@ final class M3U8InfoThread implements Runnable { AriaManager.getInstance(AriaManager.APP).getDownloadConfig().getConnectTimeOut(); onFileInfoCallback = callback; mTaskDelegate = taskWrapper.asHttp(); + mEntity.getM3U8Entity().setLive(mTaskWrapper.getRequestType() == AbsTaskWrapper.M3U8_LIVE); } @Override public void run() { @@ -109,7 +111,7 @@ final class M3U8InfoThread implements Runnable { List extInf = new ArrayList<>(); boolean isLive = mTaskWrapper.getRequestType() == ITaskWrapper.M3U8_LIVE; while ((line = reader.readLine()) != null) { - if (isStop){ + if (isStop) { break; } if (line.startsWith("#EXT-X-ENDLIST")) { @@ -145,6 +147,10 @@ final class M3U8InfoThread implements Runnable { failDownload(String.format("获取M3U8下载地址列表失败,url: %s", mEntity.getUrl()), false); return; } + if (!isLive && mEntity.getM3U8Entity().getPeerNum() != 0) { + mEntity.getM3U8Entity().setPeerNum(extInf.size()); + mEntity.getM3U8Entity().update(); + } CompleteInfo info = new CompleteInfo(); info.obj = extInf; onFileInfoCallback.onComplete(mEntity.getKey(), info); @@ -247,9 +253,6 @@ final class M3U8InfoThread implements Runnable { IBandWidthUrlConverter converter = mTaskWrapper.asM3U8().getBandWidthUrlConverter(); if (converter != null) { bandWidthM3u8Url = converter.convert(bandWidthM3u8Url); - if (converter.getClass().isAnonymousClass()) { - mTaskWrapper.asM3U8().setBandWidthUrlConverter(null); - } if (!bandWidthM3u8Url.startsWith("http")) { failDownload(String.format("码率转换器转换后的url地址无效,转换后的url:%s", bandWidthM3u8Url), false); return; diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8LiveLoader.java b/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8LiveLoader.java index f265e660..b29e3b84 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8LiveLoader.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8LiveLoader.java @@ -173,9 +173,6 @@ public class M3U8LiveLoader extends BaseM3U8Loader { boolean isSuccess; if (mergeHandler != null) { isSuccess = mergeHandler.merge(mTaskWrapper.asM3U8().getKeyInfo(), partPath); - if (mergeHandler.getClass().isAnonymousClass()) { - mTaskWrapper.asM3U8().setMergeHandler(null); - } } else { isSuccess = FileUtil.mergeFile(mEntity.getFilePath(), partPath); } diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8LiveUtil.java b/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8LiveUtil.java index 49a1f1b0..e1bc5f20 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8LiveUtil.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8LiveUtil.java @@ -101,10 +101,6 @@ public class M3U8LiveUtil implements IUtil { mListener.onFail(false, new M3U8Exception(TAG, "合并文件失败")); } } - ILiveTsUrlConverter converter = mWrapper.asM3U8().getLiveTsUrlConverter(); - if (converter != null && converter.getClass().isAnonymousClass()) { - mWrapper.asM3U8().setLiveTsUrlConverter(null); - } } @Override public void start() { diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8TaskConfig.java b/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8TaskConfig.java index b2f79b9e..50352a86 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8TaskConfig.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8TaskConfig.java @@ -87,6 +87,19 @@ public class M3U8TaskConfig { */ private long liveUpdateInterval = 10 * 1000; + /** + * 同时下载的分片数量 + */ + private int maxTsQueueNum = 4; + + public int getMaxTsQueueNum() { + return maxTsQueueNum; + } + + public void setMaxTsQueueNum(int maxTsQueueNum) { + this.maxTsQueueNum = maxTsQueueNum; + } + public long getLiveUpdateInterval() { return liveUpdateInterval; } diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8VodDelegate.java b/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8VodDelegate.java new file mode 100644 index 00000000..8c68c44c --- /dev/null +++ b/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8VodDelegate.java @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.arialyy.aria.core.download.m3u8; + +import com.arialyy.aria.core.common.BaseDelegate; +import com.arialyy.aria.core.download.DTaskWrapper; +import com.arialyy.aria.core.inf.AbsTarget; +import com.arialyy.aria.core.inf.AbsTaskWrapper; +import com.arialyy.aria.util.ALog; + +/** + * m3u8点播文件参数设置 + */ +public class M3U8VodDelegate extends BaseDelegate { + private DTaskWrapper mTaskWrapper; + + M3U8VodDelegate(TARGET target) { + super(target); + mTaskWrapper = (DTaskWrapper) mTarget.getTaskWrapper(); + mTaskWrapper.setRequestType(AbsTaskWrapper.M3U8_VOD); + } + + /** + * 由于m3u8协议的特殊性质,无法有效快速获取到正确到文件长度,如果你需要显示文件中长度,你需要自行设置文件长度 + * + * @param fileSize 文件长度 + */ + public M3U8VodDelegate setFileSize(long fileSize) { + if (fileSize <= 0) { + ALog.e(TAG, "文件长度错误"); + return this; + } + mTaskWrapper.getEntity().setFileSize(fileSize); + return this; + } + + /** + * 默认情况下,对于同一点播文件的下载,最多同时下载4个ts分片,如果你希望增加或减少同时下载的ts分片数量,可以使用该方法设置同时下载的ts分片数量 + * + * @param num 同时下载的ts分片数量 + */ + public M3U8VodDelegate setMaxTsQueueNum(int num) { + if (num < 1) { + ALog.e(TAG, "同时下载的分片数量不能小于1"); + return this; + } + mTaskWrapper.asM3U8().setMaxTsQueueNum(num); + return this; + } +} diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8VodLoader.java b/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8VodLoader.java index e0b882ed..4e73474a 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8VodLoader.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8VodLoader.java @@ -48,13 +48,14 @@ public class M3U8VodLoader extends BaseM3U8Loader { */ private static final int EXEC_MAX_NUM = 4; private Handler mStateHandler; - private ArrayBlockingQueue mFlagQueue = new ArrayBlockingQueue<>(EXEC_MAX_NUM); + private ArrayBlockingQueue mFlagQueue; private VodStateManager mManager; private ReentrantLock LOCK = new ReentrantLock(); private Condition mCondition = LOCK.newCondition(); M3U8VodLoader(IEventListener listener, DTaskWrapper wrapper) { super(listener, wrapper); + mFlagQueue = new ArrayBlockingQueue<>(wrapper.asM3U8().getMaxTsQueueNum()); } @Override protected IThreadState getStateManager(Looper looper) { @@ -84,7 +85,8 @@ public class M3U8VodLoader extends BaseM3U8Loader { M3U8ThreadTask task = createThreadTask(cacheDir, tr); getTaskList().put(tr.threadId, task); - mFlagQueue.offer(startThreadTask(task)); + mEntity.getM3U8Entity().setPeerIndex(index); + mFlagQueue.offer(startThreadTask(task, index)); } if (mFlagQueue.size() > 0) { mCondition.await(); @@ -122,9 +124,9 @@ public class M3U8VodLoader extends BaseM3U8Loader { * * @return 线程唯一id标志 */ - private long startThreadTask(M3U8ThreadTask task) { + private long startThreadTask(M3U8ThreadTask task, int peerIndex) { ThreadTaskManager.getInstance().startThread(mTaskWrapper.getKey(), task); - return IdGenerator.getInstance().nextId(); + return peerIndex; } /** @@ -304,9 +306,6 @@ public class M3U8VodLoader extends BaseM3U8Loader { boolean isSuccess; if (mergeHandler != null) { isSuccess = mergeHandler.merge(mTaskWrapper.asM3U8().getKeyInfo(), partPath); - if (mergeHandler.getClass().isAnonymousClass()) { - mTaskWrapper.asM3U8().setMergeHandler(null); - } } else { isSuccess = FileUtil.mergeFile(mTaskRecord.filePath, partPath); } diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8VodUtil.java b/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8VodUtil.java index 3eb8b498..edca7953 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8VodUtil.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/m3u8/M3U8VodUtil.java @@ -103,9 +103,6 @@ public class M3U8VodUtil implements IUtil { mUrls.addAll( converter.convert(mWrapper.asM3U8().getBandWidthUrl(), (List) info.obj)); } - if (converter.getClass().isAnonymousClass()) { - mWrapper.asM3U8().setVodUrlConverter(null); - } } else { mUrls.addAll((Collection) info.obj); } diff --git a/Aria/src/main/java/com/arialyy/aria/core/inf/IHttpFileLenAdapter.java b/Aria/src/main/java/com/arialyy/aria/core/inf/IHttpFileLenAdapter.java index 55b8c507..48202fd3 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/inf/IHttpFileLenAdapter.java +++ b/Aria/src/main/java/com/arialyy/aria/core/inf/IHttpFileLenAdapter.java @@ -23,7 +23,7 @@ import java.util.Map; /** * Http文件长度适配器 */ -public interface IHttpFileLenAdapter extends Serializable { +public class IHttpFileLenAdapter implements Serializable { long serialVersionUID = 1L; /** @@ -32,5 +32,7 @@ public interface IHttpFileLenAdapter extends Serializable { * @param headers header参数{@link URLConnection#getHeaderFields()} * @return 文件长度 */ - long handleFileLen(Map> headers); + public long handleFileLen(Map> headers) { + return 0; + } } diff --git a/Aria/src/main/java/com/arialyy/aria/core/upload/uploader/FtpFileInfoThread.java b/Aria/src/main/java/com/arialyy/aria/core/upload/uploader/FtpFileInfoThread.java index 06c7f3cc..fbe55682 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/upload/uploader/FtpFileInfoThread.java +++ b/Aria/src/main/java/com/arialyy/aria/core/upload/uploader/FtpFileInfoThread.java @@ -102,11 +102,6 @@ class FtpFileInfoThread extends AbsFtpInfoThread { } catch (IOException e) { e.printStackTrace(); return false; - } finally { - IFtpUploadInterceptor interceptor = mTaskWrapper.asFtp().getUploadInterceptor(); - if (interceptor != null && interceptor.getClass().isAnonymousClass()) { - mTaskWrapper.asFtp().setUploadInterceptor(null); - } } return true; diff --git a/Aria/src/main/java/com/arialyy/aria/orm/DBConfig.java b/Aria/src/main/java/com/arialyy/aria/orm/DBConfig.java index eead24ba..3b22df9f 100644 --- a/Aria/src/main/java/com/arialyy/aria/orm/DBConfig.java +++ b/Aria/src/main/java/com/arialyy/aria/orm/DBConfig.java @@ -37,7 +37,7 @@ class DBConfig { static boolean DEBUG = false; static Map mapping = new LinkedHashMap<>(); static String DB_NAME; - static int VERSION = 48; + static int VERSION = 49; /** * 是否将数据库保存在Sd卡,{@code true} 是 diff --git a/Aria/src/main/java/com/arialyy/aria/orm/SqlHelper.java b/Aria/src/main/java/com/arialyy/aria/orm/SqlHelper.java index e8358158..29c6bd27 100644 --- a/Aria/src/main/java/com/arialyy/aria/orm/SqlHelper.java +++ b/Aria/src/main/java/com/arialyy/aria/orm/SqlHelper.java @@ -98,7 +98,7 @@ final class SqlHelper extends SQLiteOpenHelper { handle314AriaUpdate(db); } else if (oldVersion < 45) { handle360AriaUpdate(db); - } else if (oldVersion < 48) { + } else if (oldVersion < 49) { handle365Update(db); } else { handleDbUpdate(db, null, null); diff --git a/build.gradle b/build.gradle index e9b72b95..d5b6dfac 100644 --- a/build.gradle +++ b/build.gradle @@ -43,7 +43,7 @@ task clean(type: Delete) { ext { userOrg = 'arialyy' groupId = 'com.arialyy.aria' - publishVersion = '3.6.5_beta_1' + publishVersion = '3.6.5_beta_2' // publishVersion = '1.0.4' //FTP插件 repoName='maven' desc = 'android 下载框架'