v9.2.0 从设置/桌面返回直接重连当前流(不再依赖play,避免定格);继续播放按钮强制重连
This commit is contained in:
1 parent
277485394c
commit
39c0c65c92
2 files changed
+26
-8
No files matched your search
@@ -11,8 +11,8 @@ android {
|
|||||||
applicationId = "com.iptv807.tv"
|
applicationId = "com.iptv807.tv"
|
||||||
minSdk = 21
|
minSdk = 21
|
||||||
targetSdk = 35
|
targetSdk = 35
|
||||||
versionCode = 910
|
versionCode = 920
|
||||||
versionName = "9.1.0"
|
versionName = "9.2.0"
|
||||||
}
|
}
|
||||||
|
|
||||||
buildTypes {
|
buildTypes {
|
||||||
|
|||||||
@@ -86,6 +86,7 @@ class MainActivity : Activity() {
|
|||||||
private var triedFresh = false
|
private var triedFresh = false
|
||||||
/** true=当前这次"新开播"还没真正开始(避免旧频道的播放回调把加载提示提前隐藏) */
|
/** true=当前这次"新开播"还没真正开始(避免旧频道的播放回调把加载提示提前隐藏) */
|
||||||
private var awaitingStart = false
|
private var awaitingStart = false
|
||||||
|
private var lastPlayedUrl: String? = null
|
||||||
private var failureReport = ""
|
private var failureReport = ""
|
||||||
private var wasStopped = false
|
private var wasStopped = false
|
||||||
private var resumeBtn: TextView? = null
|
private var resumeBtn: TextView? = null
|
||||||
@@ -586,6 +587,7 @@ class MainActivity : Activity() {
|
|||||||
.setMimeType(if (isFlv) MimeTypes.VIDEO_FLV else MimeTypes.APPLICATION_M3U8)
|
.setMimeType(if (isFlv) MimeTypes.VIDEO_FLV else MimeTypes.APPLICATION_M3U8)
|
||||||
.build()
|
.build()
|
||||||
awaitingStart = true
|
awaitingStart = true
|
||||||
|
lastPlayedUrl = url
|
||||||
player?.setMediaItem(item)
|
player?.setMediaItem(item)
|
||||||
player?.prepare()
|
player?.prepare()
|
||||||
player?.playWhenReady = true
|
player?.playWhenReady = true
|
||||||
@@ -897,13 +899,25 @@ class MainActivity : Activity() {
|
|||||||
// 从桌面/设置返回:先尝试续播,失败则显示「继续播放」按钮
|
// 从桌面/设置返回:先尝试续播,失败则显示「继续播放」按钮
|
||||||
if (wasStopped) {
|
if (wasStopped) {
|
||||||
wasStopped = false
|
wasStopped = false
|
||||||
|
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) { }
|
try { player?.play() } catch (e: Exception) { }
|
||||||
handler.postDelayed({
|
handler.postDelayed({
|
||||||
// 直播流暂停后常常定格无法续播 → 给用户一个明确的按钮
|
|
||||||
if (player?.isPlaying != true) resumeBtn?.visibility = View.VISIBLE
|
if (player?.isPlaying != true) resumeBtn?.visibility = View.VISIBLE
|
||||||
else resumeBtn?.visibility = View.GONE
|
else resumeBtn?.visibility = View.GONE
|
||||||
}, 1800)
|
}, 1800)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (playRequested > 0) {
|
if (playRequested > 0) {
|
||||||
val idx = channels.indexOfFirst { it.num == playRequested }
|
val idx = channels.indexOfFirst { it.num == playRequested }
|
||||||
playRequested = -1
|
playRequested = -1
|
||||||
@@ -915,11 +929,15 @@ class MainActivity : Activity() {
|
|||||||
private fun resumePlayback() {
|
private fun resumePlayback() {
|
||||||
resumeBtn?.visibility = View.GONE
|
resumeBtn?.visibility = View.GONE
|
||||||
val idx = if (currentChannel in channels.indices) currentChannel else 0
|
val idx = if (currentChannel in channels.indices) currentChannel else 0
|
||||||
try { player?.play() } catch (e: Exception) { }
|
val url = lastPlayedUrl
|
||||||
// 等 1.2 秒看是否已恢复,没恢复就重连
|
if (url != null && channels.isNotEmpty()) {
|
||||||
handler.postDelayed({
|
// 直接重连同一路流:比重新抓源快得多,也最可靠
|
||||||
if (player?.isPlaying != true) playChannel(idx)
|
loadChannelName = channels[idx].name
|
||||||
}, 1200)
|
beginLoading()
|
||||||
|
playUrl(url, channels[idx])
|
||||||
|
} else {
|
||||||
|
playChannel(idx)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onWindowFocusChanged(hasFocus: Boolean) {
|
override fun onWindowFocusChanged(hasFocus: Boolean) {
|
||||||
|
|||||||
Reference in new issue
Block a user