Skip to content

Commit

Permalink
fix video size on phone
Browse files Browse the repository at this point in the history
  • Loading branch information
lizongying committed Dec 26, 2023
1 parent 657b871 commit bb4fd56
Show file tree
Hide file tree
Showing 14 changed files with 60 additions and 89 deletions.
6 changes: 3 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down

This file was deleted.

53 changes: 28 additions & 25 deletions app/src/main/java/com/lizongying/mytv/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()

Expand All @@ -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)
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -240,49 +243,49 @@ 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
// )
// }
}
}

KeyEvent.KEYCODE_DPAD_DOWN -> {
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
// }
}
}

KeyEvent.KEYCODE_DPAD_LEFT -> {
if (mainFragment.isHidden) {
prevSource()
} else {
if (mainFragment.tvListViewModel.getTVViewModelCurrent()
?.getItemPosition() == 0
) {
// mainFragment.toLastPosition()
hideMainFragment()
}
// if (mainFragment.tvListViewModel.getTVViewModelCurrent()
// ?.getItemPosition() == 0
// ) {
//// mainFragment.toLastPosition()
// hideMainFragment()
// }
}
}

KeyEvent.KEYCODE_DPAD_RIGHT -> {
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()
// }
}
}
}
Expand Down
27 changes: 5 additions & 22 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,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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand All @@ -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!!)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@ 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
import com.lizongying.mytv.databinding.PlayerBinding
import com.lizongying.mytv.models.TVViewModel


class PlaybackFragment : Fragment() {
class PlayerFragment : Fragment() {

private var lastVideoUrl: String = ""

Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/java/com/lizongying/mytv/TVList.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(",")
Expand Down
12 changes: 4 additions & 8 deletions app/src/main/java/com/lizongying/mytv/api/YSP.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""
Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 1 addition & 4 deletions app/src/main/java/com/lizongying/mytv/models/TVViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
)
Expand Down
Binary file added app/src/main/res/drawable/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed app/src/main/res/drawable/tv.png
Binary file not shown.
3 changes: 3 additions & 0 deletions app/src/main/res/layout/player.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
1 change: 1 addition & 0 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<resources>
<color name="fastlane_background">#30000000</color>
<color name="black">#000</color>
</resources>
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<resources>
<string name="app_name">My TV</string>
<string name="app_name">我的电视</string>
</resources>
1 change: 0 additions & 1 deletion app/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@
<item name="browsePaddingEnd">11dp</item>
<item name="browseRowsMarginTop">54dp</item>
</style>

</resources>

0 comments on commit bb4fd56

Please sign in to comment.