diff --git a/HISTORY.md b/HISTORY.md index 03b8ab5..c2514dd 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,5 +1,9 @@ ## 更新日志 +### v1.2.3 + +* 修复一些无法播放的问题 + ### v1.2.2 * 修复一些无法播放的问题 diff --git a/app/src/main/java/com/lizongying/mytv0/PlayerFragment.kt b/app/src/main/java/com/lizongying/mytv0/PlayerFragment.kt index 8c10a45..fa920bb 100644 --- a/app/src/main/java/com/lizongying/mytv0/PlayerFragment.kt +++ b/app/src/main/java/com/lizongying/mytv0/PlayerFragment.kt @@ -23,6 +23,7 @@ import androidx.media3.datasource.DefaultHttpDataSource import androidx.media3.datasource.TransferListener import androidx.media3.exoplayer.DefaultRenderersFactory import androidx.media3.exoplayer.ExoPlayer +import androidx.media3.exoplayer.hls.HlsMediaSource import androidx.media3.exoplayer.mediacodec.MediaCodecSelector import androidx.media3.exoplayer.mediacodec.MediaCodecUtil import com.google.android.exoplayer2.Player.DISCONTINUITY_REASON_PERIOD_TRANSITION @@ -149,6 +150,8 @@ class PlayerFragment : Fragment(), SurfaceHolder.Callback { player?.run { IgnoreSSLCertificate.ignore() val httpDataSource = DefaultHttpDataSource.Factory() + httpDataSource.setKeepPostFor302Redirects(true) + httpDataSource.setAllowCrossProtocolRedirects(true) httpDataSource.setTransferListener(object : TransferListener { override fun onTransferInitializing( source: DataSource, 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 44c19c0..7fcdf8c 100644 --- a/app/src/main/java/com/lizongying/mytv0/models/TVModel.kt +++ b/app/src/main/java/com/lizongying/mytv0/models/TVModel.kt @@ -12,10 +12,9 @@ import androidx.media3.exoplayer.dash.DashMediaSource import androidx.media3.exoplayer.hls.HlsMediaSource import androidx.media3.exoplayer.rtsp.RtspMediaSource import androidx.media3.exoplayer.source.MediaSource +import androidx.media3.exoplayer.source.ProgressiveMediaSource import com.lizongying.mytv0.SP - -//import com.google.android.exoplayer2.source.MediaSource -//import com.google.android.exoplayer2.source.MediaSourceFactory +import java.util.Locale class TVModel(var tv: TV) : ViewModel() { private val _position = MutableLiveData() @@ -102,6 +101,8 @@ class TVModel(var tv: TV) : ViewModel() { var userAgent = "" val httpDataSource = DefaultHttpDataSource.Factory() + httpDataSource.setKeepPostFor302Redirects(true) + httpDataSource.setAllowCrossProtocolRedirects(true) tv.headers?.let { httpDataSource.setDefaultRequestProperties(it) it.forEach { (key, value) -> @@ -123,13 +124,26 @@ class TVModel(var tv: TV) : ViewModel() { } else { RtspMediaSource.Factory().setUserAgent(userAgent).createMediaSource(mediaItem) } + } else if (isVideoFile(uri)) { + ProgressiveMediaSource.Factory(httpDataSource).createMediaSource(mediaItem) } else { - null + HlsMediaSource.Factory(httpDataSource).createMediaSource(mediaItem) } } -// fun buildSource2(): com.google.android.exoplayer2.source.MediaSource { -// } + private fun isVideoFile(uri: Uri): Boolean { + val path = uri.lastPathSegment ?: return false + return if (path.contains(".")) { + val fileExtension = + path.substring(path.lastIndexOf('.') + 1) + .lowercase( + Locale.getDefault() + ) + fileExtension == "mp4" || fileExtension == "avi" || fileExtension == "mov" || fileExtension == "wmv" || fileExtension == "mkv" || fileExtension == "flv" || fileExtension == "mpeg" || fileExtension == "webm" + } else { + false + } + } companion object { private const val TAG = "TVModel" diff --git a/version.json b/version.json index fb667a2..7c5bc66 100644 --- a/version.json +++ b/version.json @@ -1 +1 @@ -{"version_code": 16908800, "version_name": "v1.2.2"} +{"version_code": 16909056, "version_name": "v1.2.3"}