From 39c0c65c925b3731867bbc2d5ae6379891963a1f Mon Sep 17 00:00:00 2001 From: Hermes Agent Date: Thu, 8 Oct 2026 14:01:59 +0800 Subject: [PATCH] =?UTF-8?q?v9.2.0=20=E4=BB=8E=E8=AE=BE=E7=BD=AE/=E6=A1=8C?= =?UTF-8?q?=E9=9D=A2=E8=BF=94=E5=9B=9E=E7=9B=B4=E6=8E=A5=E9=87=8D=E8=BF=9E?= =?UTF-8?q?=E5=BD=93=E5=89=8D=E6=B5=81=EF=BC=88=E4=B8=8D=E5=86=8D=E4=BE=9D?= =?UTF-8?q?=E8=B5=96play=EF=BC=8C=E9=81=BF=E5=85=8D=E5=AE=9A=E6=A0=BC?= =?UTF-8?q?=EF=BC=89=EF=BC=9B=E7=BB=A7=E7=BB=AD=E6=92=AD=E6=94=BE=E6=8C=89?= =?UTF-8?q?=E9=92=AE=E5=BC=BA=E5=88=B6=E9=87=8D=E8=BF=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle.kts | 4 +- .../main/java/com/iptv807/tv/MainActivity.kt | 40 ++++++++++++++----- 2 files changed, 31 insertions(+), 13 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index d3c8f75..5bb0b6c 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -11,8 +11,8 @@ android { applicationId = "com.iptv807.tv" minSdk = 21 targetSdk = 35 - versionCode = 910 - versionName = "9.1.0" + versionCode = 920 + versionName = "9.2.0" } buildTypes { diff --git a/app/src/main/java/com/iptv807/tv/MainActivity.kt b/app/src/main/java/com/iptv807/tv/MainActivity.kt index 0c4e2c2..a3491d5 100644 --- a/app/src/main/java/com/iptv807/tv/MainActivity.kt +++ b/app/src/main/java/com/iptv807/tv/MainActivity.kt @@ -86,6 +86,7 @@ class MainActivity : Activity() { private var triedFresh = false /** true=当前这次"新开播"还没真正开始(避免旧频道的播放回调把加载提示提前隐藏) */ private var awaitingStart = false + private var lastPlayedUrl: String? = null private var failureReport = "" private var wasStopped = false private var resumeBtn: TextView? = null @@ -586,6 +587,7 @@ class MainActivity : Activity() { .setMimeType(if (isFlv) MimeTypes.VIDEO_FLV else MimeTypes.APPLICATION_M3U8) .build() awaitingStart = true + lastPlayedUrl = url player?.setMediaItem(item) player?.prepare() player?.playWhenReady = true @@ -897,12 +899,24 @@ class MainActivity : Activity() { // 从桌面/设置返回:先尝试续播,失败则显示「继续播放」按钮 if (wasStopped) { wasStopped = false - try { player?.play() } catch (e: Exception) { } - handler.postDelayed({ - // 直播流暂停后常常定格无法续播 → 给用户一个明确的按钮 - if (player?.isPlaying != true) resumeBtn?.visibility = View.VISIBLE - else resumeBtn?.visibility = View.GONE - }, 1800) + val idx = if (currentChannel in channels.indices) currentChannel else 0 + val url = lastPlayedUrl + if (url != null && channels.isNotEmpty()) { + // 直接重连同一路流(新 HTTP 连接),直播流这样才能真正恢复 + loadChannelName = channels.getOrNull(idx)?.name ?: "" + beginLoading() + playUrl(url, channels[idx]) + handler.postDelayed({ + if (player?.isPlaying != true) resumeBtn?.visibility = View.VISIBLE + else resumeBtn?.visibility = View.GONE + }, 3500) + } else { + try { player?.play() } catch (e: Exception) { } + handler.postDelayed({ + if (player?.isPlaying != true) resumeBtn?.visibility = View.VISIBLE + else resumeBtn?.visibility = View.GONE + }, 1800) + } } if (playRequested > 0) { val idx = channels.indexOfFirst { it.num == playRequested } @@ -915,11 +929,15 @@ class MainActivity : Activity() { private fun resumePlayback() { resumeBtn?.visibility = View.GONE val idx = if (currentChannel in channels.indices) currentChannel else 0 - try { player?.play() } catch (e: Exception) { } - // 等 1.2 秒看是否已恢复,没恢复就重连 - handler.postDelayed({ - if (player?.isPlaying != true) playChannel(idx) - }, 1200) + val url = lastPlayedUrl + if (url != null && channels.isNotEmpty()) { + // 直接重连同一路流:比重新抓源快得多,也最可靠 + loadChannelName = channels[idx].name + beginLoading() + playUrl(url, channels[idx]) + } else { + playChannel(idx) + } } override fun onWindowFocusChanged(hasFocus: Boolean) {