使用
videos。
glide
。。
待在openSearch中显示内容详细信息。
。但是,在运行应用程序几个小时后,内存使用情况不断增加。探测仪显示没有内存泄漏(0 leaks
本期可能与本机内存分配(例如,位图,文件手柄)而不是Java Heap内存有关?
任何指导或有关如何调试和解决此问题的建议或建议将不胜感激! @SuppressLint("SetTextI18n", "SetJavaScriptEnabled")
@OptIn(UnstableApi::class)
fun startLoop() {
// If this partition has video content initially, set up ExoPlayer and attach PlayerView
if (hasVideoInitially) {
val loadControl = DefaultLoadControl.Builder()
.setBufferDurationsMs(
2000, 2000, 1000, 2000
)
.build()
val renderersFactory = DefaultRenderersFactory(context)
.setEnableDecoderFallback(true)
exoPlayer =
ExoPlayer.Builder(context, renderersFactory)
.setLoadControl(loadControl)
.build()
playerView = PlayerView(context).apply {
useController = false
setShutterBackgroundColor(Color.TRANSPARENT)
layoutParams = FrameLayout.LayoutParams(
FrameLayout.LayoutParams.MATCH_PARENT,
FrameLayout.LayoutParams.MATCH_PARENT
)
}
playerView?.player = exoPlayer
partitionContainer.addView(playerView)
}
// Create an ImageView for images/PDF
imageView = ImageView(context).apply {
layoutParams = FrameLayout.LayoutParams(
FrameLayout.LayoutParams.MATCH_PARENT,
FrameLayout.LayoutParams.MATCH_PARENT
)
scaleType = ImageView.ScaleType.FIT_XY
visibility = GONE
}
partitionContainer.addView(imageView)
// Create a WebView for HTML content
webView = WebView(context).apply {
layoutParams = FrameLayout.LayoutParams(
FrameLayout.LayoutParams.MATCH_PARENT,
FrameLayout.LayoutParams.MATCH_PARENT
)
visibility = GONE
settings.javaScriptEnabled = true
settings.domStorageEnabled = true
settings.cacheMode = WebSettings.LOAD_NO_CACHE
settings.mixedContentMode = WebSettings.MIXED_CONTENT_ALWAYS_ALLOW
WebView.setWebContentsDebuggingEnabled(true)
}
partitionContainer.addView(webView)
// Create a "No Content" TextView but hide it initially
noContentTextView = TextView(context).apply {
text = "No content to play."
textSize = 18f
setTextColor(Color.CYAN)
gravity = Gravity.CENTER
visibility = GONE
}
partitionContainer.addView(noContentTextView)
// Kick off the main loop
scope.launch {
while (isActive) {
try {
// Take a "snapshot" of the current contents under the lock
val snapshot = contentLock.withLock { contentList }
if (snapshot.isEmpty()) {
// If we've *never* played content before, it means we're just waiting for content
// so do nothing special. If we have played content before, show "No content."
if (hasEverPlayedContent) {
// Show the "No content" message
noContentTextView?.visibility = VISIBLE
noContentTextView?.bringToFront()
}
delay(2000)
} else if (snapshot.size == 1 && snapshot[0].contentType.lowercase(Locale.ROOT) == "widget") {
// Display the widget once
displayWidgetIndefinitely(snapshot[0])
// Then break out of the while loop or block the loop.
break
} else {
// Hide "No content" message if it was visible
noContentTextView?.visibility = GONE
// Loop over the snapshot
for (item in snapshot) {
if (!isActive) break // If our scope got canceled mid-loop
if (!hasFiredFirstContentPlayed) {
hasFiredFirstContentPlayed = true
onFirstContentPlayed?.onFirstContentPlayed()
}
hasEverPlayedContent = true
displayContent(item)
}
}
} catch (e: Exception) {
FirebaseCrashlytics.getInstance().recordException(e)
}
}
}
}
well,仅查看partitionContainer
addView
,
JVM无法回收对象。
removeView
,您是否拨打了exoplayer.release()和webview.destory(),nath callremoveView
??