Skip to content

Commit

Permalink
[bugfix] 1.修复下载任务内存泄漏 2.修复快进时概率 oom
Browse files Browse the repository at this point in the history
  • Loading branch information
heyanLE committed Jul 22, 2024
1 parent cdb3134 commit 7482d71
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import kotlinx.coroutines.launch
import kotlinx.coroutines.yield
import loli.ball.easyplayer2.texture.TexturePlayerRender
import java.io.File
import java.util.concurrent.atomic.AtomicBoolean

/**
* Created by heyanle on 2023/12/17.
Expand Down Expand Up @@ -459,6 +460,8 @@ class CartoonPlayingViewModel(

// surfaceTexture 回调 ==============================================

private var lastThumbnailTime = 0L

override fun onSurfaceTextureAvailable(surface: SurfaceTexture, width: Int, height: Int) {

}
Expand All @@ -479,13 +482,18 @@ class CartoonPlayingViewModel(
scope.launch {
//"onSurfaceTextureUpdated 2".logi(TAG)
val currentPosition = exoPlayer.currentPosition
// 如果该进度前后五秒都没有缩略图就保存一张
// 如果该进度前后两秒都没有缩略图就保存一张
val currentFile = thumbnailBuffer?.getThumbnail(currentPosition, 2000)
if (currentFile == null) {
val current = System.currentTimeMillis()

// 频次控制
if (currentFile == null && current - lastThumbnailTime > 2000) {
lastThumbnailTime = current
//"onSurfaceTextureUpdated 3".logi(TAG)
// 保存缩略图
thumbnailJob?.cancel()
thumbnailJob = singleScope.launch {
yield()
val textureView = easyTextRenderer.getTextureViewOrNull() ?: return@launch
val bmp = textureView.bitmap ?: return@launch
thumbnailFolder.mkdirs()
Expand All @@ -497,8 +505,8 @@ class CartoonPlayingViewModel(
bmp.compress(Bitmap.CompressFormat.JPEG, 10, it)
}
//"onSurfaceTextureUpdated 4".logi(TAG)
yield()
thumbnailBuffer?.addThumbnail(currentPosition, file)
bmp.recycle()
}

}
Expand Down
13 changes: 13 additions & 0 deletions easy-i18n/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,7 @@
<string name="quality">图片质量(1–100)</string>
<string name="quality_error">质量输入错误 [1,100]</string>

<string name="save_media">保存到相册</string>

<string name="save_gif">保存 gif</string>
<string name="save_video">保存视频</string>
Expand Down Expand Up @@ -572,4 +573,16 @@

<string name="donate_do">我已捐赠</string>

<string name="download_decode_type">下载番剧编码方式</string>

<string name="local_no_media">本地文件夹添加&#160;.nomedia&#160;文件</string>
<string name="local_no_media_msg">.nomedia&#160;文件代表你不希望本地番剧出现在相册。具体表现因设备而异,无法控制。</string>

<string name="private_path_msg">私有目录中的文件无法保存到相册,只能在纯纯看番中查看,卸载后将同步删除。</string>

<string name="downloading_max_count">最大同时下载数量</string>



<string name="save_to_media_ready">是否要保存%1$s个视频到相册?</string>
</resources>

0 comments on commit 7482d71

Please sign in to comment.