From f04d8d23bea09b2787dbac7fb806c9beab7ba51f Mon Sep 17 00:00:00 2001 From: xiaji Date: Thu, 28 May 2026 21:34:51 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E8=A7=86=E9=A2=91?= =?UTF-8?q?=E6=92=AD=E6=94=BE=E5=8F=91=E7=83=AD=E9=97=AE=E9=A2=98=20-=20We?= =?UTF-8?q?bView=E6=9A=82=E5=81=9C/=E9=94=80=E6=AF=81=E3=80=81=E4=BA=AE?= =?UTF-8?q?=E5=BA=A6=E6=81=A2=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/videoapp/tv/PlayerActivity.kt | 31 +++++++++++++++---- 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/videoapp/tv/PlayerActivity.kt b/app/src/main/java/com/videoapp/tv/PlayerActivity.kt index bb4113c..c311122 100644 --- a/app/src/main/java/com/videoapp/tv/PlayerActivity.kt +++ b/app/src/main/java/com/videoapp/tv/PlayerActivity.kt @@ -80,6 +80,12 @@ class PlayerActivity : AppCompatActivity() { private var startVolume = 0 private var maxVolume = 0 private val indicatorHideHandler = Handler(Looper.getMainLooper()) + private var savedBrightness = 0f + private val webViewClient = object : WebViewClient() { + override fun onPageFinished(view: WebView, url: String) { + showLoading(false) + } + } override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -104,6 +110,8 @@ class PlayerActivity : AppCompatActivity() { resumePosition = if (intent.hasExtra("resume_position")) intent.getLongExtra("resume_position", 0) else null maxVolume = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC) + savedBrightness = window.attributes.screenBrightness + if (savedBrightness < 0) savedBrightness = -1f btnClose.setOnClickListener { finish() } @@ -324,6 +332,7 @@ class PlayerActivity : AppCompatActivity() { private fun playWithExoPlayer(url: String) { playerWebView.visibility = View.GONE + playerWebView.onPause() playerView.visibility = View.VISIBLE showLoading(false) @@ -345,17 +354,13 @@ class PlayerActivity : AppCompatActivity() { stopPositionSaving() playerView.visibility = View.GONE playerWebView.visibility = View.VISIBLE + playerWebView.onResume() showLoading(false) playerWebView.settings.javaScriptEnabled = true playerWebView.settings.domStorageEnabled = true playerWebView.settings.mediaPlaybackRequiresUserGesture = false - playerWebView.webViewClient = object : WebViewClient() { - override fun onPageFinished(view: WebView, url: String) { - super.onPageFinished(view, url) - showLoading(false) - } - } + playerWebView.webViewClient = webViewClient playerWebView.loadUrl(url) } @@ -465,15 +470,29 @@ class PlayerActivity : AppCompatActivity() { super.onPause() saveCurrentPosition() stopPositionSaving() + playerWebView.onPause() exoPlayer?.playWhenReady = false } + override fun onResume() { + super.onResume() + if (playerWebView.visibility == View.VISIBLE) { + playerWebView.onResume() + } + } + override fun onDestroy() { super.onDestroy() saveCurrentPosition() stopPositionSaving() hideHandler.removeCallbacks(hideRunnable) + indicatorHideHandler.removeCallbacksAndMessages(null) + if (savedBrightness >= 0) { + window.attributes.screenBrightness = savedBrightness + } exoPlayer?.release() exoPlayer = null + playerWebView.stopLoading() + playerWebView.destroy() } }