From bb4fd568459352d7d4455f5ba1d9c7befbb076cf Mon Sep 17 00:00:00 2001 From: Li ZongYing Date: Tue, 26 Dec 2023 11:21:03 +0800 Subject: [PATCH] fix video size on phone --- app/src/main/AndroidManifest.xml | 6 +- .../mytv/CustomLoadErrorHandlingPolicy.kt | 23 -------- .../java/com/lizongying/mytv/MainActivity.kt | 53 +++++++++--------- .../java/com/lizongying/mytv/MainFragment.kt | 27 ++------- ...{PlaybackFragment.kt => PlayerFragment.kt} | 12 +++- .../main/java/com/lizongying/mytv/TVList.kt | 4 +- .../main/java/com/lizongying/mytv/api/YSP.kt | 12 ++-- .../com/lizongying/mytv/models/TVViewModel.kt | 5 +- app/src/main/res/drawable/logo.png | Bin 0 -> 1676 bytes app/src/main/res/drawable/tv.png | Bin 1145 -> 0 bytes app/src/main/res/layout/player.xml | 3 + app/src/main/res/values/colors.xml | 1 + app/src/main/res/values/strings.xml | 2 +- app/src/main/res/values/themes.xml | 1 - 14 files changed, 60 insertions(+), 89 deletions(-) delete mode 100644 app/src/main/java/com/lizongying/mytv/CustomLoadErrorHandlingPolicy.kt rename app/src/main/java/com/lizongying/mytv/{PlaybackFragment.kt => PlayerFragment.kt} (76%) create mode 100644 app/src/main/res/drawable/logo.png delete mode 100644 app/src/main/res/drawable/tv.png diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 379173e..61d00e9 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -16,10 +16,10 @@ diff --git a/app/src/main/java/com/lizongying/mytv/CustomLoadErrorHandlingPolicy.kt b/app/src/main/java/com/lizongying/mytv/CustomLoadErrorHandlingPolicy.kt deleted file mode 100644 index 35bf14b..0000000 --- a/app/src/main/java/com/lizongying/mytv/CustomLoadErrorHandlingPolicy.kt +++ /dev/null @@ -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 - } - } -} \ No newline at end of file diff --git a/app/src/main/java/com/lizongying/mytv/MainActivity.kt b/app/src/main/java/com/lizongying/mytv/MainActivity.kt index ea2f4ba..a3e2790 100644 --- a/app/src/main/java/com/lizongying/mytv/MainActivity.kt +++ b/app/src/main/java/com/lizongying/mytv/MainActivity.kt @@ -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() +// } } } } diff --git a/app/src/main/java/com/lizongying/mytv/MainFragment.kt b/app/src/main/java/com/lizongying/mytv/MainFragment.kt index 4687d72..5a8c726 100644 --- a/app/src/main/java/com/lizongying/mytv/MainFragment.kt +++ b/app/src/main/java/com/lizongying/mytv/MainFragment.kt @@ -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!!) } diff --git a/app/src/main/java/com/lizongying/mytv/PlaybackFragment.kt b/app/src/main/java/com/lizongying/mytv/PlayerFragment.kt similarity index 76% rename from app/src/main/java/com/lizongying/mytv/PlaybackFragment.kt rename to app/src/main/java/com/lizongying/mytv/PlayerFragment.kt index 449ece3..826d152 100644 --- a/app/src/main/java/com/lizongying/mytv/PlaybackFragment.kt +++ b/app/src/main/java/com/lizongying/mytv/PlayerFragment.kt @@ -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 { diff --git a/app/src/main/java/com/lizongying/mytv/TVList.kt b/app/src/main/java/com/lizongying/mytv/TVList.kt index 21cb71c..4a43698 100644 --- a/app/src/main/java/com/lizongying/mytv/TVList.kt +++ b/app/src/main/java/com/lizongying/mytv/TVList.kt @@ -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(",") diff --git a/app/src/main/java/com/lizongying/mytv/api/YSP.kt b/app/src/main/java/com/lizongying/mytv/api/YSP.kt index 75e3d0b..600d89e 100644 --- a/app/src/main/java/com/lizongying/mytv/api/YSP.kt +++ b/app/src/main/java/com/lizongying/mytv/api/YSP.kt @@ -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 { diff --git a/app/src/main/java/com/lizongying/mytv/models/TVViewModel.kt b/app/src/main/java/com/lizongying/mytv/models/TVViewModel.kt index b5e40ff..d0d07f5 100644 --- a/app/src/main/java/com/lizongying/mytv/models/TVViewModel.kt +++ b/app/src/main/java/com/lizongying/mytv/models/TVViewModel.kt @@ -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) ) diff --git a/app/src/main/res/drawable/logo.png b/app/src/main/res/drawable/logo.png new file mode 100644 index 0000000000000000000000000000000000000000..7e76d1fc63f0824b49602ea7393b0920797839cb GIT binary patch literal 1676 zcmcgt`#aMM9A1yhIdaP3xTMgN6OD>fks$N^!J2Kg)I%!4;pw72buC#*#qFZlZ{{qs zjOR|AfYL9sC6_RmDaquCavRy;`oV$J>{(vYzlbvaYn5BS*OgmzNi^*HbFasQFGPiNkAd!@Q)6EX#qlw#i)Fd+m0ARD z1J47(E>&IsiD$NlcifUZbOp9Pt*p=mW|KtM@SXVlV z({~Z1m>`ro)<9s-?2B>MC**<8E2<)WqZe2Cd_L-F3P7x-qeqaIi6cp-8Gkh!Uj=C3 zRK7)0qp@5+FX0$!iCGff?R7rboje%OSSgju<)#WaXLiv>2@<&lm1r{ZgKpPHPI?4f zSG}nY&te%f(fR@k`bNb56H$(|Y}kl?@oM~%%gJ|`gEX@B44Y!IWVlZKXp5SeqWZIp z1ZA<&M@5O$ouRgab=Zo0KFG06BY4|TY61y{XvfwWdm2Ct$}kI^V0JZRiF1|+D|Ps` z(%nMXmkwX4$zI`^JBju;oJwLE>F6?IoCqW|O3{({a&fu)astV{W!JPdtutsW$K;8- zl|?hMvO!+}YY7UhLttUOpj!g8T2hlG5p*}Yt)%v(3T=KZz#-uQ!-Etr<$ z7+g_u{*psZ`se5OfJ_>6d>AL_oOta=hSMk#PXF+k#dvKmlMI>0wL>gZ>0s4(F-b>I zd3y)%K4)s+*kDZ0+A>yqd{62nWWn|9p$Bqno65$*8ITJX{y zVIJrO^KB^;1s*AmMx4j{=(SLzJ_>10m2U!+g1t+`kVkOrakITze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spb99{`Q`6vUqDu`Wn z6Q+@X_2WTx3NrWC7h#*d7Q=l(tmVks4w%b=*e=IzBVf<)x_SkfPl?U8J%8L5RQ~cO z&{o}o$~~!i2VbgNP`PKF^U;TJTabU3HH>Q#blqq<{&E@LCCKj^J9!%exGt!4$ll|T z1pRI~`U5T_t5i_2go*-$5JCtcgb+dqA%qY@2qA?oJ)Kl@700000 LNkvXXu0mjfG-U&@ diff --git a/app/src/main/res/layout/player.xml b/app/src/main/res/layout/player.xml index 3c8dbe6..f31a7c8 100644 --- a/app/src/main/res/layout/player.xml +++ b/app/src/main/res/layout/player.xml @@ -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"> \ No newline at end of file diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 005847c..9f683fe 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -1,3 +1,4 @@ #30000000 + #000 \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 8e397fa..ab5ca41 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,3 +1,3 @@ - My TV + 我的电视 \ No newline at end of file diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml index b21c01e..1e18ada 100644 --- a/app/src/main/res/values/themes.xml +++ b/app/src/main/res/values/themes.xml @@ -5,5 +5,4 @@ 11dp 54dp - \ No newline at end of file