Skip to content

Commit

Permalink
fix error in playing
Browse files Browse the repository at this point in the history
  • Loading branch information
lizongying committed May 16, 2024
1 parent c16a4bc commit 7e57aa8
Show file tree
Hide file tree
Showing 15 changed files with 103 additions and 44 deletions.
6 changes: 6 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
## 更新日志

### v2.0.0

* 解决卡顿问题
* 解决网格样式时,点击空白处不退出的问题
* 解决频道列表样式切换可能不生效的问题

### v1.9.8(通用)

* 优化在线升级
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ gen-version:
git describe --tags --always
git describe --tags --always | sed 's/v/ /g' | sed 's/\./ /g' | sed 's/-/ /g' | awk '{print ($$1*16777216)+($$2*65536)+($$3*256)+$$4}'

#make gen v=v1.1.3
#make gen v=v2.0.0
gen:
echo $(v) | sed 's/v/ /g' | sed 's/\./ /g' | sed 's/-/ /g' | awk '{print "{\"version_code\": " ($$1*16777216)+($$2*65536)+($$3*256)+$$4 ", \"version_name\": \"" "$(v)" "\"}"}' > version.json
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
## TODO

* 音量不同
* 大湾区卫视、广东4k超高清、广东珠江、三沙卫视
* 大湾区卫视、广东4k超高清、广东珠江、三沙卫视、翡翠
* CHC高清三个电影频道
* 地方频道
* 收藏夹
Expand All @@ -35,7 +35,7 @@
* 亮度调节
* 音量调节
* 軟解
* 自動更新
* 网格空白处退出

## 版权说明

Expand Down
11 changes: 8 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -77,24 +77,29 @@ static def VersionCode() {
def replace = [v: "", ".": " ", "-": " "]
def arr = (process.text.trim().replace(replace) + " 0").split(" ")
def versionCode = arr[0].toInteger() * 16777216 + arr[1].toInteger() * 65536 + arr[2].toInteger() * 256 + arr[3].toInteger()
println("VersionCode $versionCode")
return versionCode
} catch (ignored) {
return 0
return 1
}
}

static def VersionName() {
try {
def process = "git describe --tags --always".execute()
process.waitFor()
return process.text.trim() - "v"
def versionName = process.text.trim() - "v"
if (versionName.isEmpty()) {
versionName = "1.0.0"
}
return versionName
} catch (ignored) {
return "1.0.0"
}
}

dependencies {

// minSdk17
def media3_version = "1.2.1"

implementation "androidx.media3:media3-ui:$media3_version"
Expand Down
16 changes: 12 additions & 4 deletions app/src/main/java/com/lizongying/mytv/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import kotlinx.coroutines.async
import kotlinx.coroutines.launch


class MainActivity : FragmentActivity(), Request.RequestListener {
class MainActivity : FragmentActivity(), Request.RequestListener, OnSharedPreferenceChangeListener {

private var ready = 0
private val playerFragment = PlayerFragment()
Expand Down Expand Up @@ -122,6 +122,8 @@ class MainActivity : FragmentActivity(), Request.RequestListener {
// Log.i(TAG, "net ${Build.VERSION.SDK_INT}")
// ready++
// }

SP.setOnSharedPreferenceChangeListener(this)
}

fun showInfoFragment(tvViewModel: TVViewModel) {
Expand Down Expand Up @@ -358,8 +360,6 @@ class MainActivity : FragmentActivity(), Request.RequestListener {
private val hideSetting = Runnable {
if (settingFragment.isVisible) {
settingFragment.dismiss()
showTime()
mainFragment.changeMenu()
}
}

Expand Down Expand Up @@ -499,7 +499,7 @@ class MainActivity : FragmentActivity(), Request.RequestListener {
}

KeyEvent.KEYCODE_UNKNOWN -> {
showSetting()
// showSetting()
return true
}

Expand Down Expand Up @@ -612,4 +612,12 @@ class MainActivity : FragmentActivity(), Request.RequestListener {
private companion object {
const val TAG = "MainActivity"
}

override fun onSharedPreferenceChanged(key: String) {
Log.i(TAG, "$key changed")
when (key) {
SP.KEY_GRID -> mainFragment.changeMenu()
SP.KEY_TIME -> showTime()
}
}
}
16 changes: 16 additions & 0 deletions app/src/main/java/com/lizongying/mytv/MainFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.os.Bundle
import android.util.Log
import android.view.KeyEvent
import android.view.LayoutInflater
import android.view.MotionEvent
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
Expand Down Expand Up @@ -134,6 +135,21 @@ class MainFragment : Fragment(), CardAdapter.ItemListener {
hideSelf()
}

itemBinding.items.addOnItemTouchListener(object : RecyclerView.OnItemTouchListener {
override fun onInterceptTouchEvent(rv: RecyclerView, e: MotionEvent): Boolean {
hideSelf()
return false
}

override fun onTouchEvent(rv: RecyclerView, e: MotionEvent) {
TODO("Not yet implemented")
}

override fun onRequestDisallowInterceptTouchEvent(disallowIntercept: Boolean) {
TODO("Not yet implemented")
}
})

val layoutParamsHeader =
itemBinding.header.layoutParams as ViewGroup.MarginLayoutParams
layoutParamsHeader.topMargin = application.px2Px(itemBinding.header.marginTop)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.lizongying.mytv


interface OnSharedPreferenceChangeListener {
fun onSharedPreferenceChanged(key: String)
}
7 changes: 7 additions & 0 deletions app/src/main/java/com/lizongying/mytv/PlayerFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import androidx.media3.common.PlaybackException
import androidx.media3.common.Player
import androidx.media3.common.VideoSize
import androidx.media3.common.util.UnstableApi
import androidx.media3.exoplayer.DefaultRenderersFactory
import androidx.media3.exoplayer.ExoPlayer
import androidx.media3.ui.PlayerView
import com.google.android.exoplayer2.SimpleExoPlayer
Expand Down Expand Up @@ -52,10 +53,16 @@ class PlayerFragment : Fragment(), SurfaceHolder.Callback {

playerView?.viewTreeObserver?.addOnGlobalLayoutListener(object :
ViewTreeObserver.OnGlobalLayoutListener {
@OptIn(UnstableApi::class)
override fun onGlobalLayout() {
playerView!!.viewTreeObserver.removeOnGlobalLayoutListener(this)

// val renderersFactory = context?.let { DefaultRenderersFactory(it) }
// renderersFactory?.setExtensionRendererMode(DefaultRenderersFactory.EXTENSION_RENDERER_MODE_ON)

playerView!!.player = activity?.let {
ExoPlayer.Builder(it)
// .setRenderersFactory(renderersFactory!!)
.build()
}
playerView!!.player?.playWhenReady = true
Expand Down
17 changes: 14 additions & 3 deletions app/src/main/java/com/lizongying/mytv/SP.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ object SP {
// If use channel num to select channel or not
private const val KEY_CHANNEL_NUM = "channel_num"

private const val KEY_TIME = "time"
const val KEY_TIME = "time"

// If start app on device boot or not
private const val KEY_BOOT_STARTUP = "boot_startup"

private const val KEY_GRID = "grid"
const val KEY_GRID = "grid"

// Position in list of the selected channel item
private const val KEY_POSITION = "position"
Expand All @@ -28,13 +28,19 @@ object SP {

private lateinit var sp: SharedPreferences

private var listener: OnSharedPreferenceChangeListener? = null

/**
* The method must be invoked as early as possible(At least before using the keys)
*/
fun init(context: Context) {
sp = context.getSharedPreferences(SP_FILE_NAME, Context.MODE_PRIVATE)
}

fun setOnSharedPreferenceChangeListener(listener: OnSharedPreferenceChangeListener) {
this.listener = listener
}

var channelReversal: Boolean
get() = sp.getBoolean(KEY_CHANNEL_REVERSAL, false)
set(value) = sp.edit().putBoolean(KEY_CHANNEL_REVERSAL, value).apply()
Expand All @@ -53,7 +59,12 @@ object SP {

var grid: Boolean
get() = sp.getBoolean(KEY_GRID, false)
set(value) = sp.edit().putBoolean(KEY_GRID, value).apply()
set(value) {
if (value != this.grid) {
sp.edit().putBoolean(KEY_GRID, value).apply()
listener?.onSharedPreferenceChanged(KEY_GRID)
}
}

var itemPosition: Int
get() = sp.getInt(KEY_POSITION, 0)
Expand Down
7 changes: 4 additions & 3 deletions app/src/main/java/com/lizongying/mytv/SettingFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ class SettingFragment : DialogFragment() {
requireActivity().finishAffinity()
}

updateManager = UpdateManager(context, context.appVersionCode)

return binding.root
}

Expand Down Expand Up @@ -197,7 +199,7 @@ class SettingFragment : DialogFragment() {
PERMISSIONS_REQUEST_CODE
)
} else {
UpdateManager(context, context.appVersionCode).checkAndUpdate()
updateManager.checkAndUpdate()
}
}

Expand All @@ -216,8 +218,7 @@ class SettingFragment : DialogFragment() {
}
}
if (allPermissionsGranted) {
val context = requireContext()
UpdateManager(context, context.appVersionCode).checkAndUpdate()
updateManager.checkAndUpdate()
} else {
Toast.makeText(context, "权限授权失败", Toast.LENGTH_LONG).show()
}
Expand Down
1 change: 0 additions & 1 deletion app/src/main/java/com/lizongying/mytv/UpdateManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ class UpdateManager(
private fun startDownload(release: ReleaseResponse) {
val apkName = "my-tv"
val apkFileName = "$apkName-${release.version_name}.apk"
Log.i(TAG, "apkFileName $apkFileName")
val downloadManager =
context.getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager
val request =
Expand Down
20 changes: 10 additions & 10 deletions app/src/main/java/com/lizongying/mytv/api/KvcollectRequest.kt
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package com.lizongying.mytv.api

data class KvcollectRequest(
val BossId: Int = 2727,
val Pwd: Int = 1424084450,
val BossId: Int = 99150,
val Pwd: Int = 1999332929,
val cdn: String = "waibao",
val cmd: Int = 263,
val defn: String = "fhd",
val downspeed: Double = 10.0,
val downspeed: Int = 10,
val durl: String = "", //
val errcode: String = "",
val fact1: String = "ysp_pc_live_b",
val firstreport: Int = 0,
val fplayerver: String = "100",
val fplayerver: String = "180",
val ftime: String = "", //
val geturltime: Int = 0,
val guid: String = "", //
Expand Down Expand Up @@ -39,17 +39,17 @@ data class KvcollectRequest(


data class KvcollectRequest2(
val BossId: Int = 2727,
val Pwd: Int = 1424084450,
val BossId: Int = 99150,
val Pwd: Int = 1999332929,
val cdn: String = "waibao",
val cmd: Int = 263,
val defn: String = "fhd",
val downspeed: String = "10",
val downspeed: Int = 10,
val durl: String = "", //
val errcode: String = "",
val fact1: String = "ysp_pc_live_b",
val firstreport: Int = 0,
val fplayerver: String = "100",
val fplayerver: String = "180",
val ftime: String = "", //
val geturltime: Int = 0,
val guid: String = "", //
Expand All @@ -68,9 +68,9 @@ data class KvcollectRequest2(
val sRef: String = "",
val sUrl: String = "", //
val sdtfrom: String = "ysp_pc_01",
val seq: Int = 9, //
val seq: Int = 0, //
var signature: String = "",
val url: String = "", //
val viewid: String = "", //
val _dc: Double = 0.0,
val _dc: String = "",
)
12 changes: 6 additions & 6 deletions app/src/main/java/com/lizongying/mytv/api/YSPBtraceService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ interface YSPBtraceService {
"referer: https://www.yangshipin.cn/",
)
fun kvcollect3(
@Field("BossId") BossId: String = "9141",
@Field("Pwd") Pwd: String = "1137850982",
@Field("BossId") BossId: String = "9150",
@Field("Pwd") Pwd: String = "1999332929",
@Field("prog") prog: String = "", //
@Field("playno") playno: String = "", //
@Field("guid") guid: String = "", //
Expand All @@ -102,7 +102,7 @@ interface YSPBtraceService {
@Field("firstreport") firstreport: String = "-",
@Field("sUrl") sUrl: String = "", //
@Field("sRef") sRef: String = "-",
@Field("fplayerver") fplayerver: String = "100",
@Field("fplayerver") fplayerver: String = "180",
@Field("livepid") livepid: String = "",
@Field("viewid") viewid: String = "",
@Field("seq") seq: String = "",
Expand All @@ -118,8 +118,8 @@ interface YSPBtraceService {
@Field("_dc") _dc: String = "",
@Field("live_type") live_type: String = "-",
@Field("ftime") ftime: String = "",
@Field("url") url: String = "",
@Field("rand_str") rand_str: String = "", //
@Field("signature") signature: String = "",
// @Field("url") url: String = "",
// @Field("rand_str") rand_str: String = "", //
// @Field("signature") signature: String = "",
): Call<Void>
}
Loading

0 comments on commit 7e57aa8

Please sign in to comment.