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 0000000..7e76d1f Binary files /dev/null and b/app/src/main/res/drawable/logo.png differ diff --git a/app/src/main/res/drawable/tv.png b/app/src/main/res/drawable/tv.png deleted file mode 100644 index 37d4d4b..0000000 Binary files a/app/src/main/res/drawable/tv.png and /dev/null differ 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