fix video size on phone

This commit is contained in:
Li ZongYing 2023-12-26 11:21:03 +08:00
parent 657b8714a0
commit bb4fd56845
14 changed files with 60 additions and 89 deletions

View File

@ -16,10 +16,10 @@
<activity
android:keepScreenOn="true"
android:name=".MainActivity"
android:banner="@drawable/tv"
android:banner="@drawable/logo"
android:exported="true"
android:icon="@drawable/tv"
android:logo="@drawable/tv"
android:icon="@drawable/logo"
android:logo="@drawable/logo"
android:screenOrientation="landscape">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

View File

@ -1,23 +0,0 @@
package com.lizongying.mytv
import androidx.media3.common.C
import androidx.media3.common.util.UnstableApi
import androidx.media3.exoplayer.upstream.DefaultLoadErrorHandlingPolicy
@UnstableApi
class CustomLoadErrorHandlingPolicy(private val minimumLoadableRetryCount: Int) :
DefaultLoadErrorHandlingPolicy(minimumLoadableRetryCount) {
override fun getMinimumLoadableRetryCount(dataType: Int): Int {
return if (minimumLoadableRetryCount == -1) {
if (dataType == C.DATA_TYPE_MEDIA_PROGRESSIVE_LIVE) {
DEFAULT_MIN_LOADABLE_RETRY_COUNT_PROGRESSIVE_LIVE
} else {
DEFAULT_MIN_LOADABLE_RETRY_COUNT
}
} else {
minimumLoadableRetryCount
}
}
}

View File

@ -13,6 +13,7 @@ import android.util.Log
import android.view.GestureDetector
import android.view.KeyEvent
import android.view.MotionEvent
import android.view.View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
import android.view.WindowManager
import android.widget.ImageView
import android.widget.LinearLayout
@ -26,7 +27,7 @@ import java.security.MessageDigest
class MainActivity : FragmentActivity() {
private val playbackFragment = PlaybackFragment()
private val playerFragment = PlayerFragment()
private val mainFragment = MainFragment()
private val infoFragment = InfoFragment()
@ -40,10 +41,11 @@ class MainActivity : FragmentActivity() {
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN)
window.decorView.systemUiVisibility = SYSTEM_UI_FLAG_HIDE_NAVIGATION
if (savedInstanceState == null) {
supportFragmentManager.beginTransaction()
.add(R.id.main_browse_fragment, playbackFragment)
.add(R.id.main_browse_fragment, playerFragment)
.add(R.id.main_browse_fragment, mainFragment)
.add(R.id.main_browse_fragment, infoFragment)
.hide(infoFragment)
@ -75,7 +77,7 @@ class MainActivity : FragmentActivity() {
fun play(tvViewModel: TVViewModel) {
Log.i(TAG, "play: ${tvViewModel.getTV()}")
playbackFragment.play(tvViewModel)
playerFragment.play(tvViewModel)
}
fun prev() {
@ -134,6 +136,7 @@ class MainActivity : FragmentActivity() {
private inner class GestureListener : GestureDetector.SimpleOnGestureListener() {
override fun onSingleTapConfirmed(e: MotionEvent): Boolean {
Log.i(TAG, "onSingleTapConfirmed")
switchMainFragment()
return true
}
@ -240,12 +243,12 @@ class MainActivity : FragmentActivity() {
if (mainFragment.isHidden) {
prev()
} else {
if (mainFragment.selectedPosition == 0) {
mainFragment.setSelectedPosition(
mainFragment.tvListViewModel.maxNum.size - 1,
false
)
}
// if (mainFragment.selectedPosition == 0) {
// mainFragment.setSelectedPosition(
// mainFragment.tvListViewModel.maxNum.size - 1,
// false
// )
// }
}
}
@ -253,11 +256,11 @@ class MainActivity : FragmentActivity() {
if (mainFragment.isHidden) {
next()
} else {
if (mainFragment.selectedPosition == mainFragment.tvListViewModel.maxNum.size - 1) {
// mainFragment.setSelectedPosition(0, false)
hideMainFragment()
return false
}
// if (mainFragment.selectedPosition == mainFragment.tvListViewModel.maxNum.size - 1) {
//// mainFragment.setSelectedPosition(0, false)
// hideMainFragment()
// return false
// }
}
}
@ -265,12 +268,12 @@ class MainActivity : FragmentActivity() {
if (mainFragment.isHidden) {
prevSource()
} else {
if (mainFragment.tvListViewModel.getTVViewModelCurrent()
?.getItemPosition() == 0
) {
// mainFragment.toLastPosition()
hideMainFragment()
}
// if (mainFragment.tvListViewModel.getTVViewModelCurrent()
// ?.getItemPosition() == 0
// ) {
//// mainFragment.toLastPosition()
// hideMainFragment()
// }
}
}
@ -278,11 +281,11 @@ class MainActivity : FragmentActivity() {
if (mainFragment.isHidden) {
nextSource()
} else {
if (mainFragment.tvListViewModel.getTVViewModelCurrent()
?.getItemPosition() == mainFragment.tvListViewModel.maxNum[mainFragment.selectedPosition] - 1
) {
mainFragment.toFirstPosition()
}
// if (mainFragment.tvListViewModel.getTVViewModelCurrent()
// ?.getItemPosition() == mainFragment.tvListViewModel.maxNum[mainFragment.selectedPosition] - 1
// ) {
// mainFragment.toFirstPosition()
// }
}
}
}

View File

@ -4,6 +4,9 @@ import android.content.Context
import android.content.SharedPreferences
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.leanback.app.BrowseSupportFragment
import androidx.leanback.widget.ArrayObjectAdapter
@ -95,17 +98,6 @@ class MainFragment : BrowseSupportFragment() {
}
}
fun checkProgram() {
tvListViewModel.getTVListViewModel().value?.forEach { tvViewModel ->
if (tvViewModel.program.value!!.isEmpty()) {
if (tvViewModel.programId.value != null) {
Log.i(TAG, "get program ${tvViewModel.title.value}")
request?.fetchProgram(tvViewModel)
}
}
}
}
fun toLastPosition() {
setSelectedPosition(
selectedPosition, false,
@ -244,6 +236,7 @@ class MainFragment : BrowseSupportFragment() {
rowViewHolder: RowPresenter.ViewHolder,
row: Row
) {
Log.i(TAG, "onSingleTapConfirmed")
if (item is TVViewModel) {
itemPosition = item.id.value!!
savePosition(itemPosition)
@ -261,17 +254,7 @@ class MainFragment : BrowseSupportFragment() {
itemViewHolder: Presenter.ViewHolder?, item: Any?,
rowViewHolder: RowPresenter.ViewHolder, row: Row
) {
if (itemViewHolder == null) {
view?.post {
val tvViewModel = tvListViewModel.getTVViewModel(itemPosition)
if (tvViewModel != null) {
setSelectedPosition(
tvViewModel.getRowPosition(), false,
SelectItemViewHolderTask(tvViewModel.getItemPosition())
)
}
}
}
Log.i(TAG, "onSingleTapConfirmed1111")
if (item is TVViewModel) {
tvListViewModel.setItemPositionCurrent(item.id.value!!)
}

View File

@ -8,6 +8,8 @@ import android.view.ViewGroup
import androidx.annotation.OptIn
import androidx.fragment.app.Fragment
import androidx.media3.common.MediaItem
import androidx.media3.common.Player
import androidx.media3.common.VideoSize
import androidx.media3.common.util.UnstableApi
import androidx.media3.exoplayer.ExoPlayer
import androidx.media3.ui.PlayerView
@ -15,7 +17,7 @@ import com.lizongying.mytv.databinding.PlayerBinding
import com.lizongying.mytv.models.TVViewModel
class PlaybackFragment : Fragment() {
class PlayerFragment : Fragment() {
private var lastVideoUrl: String = ""
@ -52,6 +54,14 @@ class PlaybackFragment : Fragment() {
.build()
}
playerView!!.player?.playWhenReady = true
playerView!!.player?.addListener(object : Player.Listener {
override fun onVideoSizeChanged(videoSize: VideoSize) {
val aspectRatio = 16f / 9f
val layoutParams = playerView?.layoutParams
layoutParams?.width = (playerView?.measuredHeight?.times(aspectRatio))?.toInt()
playerView?.layoutParams = layoutParams
}
})
}
playerView!!.player?.run {

View File

@ -84,7 +84,6 @@ CGTN 纪录频道,https://livedoc.cgtn.com/500d/prog_index.m3u8,https://resource
三沙卫视,https://pullsstv90080111.ssws.tv/live/SSTV20220729.m3u8
延边卫视,http://live.ybtvyun.com/video/s10006-44f040627ca1/index.m3u8;http://dbiptv.sn.chinamobile.com/PLTV/88888890/224/3221226220/index.m3u8
浙江少儿,http://hw-m-l.cztv.com/channels/lantian/channel008/1080p.m3u8
南京少儿,http://live.nbs.cn/channels/njtv/sepd/500k.m3u8
移动专区
CETV1,http://dbiptv.sn.chinamobile.com/PLTV/88888890/224/3221225753/index.m3u8
@ -161,6 +160,9 @@ CHC动作电影,http://dbiptv.sn.chinamobile.com/PLTV/88888890/224/3221226465/in
}
if (!i.contains(",")) {
channel = i.trim()
if (channel == "移动专区") {
break
}
continue
}
val p = i.split(",")

View File

@ -2,11 +2,13 @@ package com.lizongying.mytv.api
import android.content.Context
import android.content.SharedPreferences
import android.util.Log
import com.lizongying.mytv.Encryptor
import com.lizongying.mytv.MainActivity
import com.lizongying.mytv.models.TVViewModel
import java.util.Date
import kotlin.math.floor
import kotlin.random.Random
class YSP(var context: Context) {
private var cnlid = ""
@ -87,14 +89,8 @@ class YSP(var context: Context) {
fun generateGuid(): String {
val timestamp = (System.currentTimeMillis()).toString(36)
val originalString = Math.random().toString()
val resultString = if (originalString.startsWith("0.")) {
originalString.substring(2)
} else {
originalString
}
val randomPart = resultString.toLong().toString(36)
return timestamp + "_" + randomPart
val randomPart = Random.nextLong().toString(36).take(11)
return timestamp + "_" + "0".repeat(11 - randomPart.length) + randomPart
}
fun getGuid(): String {

View File

@ -10,7 +10,6 @@ import androidx.media3.common.MediaItem
import androidx.media3.common.util.UnstableApi
import androidx.media3.datasource.DefaultHttpDataSource
import androidx.media3.exoplayer.hls.HlsMediaSource
import com.lizongying.mytv.CustomLoadErrorHandlingPolicy
import com.lizongying.mytv.TV
import com.lizongying.mytv.proto.Ysp.cn.yangshipin.omstv.common.proto.programModel.Program
import java.util.Date
@ -426,9 +425,7 @@ class TVViewModel(private var tv: TV) : ViewModel() {
val httpDataSource = DefaultHttpDataSource.Factory()
mHeaders?.let { httpDataSource.setDefaultRequestProperties(it) }
return HlsMediaSource.Factory(httpDataSource).setLoadErrorHandlingPolicy(
CustomLoadErrorHandlingPolicy(mMinimumLoadableRetryCount)
).createMediaSource(
return HlsMediaSource.Factory(httpDataSource).createMediaSource(
MediaItem.fromUri(
Uri.parse(videoUrl)
)

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

View File

@ -4,11 +4,14 @@
android:id="@+id/player_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/black"
android:keepScreenOn="true">
<androidx.media3.ui.PlayerView
android:id="@+id/player_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
app:resize_mode="fill"
app:use_controller="false" />
</FrameLayout>

View File

@ -1,3 +1,4 @@
<resources>
<color name="fastlane_background">#30000000</color>
<color name="black">#000</color>
</resources>

View File

@ -1,3 +1,3 @@
<resources>
<string name="app_name">My TV</string>
<string name="app_name">我的电视</string>
</resources>

View File

@ -5,5 +5,4 @@
<item name="browsePaddingEnd">11dp</item>
<item name="browseRowsMarginTop">54dp</item>
</style>
</resources>