1:优化礼物播放和下载方式
This commit is contained in:
@@ -361,18 +361,21 @@ public class AvatarFrameView extends FrameLayout implements IAnimListener {
|
|||||||
String filePath = PathUtils.getInternalAppCachePath() + Md5Utils.getStringMD5(url) + ".mp4";
|
String filePath = PathUtils.getInternalAppCachePath() + Md5Utils.getStringMD5(url) + ".mp4";
|
||||||
File file = new File(filePath);
|
File file = new File(filePath);
|
||||||
|
|
||||||
if (file.exists()) {
|
if (file.exists() && file.length() > 0) {
|
||||||
playMp4(file);
|
playMp4(file);
|
||||||
mFile = file;
|
mFile = file;
|
||||||
} else {
|
} else {
|
||||||
|
// 删除可能存在的损坏文件
|
||||||
|
if (file.exists()) {
|
||||||
|
file.delete();
|
||||||
|
}
|
||||||
DownloadTask task = new DownloadTask.Builder(url, PathUtils.getInternalAppCachePath()
|
DownloadTask task = new DownloadTask.Builder(url, PathUtils.getInternalAppCachePath()
|
||||||
, Md5Utils.getStringMD5(url) + ".mp4")
|
, Md5Utils.getStringMD5(url) + ".mp4")
|
||||||
.setMinIntervalMillisCallbackProcess(1000)
|
.setMinIntervalMillisCallbackProcess(300)
|
||||||
.setPassIfAlreadyCompleted(true)
|
.setPassIfAlreadyCompleted(true)
|
||||||
.setAutoCallbackToUIThread(true)
|
.setAutoCallbackToUIThread(true)
|
||||||
|
.setConnectionCount(3) // 增加连接数提高稳定性
|
||||||
// 添加以下优化配置
|
.setReadBufferSize(1024 * 8) // 增大缓冲区
|
||||||
.setConnectionCount(1) // 对于大文件,减少连接数可能更稳定
|
|
||||||
.build();
|
.build();
|
||||||
if (StatusUtil.isCompleted(task)) {
|
if (StatusUtil.isCompleted(task)) {
|
||||||
playMp4(task.getFile());
|
playMp4(task.getFile());
|
||||||
@@ -391,9 +394,7 @@ public class AvatarFrameView extends FrameLayout implements IAnimListener {
|
|||||||
@Override
|
@Override
|
||||||
public void retry(@NonNull DownloadTask task, @NonNull ResumeFailedCause cause) {
|
public void retry(@NonNull DownloadTask task, @NonNull ResumeFailedCause cause) {
|
||||||
Logger.e("AvatarFrameView2", cause);
|
Logger.e("AvatarFrameView2", cause);
|
||||||
task.cancel();
|
|
||||||
|
|
||||||
// CrashReport.postCatchedException(new RuntimeException("下载文件重试:" + cause == null ? "" : cause.name()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user