optimize ysp

This commit is contained in:
Li ZongYing 2023-12-15 18:12:11 +08:00
parent aef165504f
commit cc2dc25e35
5 changed files with 58 additions and 18 deletions

View File

@ -17,13 +17,13 @@ import androidx.media3.exoplayer.hls.HlsMediaSource
import java.io.IOException
open class Custom2MediaPlayerAdapter(private var mContext: Context?) : PlayerAdapter() {
open class ExoPlayerAdapter(private var mContext: Context?) : PlayerAdapter() {
val mPlayer = mContext?.let { ExoPlayer.Builder(it).build() }
var mSurfaceHolderGlueHost: SurfaceHolderGlueHost? = null
val mRunnable: Runnable = object : Runnable {
override fun run() {
callback.onCurrentPositionChanged(this@Custom2MediaPlayerAdapter)
callback.onCurrentPositionChanged(this@ExoPlayerAdapter)
mHandler.postDelayed(this, getProgressUpdatingInterval().toLong())
}
};
@ -38,7 +38,7 @@ open class Custom2MediaPlayerAdapter(private var mContext: Context?) : PlayerAda
open fun notifyBufferingStartEnd() {
callback.onBufferingStateChanged(
this@Custom2MediaPlayerAdapter,
this@ExoPlayerAdapter,
mBufferingStart || !mInitialized
)
}
@ -65,7 +65,7 @@ open class Custom2MediaPlayerAdapter(private var mContext: Context?) : PlayerAda
mInitialized = false
notifyBufferingStartEnd()
if (mHasDisplay) {
callback.onPreparedStateChanged(this@Custom2MediaPlayerAdapter)
callback.onPreparedStateChanged(this@ExoPlayerAdapter)
}
}
}
@ -100,11 +100,11 @@ open class Custom2MediaPlayerAdapter(private var mContext: Context?) : PlayerAda
mPlayer?.setVideoSurfaceHolder(surfaceHolder)
if (mHasDisplay) {
if (mInitialized) {
callback.onPreparedStateChanged(this@Custom2MediaPlayerAdapter)
callback.onPreparedStateChanged(this@ExoPlayerAdapter)
}
} else {
if (mInitialized) {
callback.onPreparedStateChanged(this@Custom2MediaPlayerAdapter)
callback.onPreparedStateChanged(this@ExoPlayerAdapter)
}
}
}
@ -154,14 +154,14 @@ open class Custom2MediaPlayerAdapter(private var mContext: Context?) : PlayerAda
return
}
mPlayer?.play()
callback.onPlayStateChanged(this@Custom2MediaPlayerAdapter)
callback.onCurrentPositionChanged(this@Custom2MediaPlayerAdapter)
callback.onPlayStateChanged(this@ExoPlayerAdapter)
callback.onCurrentPositionChanged(this@ExoPlayerAdapter)
}
override fun pause() {
if (isPlaying) {
mPlayer?.pause()
callback.onPlayStateChanged(this@Custom2MediaPlayerAdapter)
callback.onPlayStateChanged(this@ExoPlayerAdapter)
}
}
@ -222,7 +222,7 @@ open class Custom2MediaPlayerAdapter(private var mContext: Context?) : PlayerAda
}
mPlayer?.prepare()
mPlayer?.playWhenReady = true
callback.onPlayStateChanged(this@Custom2MediaPlayerAdapter)
callback.onPlayStateChanged(this@ExoPlayerAdapter)
}
/**
@ -234,7 +234,7 @@ open class Custom2MediaPlayerAdapter(private var mContext: Context?) : PlayerAda
}
}
internal class VideoPlayerSurfaceHolderCallback(private val playerAdapter: Custom2MediaPlayerAdapter) :
internal class VideoPlayerSurfaceHolderCallback(private val playerAdapter: ExoPlayerAdapter) :
SurfaceHolder.Callback {
override fun surfaceCreated(surfaceHolder: SurfaceHolder) {

View File

@ -47,12 +47,12 @@ class MainFragment : BrowseSupportFragment() {
setupEventListeners()
view?.post {
request?.fetchPage()
// request?.fetchPage()
}
tvListViewModel.getListLiveData().value?.forEach { tvViewModel ->
tvViewModel.videoUrl.observe(viewLifecycleOwner) { _ ->
Log.i(TAG, "tv ${tvViewModel.getTV()}")
// Log.i(TAG, "tv ${tvViewModel.getTV()}")
if (tvViewModel.updateByYSP()) {
val tv = tvViewModel.getTV()
if (tv.id == itemPosition) {
@ -87,7 +87,6 @@ class MainFragment : BrowseSupportFragment() {
rowsAdapter = ArrayObjectAdapter(ListRowPresenter())
// val cardPresenter = CardPresenter(lifecycleScope, viewLifecycleOwner)
val cardPresenter = CardPresenter(lifecycleScope)
var idx: Long = 0

View File

@ -13,13 +13,13 @@ import java.io.IOException
class PlaybackFragment : VideoSupportFragment() {
private lateinit var mTransportControlGlue: PlaybackTransportControlGlue<PlayerAdapter>
private var playerAdapter: Custom2MediaPlayerAdapter? = null
private var playerAdapter: ExoPlayerAdapter? = null
private var lastVideoUrl: String = ""
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
playerAdapter = Custom2MediaPlayerAdapter(context)
playerAdapter = ExoPlayerAdapter(context)
playerAdapter?.setRepeatAction(PlaybackControlsRow.RepeatAction.INDEX_NONE)
view?.isFocusable = false

View File

@ -1,6 +1,7 @@
package com.lizongying.mytv
import android.content.Context
import android.util.Base64
import android.util.Log
import com.lizongying.mytv.api.ApiClient
import com.lizongying.mytv.api.LiveInfo
@ -14,6 +15,9 @@ import com.lizongying.mytv.proto.Ysp.cn.yangshipin.oms.common.proto.pageModel
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response
import javax.crypto.Cipher
import javax.crypto.spec.IvParameterSpec
import javax.crypto.spec.SecretKeySpec
class Request(var context: Context) {
@ -86,7 +90,27 @@ class Request(var context: Context) {
if (response.isSuccessful) {
val liveInfo = response.body()
if (liveInfo?.data?.playurl != null) {
tvModel.updateVideoUrlByYSP(liveInfo.data.playurl)
val chanll = liveInfo.data.chanll
val decodedBytes = Base64.decode(
chanll.substring(9, chanll.length - 3),
Base64.DEFAULT
)
val decodedString = String(decodedBytes)
val regex = Regex("""des_key = "([^"]+).+var des_iv = "([^"]+)""")
val matchResult = regex.find(decodedString)
var keyBytes = byteArrayOf()
var ivBytes = byteArrayOf()
if (matchResult != null) {
val (key, iv) = matchResult.destructured
keyBytes = Base64.decode(key, Base64.DEFAULT)
ivBytes = Base64.decode(iv, Base64.DEFAULT)
}
tvModel.updateVideoUrlByYSP(
liveInfo.data.playurl + "&revoi=" + encryptTripleDES(
keyBytes,
ivBytes
)
)
}
}
}
@ -152,6 +176,22 @@ class Request(var context: Context) {
})
}
private fun encryptTripleDES(key: ByteArray, iv: ByteArray): String {
val plaintext =
"""{"mver":"1","subver":"1.2","host":"www.yangshipin.cn/#/tv/home?pid=","referer":"","canvas":"YSPANGLE(Apple,AppleM1Pro,OpenGL4.1)"}"""
return try {
val keySpec = SecretKeySpec(key, "DESede")
val ivSpec = IvParameterSpec(iv)
val cipher = Cipher.getInstance("DESede/CBC/PKCS7Padding")
cipher.init(Cipher.ENCRYPT_MODE, keySpec, ivSpec)
val encryptedBytes = cipher.doFinal(plaintext.toByteArray())
encryptedBytes.let { it -> it.joinToString("") { "%02x".format(it) } }
} catch (e: Exception) {
e.printStackTrace()
""
}
}
companion object {
private const val TAG = "Request"
}

View File

@ -13,7 +13,8 @@ data class LiveInfo(
)
data class LiveInfoData(
val playurl: String
val chanll: String,
val playurl: String,
)
data class LiveInfoRequest(