From 9f3362d4d87776042b81339d046bbf67c7e0db48 Mon Sep 17 00:00:00 2001 From: vrichv <1572349+vrichv@users.noreply.github.com> Date: Mon, 29 Jul 2024 18:05:07 +0800 Subject: [PATCH] Merge from kk6 --- .../com/lizongying/mytv0/PlayerFragment.kt | 22 ++++++++++++++++++- .../java/com/lizongying/mytv0/PortUtil.kt | 11 +++++++--- .../com/lizongying/mytv0/UpdateManager.kt | 2 -- .../com/lizongying/mytv0/models/TVList.kt | 8 ++++++- .../com/lizongying/mytv0/models/TVModel.kt | 18 ++++++++++----- version.json | 2 +- 6 files changed, 50 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/com/lizongying/mytv0/PlayerFragment.kt b/app/src/main/java/com/lizongying/mytv0/PlayerFragment.kt index 6ca9780..2a9904f 100644 --- a/app/src/main/java/com/lizongying/mytv0/PlayerFragment.kt +++ b/app/src/main/java/com/lizongying/mytv0/PlayerFragment.kt @@ -61,6 +61,7 @@ class PlayerFragment : Fragment() { val playerMediaCodecSelector = PlayerMediaCodecSelector() renderersFactory?.setMediaCodecSelector(playerMediaCodecSelector) renderersFactory?.setExtensionRendererMode(DefaultRenderersFactory.EXTENSION_RENDERER_MODE_ON) + renderersFactory?.setEnableDecoderFallback(true) player = context?.let { ExoPlayer.Builder(it) @@ -120,14 +121,32 @@ class PlayerFragment : Fragment() { TAG, "播放错误 ${error.errorCode}||| ${error.errorCodeName}||| ${error.message}||| $error" ) + + if (error.errorCode == PlaybackException.ERROR_CODE_BEHIND_LIVE_WINDOW) { + tvModel?.setReady() + return + } + + "错误码[${error.errorCode}] ${error.errorCodeName}".showToast() tvModel?.setErrInfo("播放错误") - if (tvModel?.getSourceType() == SourceType.UNKNOWN) { + if (tvModel?.getSourceType() == SourceType.UNKNOWN) {//FIXME: retryTimes and UNKNOWN tvModel?.nextSource() } if (tvModel!!.retryTimes < tvModel!!.retryMaxTimes) { tvModel?.setReady() tvModel!!.retryTimes++ } + if (tvModel!!.retryTimes == tvModel!!.retryMaxTimes) { + val errorType = when (error.errorCode) { + in 2000 until 2003 -> "网络异常" + in 2003 until 3000 -> "服务器异常" + in 3000 until 4000 -> "节目源异常" + in 4000 until 6000 -> "解码异常" + in 6000 until 7000 -> "DRM 异常" + else -> "播放错误" + } + tvModel?.setErrInfo("${errorType}[${error.errorCode}]\n${error.errorCodeName}") + } } }) @@ -206,6 +225,7 @@ class PlayerFragment : Fragment() { requiresSecureDecoder, requiresTunnelingDecoder ) + Log.d(TAG, "Requested MIME type: $mimeType") if (mimeType == MimeTypes.VIDEO_H265 && !requiresSecureDecoder && !requiresTunnelingDecoder) { if (infos.size > 0) { val infosNew = infos.find { it.name == "c2.android.hevc.decoder" } diff --git a/app/src/main/java/com/lizongying/mytv0/PortUtil.kt b/app/src/main/java/com/lizongying/mytv0/PortUtil.kt index 065f5c2..0c76bd6 100644 --- a/app/src/main/java/com/lizongying/mytv0/PortUtil.kt +++ b/app/src/main/java/com/lizongying/mytv0/PortUtil.kt @@ -8,13 +8,18 @@ import java.net.ServerSocket object PortUtil { fun findFreePort(): Int { - var port = -1 + var port: Int var socket: ServerSocket? = null try { - socket = ServerSocket(0) + socket = ServerSocket(10086) port = socket.localPort } catch (e: IOException) { - e.printStackTrace() + try { + socket = ServerSocket(0) + port = socket.localPort + } catch (e: IOException) { + return -1 + } } finally { if (socket != null) { try { diff --git a/app/src/main/java/com/lizongying/mytv0/UpdateManager.kt b/app/src/main/java/com/lizongying/mytv0/UpdateManager.kt index 6c142a0..1661b45 100644 --- a/app/src/main/java/com/lizongying/mytv0/UpdateManager.kt +++ b/app/src/main/java/com/lizongying/mytv0/UpdateManager.kt @@ -19,7 +19,6 @@ import kotlinx.coroutines.withContext import java.io.File import java.io.IOException - class UpdateManager( private val context: Context, private val versionCode: Long @@ -92,7 +91,6 @@ class UpdateManager( } } } - private suspend fun downloadWithRetry(url: String, file: File, maxRetries: Int = 3) { var retries = 0 while (retries < maxRetries) { diff --git a/app/src/main/java/com/lizongying/mytv0/models/TVList.kt b/app/src/main/java/com/lizongying/mytv0/models/TVList.kt index d57dc62..c0d0fe4 100644 --- a/app/src/main/java/com/lizongying/mytv0/models/TVList.kt +++ b/app/src/main/java/com/lizongying/mytv0/models/TVList.kt @@ -323,7 +323,13 @@ object TVList { } private fun getTVModel(idx: Int): TVModel { - return listModel[idx] + if (idx < listModel.size) { + return listModel[idx] + } else { + SP.channel=0 + this.setPosition(0) + return listModel[0] + } } fun setPosition(position: Int): Boolean { diff --git a/app/src/main/java/com/lizongying/mytv0/models/TVModel.kt b/app/src/main/java/com/lizongying/mytv0/models/TVModel.kt index 756dc99..5b8e2d0 100644 --- a/app/src/main/java/com/lizongying/mytv0/models/TVModel.kt +++ b/app/src/main/java/com/lizongying/mytv0/models/TVModel.kt @@ -6,6 +6,7 @@ import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.media3.common.MediaItem +import androidx.media3.common.util.Log import androidx.media3.common.util.UnstableApi import androidx.media3.datasource.DefaultHttpDataSource import androidx.media3.exoplayer.dash.DashMediaSource @@ -23,7 +24,7 @@ class TVModel(var tv: TV) : ViewModel() { get() = _position var retryTimes = 0 - var retryMaxTimes = 10 + var retryMaxTimes = 3 var programUpdateTime = 0L var groupIndex = 0 @@ -123,6 +124,7 @@ class TVModel(var tv: TV) : ViewModel() { httpDataSource = DefaultHttpDataSource.Factory() httpDataSource.setKeepPostFor302Redirects(true) httpDataSource.setAllowCrossProtocolRedirects(true) + httpDataSource.setConnectTimeoutMs(5000) tv.headers?.let { httpDataSource.setDefaultRequestProperties(it) it.forEach { (key, value) -> @@ -139,12 +141,15 @@ class TVModel(var tv: TV) : ViewModel() { addSource(SourceType.HLS) } else if (path.lowercase().endsWith(".mpd")) { addSource(SourceType.DASH) - } else if (scheme.lowercase() == "rtsp") { + } else if (scheme.lowercase() == "rtsp" || scheme.lowercase() == "rtp") { addSource(SourceType.RTSP) + } else if (path.lowercase().substringAfterLast(".", "") + .let { it.isNotEmpty() && videoExtensions.contains(it) } + ) { + addSource(SourceType.PROGRESSIVE) } else { -// addSource(SourceType.UNKNOWN) -// addSource(SourceType.PROGRESSIVE) - addSource(SourceType.HLS) + Log.w(TAG, "URL SourceType UNKNOWN: ${uri.toString()}") + addSource(SourceType.UNKNOWN) } nextSource() @@ -209,5 +214,8 @@ class TVModel(var tv: TV) : ViewModel() { companion object { private const val TAG = "TVModel" + val videoExtensions = setOf( + ".flv", ".mp4", ".avi", ".mkv", ".mov", ".mpeg", "wmv", "webm" + ) } } \ No newline at end of file diff --git a/version.json b/version.json index 0515f9a..2b9ed45 100644 --- a/version.json +++ b/version.json @@ -1 +1 @@ -{"version_code": 16910342, "version_name": "v1.2.8-jb2"} +{"version_code": 16910343, "version_name": "v1.2.8-jb3"}