fix video size on phone
This commit is contained in:
parent
657b8714a0
commit
bb4fd56845
|
@ -16,10 +16,10 @@
|
||||||
<activity
|
<activity
|
||||||
android:keepScreenOn="true"
|
android:keepScreenOn="true"
|
||||||
android:name=".MainActivity"
|
android:name=".MainActivity"
|
||||||
android:banner="@drawable/tv"
|
android:banner="@drawable/logo"
|
||||||
android:exported="true"
|
android:exported="true"
|
||||||
android:icon="@drawable/tv"
|
android:icon="@drawable/logo"
|
||||||
android:logo="@drawable/tv"
|
android:logo="@drawable/logo"
|
||||||
android:screenOrientation="landscape">
|
android:screenOrientation="landscape">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
|
|
@ -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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -13,6 +13,7 @@ import android.util.Log
|
||||||
import android.view.GestureDetector
|
import android.view.GestureDetector
|
||||||
import android.view.KeyEvent
|
import android.view.KeyEvent
|
||||||
import android.view.MotionEvent
|
import android.view.MotionEvent
|
||||||
|
import android.view.View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
|
||||||
import android.view.WindowManager
|
import android.view.WindowManager
|
||||||
import android.widget.ImageView
|
import android.widget.ImageView
|
||||||
import android.widget.LinearLayout
|
import android.widget.LinearLayout
|
||||||
|
@ -26,7 +27,7 @@ import java.security.MessageDigest
|
||||||
|
|
||||||
class MainActivity : FragmentActivity() {
|
class MainActivity : FragmentActivity() {
|
||||||
|
|
||||||
private val playbackFragment = PlaybackFragment()
|
private val playerFragment = PlayerFragment()
|
||||||
private val mainFragment = MainFragment()
|
private val mainFragment = MainFragment()
|
||||||
private val infoFragment = InfoFragment()
|
private val infoFragment = InfoFragment()
|
||||||
|
|
||||||
|
@ -40,10 +41,11 @@ class MainActivity : FragmentActivity() {
|
||||||
|
|
||||||
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||||
window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN)
|
window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN)
|
||||||
|
window.decorView.systemUiVisibility = SYSTEM_UI_FLAG_HIDE_NAVIGATION
|
||||||
|
|
||||||
if (savedInstanceState == null) {
|
if (savedInstanceState == null) {
|
||||||
supportFragmentManager.beginTransaction()
|
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, mainFragment)
|
||||||
.add(R.id.main_browse_fragment, infoFragment)
|
.add(R.id.main_browse_fragment, infoFragment)
|
||||||
.hide(infoFragment)
|
.hide(infoFragment)
|
||||||
|
@ -75,7 +77,7 @@ class MainActivity : FragmentActivity() {
|
||||||
|
|
||||||
fun play(tvViewModel: TVViewModel) {
|
fun play(tvViewModel: TVViewModel) {
|
||||||
Log.i(TAG, "play: ${tvViewModel.getTV()}")
|
Log.i(TAG, "play: ${tvViewModel.getTV()}")
|
||||||
playbackFragment.play(tvViewModel)
|
playerFragment.play(tvViewModel)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun prev() {
|
fun prev() {
|
||||||
|
@ -134,6 +136,7 @@ class MainActivity : FragmentActivity() {
|
||||||
private inner class GestureListener : GestureDetector.SimpleOnGestureListener() {
|
private inner class GestureListener : GestureDetector.SimpleOnGestureListener() {
|
||||||
|
|
||||||
override fun onSingleTapConfirmed(e: MotionEvent): Boolean {
|
override fun onSingleTapConfirmed(e: MotionEvent): Boolean {
|
||||||
|
Log.i(TAG, "onSingleTapConfirmed")
|
||||||
switchMainFragment()
|
switchMainFragment()
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -240,12 +243,12 @@ class MainActivity : FragmentActivity() {
|
||||||
if (mainFragment.isHidden) {
|
if (mainFragment.isHidden) {
|
||||||
prev()
|
prev()
|
||||||
} else {
|
} else {
|
||||||
if (mainFragment.selectedPosition == 0) {
|
// if (mainFragment.selectedPosition == 0) {
|
||||||
mainFragment.setSelectedPosition(
|
// mainFragment.setSelectedPosition(
|
||||||
mainFragment.tvListViewModel.maxNum.size - 1,
|
// mainFragment.tvListViewModel.maxNum.size - 1,
|
||||||
false
|
// false
|
||||||
)
|
// )
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -253,11 +256,11 @@ class MainActivity : FragmentActivity() {
|
||||||
if (mainFragment.isHidden) {
|
if (mainFragment.isHidden) {
|
||||||
next()
|
next()
|
||||||
} else {
|
} else {
|
||||||
if (mainFragment.selectedPosition == mainFragment.tvListViewModel.maxNum.size - 1) {
|
// if (mainFragment.selectedPosition == mainFragment.tvListViewModel.maxNum.size - 1) {
|
||||||
// mainFragment.setSelectedPosition(0, false)
|
//// mainFragment.setSelectedPosition(0, false)
|
||||||
hideMainFragment()
|
// hideMainFragment()
|
||||||
return false
|
// return false
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -265,12 +268,12 @@ class MainActivity : FragmentActivity() {
|
||||||
if (mainFragment.isHidden) {
|
if (mainFragment.isHidden) {
|
||||||
prevSource()
|
prevSource()
|
||||||
} else {
|
} else {
|
||||||
if (mainFragment.tvListViewModel.getTVViewModelCurrent()
|
// if (mainFragment.tvListViewModel.getTVViewModelCurrent()
|
||||||
?.getItemPosition() == 0
|
// ?.getItemPosition() == 0
|
||||||
) {
|
// ) {
|
||||||
// mainFragment.toLastPosition()
|
//// mainFragment.toLastPosition()
|
||||||
hideMainFragment()
|
// hideMainFragment()
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -278,11 +281,11 @@ class MainActivity : FragmentActivity() {
|
||||||
if (mainFragment.isHidden) {
|
if (mainFragment.isHidden) {
|
||||||
nextSource()
|
nextSource()
|
||||||
} else {
|
} else {
|
||||||
if (mainFragment.tvListViewModel.getTVViewModelCurrent()
|
// if (mainFragment.tvListViewModel.getTVViewModelCurrent()
|
||||||
?.getItemPosition() == mainFragment.tvListViewModel.maxNum[mainFragment.selectedPosition] - 1
|
// ?.getItemPosition() == mainFragment.tvListViewModel.maxNum[mainFragment.selectedPosition] - 1
|
||||||
) {
|
// ) {
|
||||||
mainFragment.toFirstPosition()
|
// mainFragment.toFirstPosition()
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,9 @@ import android.content.Context
|
||||||
import android.content.SharedPreferences
|
import android.content.SharedPreferences
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.view.View
|
||||||
|
import android.view.ViewGroup
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.leanback.app.BrowseSupportFragment
|
import androidx.leanback.app.BrowseSupportFragment
|
||||||
import androidx.leanback.widget.ArrayObjectAdapter
|
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() {
|
fun toLastPosition() {
|
||||||
setSelectedPosition(
|
setSelectedPosition(
|
||||||
selectedPosition, false,
|
selectedPosition, false,
|
||||||
|
@ -244,6 +236,7 @@ class MainFragment : BrowseSupportFragment() {
|
||||||
rowViewHolder: RowPresenter.ViewHolder,
|
rowViewHolder: RowPresenter.ViewHolder,
|
||||||
row: Row
|
row: Row
|
||||||
) {
|
) {
|
||||||
|
Log.i(TAG, "onSingleTapConfirmed")
|
||||||
if (item is TVViewModel) {
|
if (item is TVViewModel) {
|
||||||
itemPosition = item.id.value!!
|
itemPosition = item.id.value!!
|
||||||
savePosition(itemPosition)
|
savePosition(itemPosition)
|
||||||
|
@ -261,17 +254,7 @@ class MainFragment : BrowseSupportFragment() {
|
||||||
itemViewHolder: Presenter.ViewHolder?, item: Any?,
|
itemViewHolder: Presenter.ViewHolder?, item: Any?,
|
||||||
rowViewHolder: RowPresenter.ViewHolder, row: Row
|
rowViewHolder: RowPresenter.ViewHolder, row: Row
|
||||||
) {
|
) {
|
||||||
if (itemViewHolder == null) {
|
Log.i(TAG, "onSingleTapConfirmed1111")
|
||||||
view?.post {
|
|
||||||
val tvViewModel = tvListViewModel.getTVViewModel(itemPosition)
|
|
||||||
if (tvViewModel != null) {
|
|
||||||
setSelectedPosition(
|
|
||||||
tvViewModel.getRowPosition(), false,
|
|
||||||
SelectItemViewHolderTask(tvViewModel.getItemPosition())
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (item is TVViewModel) {
|
if (item is TVViewModel) {
|
||||||
tvListViewModel.setItemPositionCurrent(item.id.value!!)
|
tvListViewModel.setItemPositionCurrent(item.id.value!!)
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,8 @@ import android.view.ViewGroup
|
||||||
import androidx.annotation.OptIn
|
import androidx.annotation.OptIn
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.media3.common.MediaItem
|
import androidx.media3.common.MediaItem
|
||||||
|
import androidx.media3.common.Player
|
||||||
|
import androidx.media3.common.VideoSize
|
||||||
import androidx.media3.common.util.UnstableApi
|
import androidx.media3.common.util.UnstableApi
|
||||||
import androidx.media3.exoplayer.ExoPlayer
|
import androidx.media3.exoplayer.ExoPlayer
|
||||||
import androidx.media3.ui.PlayerView
|
import androidx.media3.ui.PlayerView
|
||||||
|
@ -15,7 +17,7 @@ import com.lizongying.mytv.databinding.PlayerBinding
|
||||||
import com.lizongying.mytv.models.TVViewModel
|
import com.lizongying.mytv.models.TVViewModel
|
||||||
|
|
||||||
|
|
||||||
class PlaybackFragment : Fragment() {
|
class PlayerFragment : Fragment() {
|
||||||
|
|
||||||
private var lastVideoUrl: String = ""
|
private var lastVideoUrl: String = ""
|
||||||
|
|
||||||
|
@ -52,6 +54,14 @@ class PlaybackFragment : Fragment() {
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
playerView!!.player?.playWhenReady = true
|
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 {
|
playerView!!.player?.run {
|
|
@ -84,7 +84,6 @@ CGTN 纪录频道,https://livedoc.cgtn.com/500d/prog_index.m3u8,https://resource
|
||||||
三沙卫视,https://pullsstv90080111.ssws.tv/live/SSTV20220729.m3u8
|
三沙卫视,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://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://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
|
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(",")) {
|
if (!i.contains(",")) {
|
||||||
channel = i.trim()
|
channel = i.trim()
|
||||||
|
if (channel == "移动专区") {
|
||||||
|
break
|
||||||
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
val p = i.split(",")
|
val p = i.split(",")
|
||||||
|
|
|
@ -2,11 +2,13 @@ package com.lizongying.mytv.api
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.SharedPreferences
|
import android.content.SharedPreferences
|
||||||
|
import android.util.Log
|
||||||
import com.lizongying.mytv.Encryptor
|
import com.lizongying.mytv.Encryptor
|
||||||
import com.lizongying.mytv.MainActivity
|
import com.lizongying.mytv.MainActivity
|
||||||
import com.lizongying.mytv.models.TVViewModel
|
import com.lizongying.mytv.models.TVViewModel
|
||||||
import java.util.Date
|
import java.util.Date
|
||||||
import kotlin.math.floor
|
import kotlin.math.floor
|
||||||
|
import kotlin.random.Random
|
||||||
|
|
||||||
class YSP(var context: Context) {
|
class YSP(var context: Context) {
|
||||||
private var cnlid = ""
|
private var cnlid = ""
|
||||||
|
@ -87,14 +89,8 @@ class YSP(var context: Context) {
|
||||||
|
|
||||||
fun generateGuid(): String {
|
fun generateGuid(): String {
|
||||||
val timestamp = (System.currentTimeMillis()).toString(36)
|
val timestamp = (System.currentTimeMillis()).toString(36)
|
||||||
val originalString = Math.random().toString()
|
val randomPart = Random.nextLong().toString(36).take(11)
|
||||||
val resultString = if (originalString.startsWith("0.")) {
|
return timestamp + "_" + "0".repeat(11 - randomPart.length) + randomPart
|
||||||
originalString.substring(2)
|
|
||||||
} else {
|
|
||||||
originalString
|
|
||||||
}
|
|
||||||
val randomPart = resultString.toLong().toString(36)
|
|
||||||
return timestamp + "_" + randomPart
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getGuid(): String {
|
fun getGuid(): String {
|
||||||
|
|
|
@ -10,7 +10,6 @@ import androidx.media3.common.MediaItem
|
||||||
import androidx.media3.common.util.UnstableApi
|
import androidx.media3.common.util.UnstableApi
|
||||||
import androidx.media3.datasource.DefaultHttpDataSource
|
import androidx.media3.datasource.DefaultHttpDataSource
|
||||||
import androidx.media3.exoplayer.hls.HlsMediaSource
|
import androidx.media3.exoplayer.hls.HlsMediaSource
|
||||||
import com.lizongying.mytv.CustomLoadErrorHandlingPolicy
|
|
||||||
import com.lizongying.mytv.TV
|
import com.lizongying.mytv.TV
|
||||||
import com.lizongying.mytv.proto.Ysp.cn.yangshipin.omstv.common.proto.programModel.Program
|
import com.lizongying.mytv.proto.Ysp.cn.yangshipin.omstv.common.proto.programModel.Program
|
||||||
import java.util.Date
|
import java.util.Date
|
||||||
|
@ -426,9 +425,7 @@ class TVViewModel(private var tv: TV) : ViewModel() {
|
||||||
val httpDataSource = DefaultHttpDataSource.Factory()
|
val httpDataSource = DefaultHttpDataSource.Factory()
|
||||||
mHeaders?.let { httpDataSource.setDefaultRequestProperties(it) }
|
mHeaders?.let { httpDataSource.setDefaultRequestProperties(it) }
|
||||||
|
|
||||||
return HlsMediaSource.Factory(httpDataSource).setLoadErrorHandlingPolicy(
|
return HlsMediaSource.Factory(httpDataSource).createMediaSource(
|
||||||
CustomLoadErrorHandlingPolicy(mMinimumLoadableRetryCount)
|
|
||||||
).createMediaSource(
|
|
||||||
MediaItem.fromUri(
|
MediaItem.fromUri(
|
||||||
Uri.parse(videoUrl)
|
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 |
|
@ -4,11 +4,14 @@
|
||||||
android:id="@+id/player_fragment"
|
android:id="@+id/player_fragment"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
|
android:background="@color/black"
|
||||||
android:keepScreenOn="true">
|
android:keepScreenOn="true">
|
||||||
|
|
||||||
<androidx.media3.ui.PlayerView
|
<androidx.media3.ui.PlayerView
|
||||||
android:id="@+id/player_view"
|
android:id="@+id/player_view"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
app:resize_mode="fill"
|
||||||
app:use_controller="false" />
|
app:use_controller="false" />
|
||||||
</FrameLayout>
|
</FrameLayout>
|
|
@ -1,3 +1,4 @@
|
||||||
<resources>
|
<resources>
|
||||||
<color name="fastlane_background">#30000000</color>
|
<color name="fastlane_background">#30000000</color>
|
||||||
|
<color name="black">#000</color>
|
||||||
</resources>
|
</resources>
|
|
@ -1,3 +1,3 @@
|
||||||
<resources>
|
<resources>
|
||||||
<string name="app_name">My TV</string>
|
<string name="app_name">我的电视</string>
|
||||||
</resources>
|
</resources>
|
|
@ -5,5 +5,4 @@
|
||||||
<item name="browsePaddingEnd">11dp</item>
|
<item name="browsePaddingEnd">11dp</item>
|
||||||
<item name="browseRowsMarginTop">54dp</item>
|
<item name="browseRowsMarginTop">54dp</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
Loading…
Reference in New Issue