Skip to content

Commit

Permalink
Merge from kk6
Browse files Browse the repository at this point in the history
  • Loading branch information
vrichv committed Jul 29, 2024
1 parent 81f4e97 commit 9f3362d
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 13 deletions.
22 changes: 21 additions & 1 deletion app/src/main/java/com/lizongying/mytv0/PlayerFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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}")
}
}
})

Expand Down Expand Up @@ -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" }
Expand Down
11 changes: 8 additions & 3 deletions app/src/main/java/com/lizongying/mytv0/PortUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 0 additions & 2 deletions app/src/main/java/com/lizongying/mytv0/UpdateManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -92,7 +91,6 @@ class UpdateManager(
}
}
}

private suspend fun downloadWithRetry(url: String, file: File, maxRetries: Int = 3) {
var retries = 0
while (retries < maxRetries) {
Expand Down
8 changes: 7 additions & 1 deletion app/src/main/java/com/lizongying/mytv0/models/TVList.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
18 changes: 13 additions & 5 deletions app/src/main/java/com/lizongying/mytv0/models/TVModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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) ->
Expand All @@ -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()
Expand Down Expand Up @@ -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"
)
}
}
2 changes: 1 addition & 1 deletion version.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"version_code": 16910342, "version_name": "v1.2.8-jb2"}
{"version_code": 16910343, "version_name": "v1.2.8-jb3"}

0 comments on commit 9f3362d

Please sign in to comment.