mirror of
https://github.com/lizongying/my-tv.git
synced 2026-10-26 22:26:29 +08:00
auto-startup
This commit is contained in:
@@ -113,4 +113,8 @@ dependencies {
|
|||||||
implementation 'com.github.bumptech.glide:glide:4.11.0'
|
implementation 'com.github.bumptech.glide:glide:4.11.0'
|
||||||
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.6.2"
|
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.6.2"
|
||||||
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.8.0-RC")
|
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.8.0-RC")
|
||||||
|
|
||||||
|
implementation 'com.google.android.exoplayer:exoplayer-ui:2.13.3'
|
||||||
|
implementation 'com.google.android.exoplayer:exoplayer-core:2.13.3'
|
||||||
|
implementation 'com.google.android.exoplayer:exoplayer-hls:2.13.3'
|
||||||
}
|
}
|
||||||
@@ -7,6 +7,7 @@
|
|||||||
android:name="android.software.leanback"
|
android:name="android.software.leanback"
|
||||||
android:required="true" />
|
android:required="true" />
|
||||||
<uses-permission android:name="android.permission.INTERNET" />
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
|
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
||||||
<application
|
<application
|
||||||
android:allowBackup="true"
|
android:allowBackup="true"
|
||||||
android:largeHeap="true"
|
android:largeHeap="true"
|
||||||
@@ -29,5 +30,13 @@
|
|||||||
<category android:name="android.intent.category.LAUNCHER" />
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
<receiver
|
||||||
|
android:name=".BootReceiver"
|
||||||
|
android:exported="true">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
||||||
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
|
</intent-filter>
|
||||||
|
</receiver>
|
||||||
</application>
|
</application>
|
||||||
</manifest>
|
</manifest>
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package com.lizongying.mytv
|
||||||
|
|
||||||
|
import android.content.BroadcastReceiver
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.Intent
|
||||||
|
|
||||||
|
class BootReceiver : BroadcastReceiver() {
|
||||||
|
|
||||||
|
override fun onReceive(context: Context, intent: Intent) {
|
||||||
|
val sp = context.getSharedPreferences("MainActivity", Context.MODE_PRIVATE)
|
||||||
|
if (sp.getBoolean(MainActivity.BOOT_STARTUP, true)) {
|
||||||
|
context.startActivity(
|
||||||
|
Intent(context, MainActivity::class.java)
|
||||||
|
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -47,6 +47,7 @@ class MainActivity : FragmentActivity() {
|
|||||||
lateinit var sharedPref: SharedPreferences
|
lateinit var sharedPref: SharedPreferences
|
||||||
private var channelReversal = false
|
private var channelReversal = false
|
||||||
private var channelNum = true
|
private var channelNum = true
|
||||||
|
private var bootStartup = true
|
||||||
|
|
||||||
private var versionName = ""
|
private var versionName = ""
|
||||||
|
|
||||||
@@ -83,6 +84,7 @@ class MainActivity : FragmentActivity() {
|
|||||||
sharedPref = getPreferences(Context.MODE_PRIVATE)
|
sharedPref = getPreferences(Context.MODE_PRIVATE)
|
||||||
channelReversal = sharedPref.getBoolean(CHANNEL_REVERSAL, channelReversal)
|
channelReversal = sharedPref.getBoolean(CHANNEL_REVERSAL, channelReversal)
|
||||||
channelNum = sharedPref.getBoolean(CHANNEL_NUM, channelNum)
|
channelNum = sharedPref.getBoolean(CHANNEL_NUM, channelNum)
|
||||||
|
bootStartup = sharedPref.getBoolean(BOOT_STARTUP, bootStartup)
|
||||||
|
|
||||||
val packageInfo = getPackageInfo()
|
val packageInfo = getPackageInfo()
|
||||||
versionName = packageInfo.versionName
|
versionName = packageInfo.versionName
|
||||||
@@ -91,7 +93,7 @@ class MainActivity : FragmentActivity() {
|
|||||||
} else {
|
} else {
|
||||||
packageInfo.versionCode.toLong()
|
packageInfo.versionCode.toLong()
|
||||||
}
|
}
|
||||||
settingFragment = SettingFragment(versionName, versionCode, channelReversal, channelNum)
|
settingFragment = SettingFragment(versionName, versionCode, channelReversal, channelNum, bootStartup)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun showInfoFragment(tvViewModel: TVViewModel) {
|
fun showInfoFragment(tvViewModel: TVViewModel) {
|
||||||
@@ -249,6 +251,14 @@ class MainActivity : FragmentActivity() {
|
|||||||
this.channelNum = channelNum
|
this.channelNum = channelNum
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun saveBootStartup(bootStartup: Boolean) {
|
||||||
|
with(sharedPref.edit()) {
|
||||||
|
putBoolean(BOOT_STARTUP, bootStartup)
|
||||||
|
apply()
|
||||||
|
}
|
||||||
|
this.bootStartup = bootStartup
|
||||||
|
}
|
||||||
|
|
||||||
private fun showSetting() {
|
private fun showSetting() {
|
||||||
if (!mainFragment.isHidden) {
|
if (!mainFragment.isHidden) {
|
||||||
return
|
return
|
||||||
@@ -537,5 +547,6 @@ class MainActivity : FragmentActivity() {
|
|||||||
private const val TAG = "MainActivity"
|
private const val TAG = "MainActivity"
|
||||||
private const val CHANNEL_REVERSAL = "channel_reversal"
|
private const val CHANNEL_REVERSAL = "channel_reversal"
|
||||||
private const val CHANNEL_NUM = "channel_num"
|
private const val CHANNEL_NUM = "channel_num"
|
||||||
|
const val BOOT_STARTUP = "boot_startup"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3,6 +3,8 @@ package com.lizongying.mytv
|
|||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
|
import android.view.SurfaceHolder
|
||||||
|
import android.view.SurfaceView
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.view.ViewTreeObserver
|
import android.view.ViewTreeObserver
|
||||||
@@ -15,23 +17,39 @@ 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
|
||||||
|
import com.google.android.exoplayer2.SimpleExoPlayer
|
||||||
import com.lizongying.mytv.databinding.PlayerBinding
|
import com.lizongying.mytv.databinding.PlayerBinding
|
||||||
import com.lizongying.mytv.models.TVViewModel
|
import com.lizongying.mytv.models.TVViewModel
|
||||||
|
|
||||||
|
|
||||||
class PlayerFragment : Fragment() {
|
class PlayerFragment : Fragment(), SurfaceHolder.Callback {
|
||||||
|
|
||||||
private var _binding: PlayerBinding? = null
|
private var _binding: PlayerBinding? = null
|
||||||
private var playerView: PlayerView? = null
|
private var playerView: PlayerView? = null
|
||||||
private var tvViewModel: TVViewModel? = null
|
private var tvViewModel: TVViewModel? = null
|
||||||
private val aspectRatio = 16f / 9f
|
private val aspectRatio = 16f / 9f
|
||||||
|
|
||||||
|
|
||||||
|
private lateinit var surfaceView: SurfaceView
|
||||||
|
private lateinit var surfaceHolder: SurfaceHolder
|
||||||
|
private var exoPlayer: SimpleExoPlayer? = null
|
||||||
|
|
||||||
override fun onCreateView(
|
override fun onCreateView(
|
||||||
inflater: LayoutInflater, container: ViewGroup?,
|
inflater: LayoutInflater, container: ViewGroup?,
|
||||||
savedInstanceState: Bundle?
|
savedInstanceState: Bundle?
|
||||||
): View {
|
): View {
|
||||||
_binding = PlayerBinding.inflate(inflater, container, false)
|
_binding = PlayerBinding.inflate(inflater, container, false)
|
||||||
playerView = _binding!!.playerView
|
|
||||||
|
if (Utils.isTmallDevice()) {
|
||||||
|
_binding!!.playerView.visibility = View.GONE
|
||||||
|
surfaceView = _binding!!.surfaceView
|
||||||
|
surfaceHolder = surfaceView.holder
|
||||||
|
surfaceHolder.addCallback(this)
|
||||||
|
} else {
|
||||||
|
_binding!!.surfaceView.visibility = View.GONE
|
||||||
|
playerView = _binding!!.playerView
|
||||||
|
}
|
||||||
|
|
||||||
playerView?.viewTreeObserver?.addOnGlobalLayoutListener(object :
|
playerView?.viewTreeObserver?.addOnGlobalLayoutListener(object :
|
||||||
ViewTreeObserver.OnGlobalLayoutListener {
|
ViewTreeObserver.OnGlobalLayoutListener {
|
||||||
override fun onGlobalLayout() {
|
override fun onGlobalLayout() {
|
||||||
@@ -78,6 +96,10 @@ class PlayerFragment : Fragment() {
|
|||||||
setMediaItem(MediaItem.fromUri(tvViewModel.getVideoUrlCurrent()))
|
setMediaItem(MediaItem.fromUri(tvViewModel.getVideoUrlCurrent()))
|
||||||
prepare()
|
prepare()
|
||||||
}
|
}
|
||||||
|
exoPlayer?.run {
|
||||||
|
setMediaItem(com.google.android.exoplayer2.MediaItem.fromUri(tvViewModel.getVideoUrlCurrent()))
|
||||||
|
prepare()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onStart() {
|
override fun onStart() {
|
||||||
@@ -87,8 +109,11 @@ class PlayerFragment : Fragment() {
|
|||||||
Log.i(TAG, "replay")
|
Log.i(TAG, "replay")
|
||||||
playerView!!.player?.prepare()
|
playerView!!.player?.prepare()
|
||||||
playerView!!.player?.play()
|
playerView!!.player?.play()
|
||||||
} else {
|
}
|
||||||
Log.i(TAG, "playing")
|
if (exoPlayer?.isPlaying == false) {
|
||||||
|
Log.i(TAG, "replay")
|
||||||
|
exoPlayer?.prepare()
|
||||||
|
exoPlayer?.play()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,6 +127,9 @@ class PlayerFragment : Fragment() {
|
|||||||
if (playerView != null && playerView!!.player?.isPlaying == true) {
|
if (playerView != null && playerView!!.player?.isPlaying == true) {
|
||||||
playerView!!.player?.stop()
|
playerView!!.player?.stop()
|
||||||
}
|
}
|
||||||
|
if (exoPlayer?.isPlaying == true) {
|
||||||
|
exoPlayer?.stop()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
@@ -109,6 +137,7 @@ class PlayerFragment : Fragment() {
|
|||||||
if (playerView != null) {
|
if (playerView != null) {
|
||||||
playerView!!.player?.release()
|
playerView!!.player?.release()
|
||||||
}
|
}
|
||||||
|
exoPlayer?.release()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroyView() {
|
override fun onDestroyView() {
|
||||||
@@ -119,4 +148,16 @@ class PlayerFragment : Fragment() {
|
|||||||
companion object {
|
companion object {
|
||||||
private const val TAG = "PlaybackVideoFragment"
|
private const val TAG = "PlaybackVideoFragment"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun surfaceCreated(holder: SurfaceHolder) {
|
||||||
|
exoPlayer = SimpleExoPlayer.Builder(requireContext()).build()
|
||||||
|
exoPlayer?.setVideoSurfaceHolder(surfaceHolder)
|
||||||
|
exoPlayer?.playWhenReady = true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun surfaceChanged(holder: SurfaceHolder, format: Int, width: Int, height: Int) {
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun surfaceDestroyed(holder: SurfaceHolder) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -15,6 +15,7 @@ class SettingFragment(
|
|||||||
private val versionCode: Long,
|
private val versionCode: Long,
|
||||||
private val channelReversal: Boolean,
|
private val channelReversal: Boolean,
|
||||||
private val channelNum: Boolean,
|
private val channelNum: Boolean,
|
||||||
|
private val bootStartup: Boolean,
|
||||||
) :
|
) :
|
||||||
DialogFragment() {
|
DialogFragment() {
|
||||||
|
|
||||||
@@ -49,6 +50,12 @@ class SettingFragment(
|
|||||||
(activity as MainActivity).saveChannelNum(isChecked)
|
(activity as MainActivity).saveChannelNum(isChecked)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val switchBootStartup = _binding?.switchBootStartup
|
||||||
|
switchBootStartup?.isChecked = bootStartup
|
||||||
|
switchBootStartup?.setOnCheckedChangeListener { _, isChecked ->
|
||||||
|
(activity as MainActivity).saveBootStartup(isChecked)
|
||||||
|
}
|
||||||
|
|
||||||
updateManager = UpdateManager(context, this, versionCode)
|
updateManager = UpdateManager(context, this, versionCode)
|
||||||
_binding?.checkVersion?.setOnClickListener(OnClickListenerCheckVersion(updateManager))
|
_binding?.checkVersion?.setOnClickListener(OnClickListenerCheckVersion(updateManager))
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package com.lizongying.mytv
|
|||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.res.Resources
|
import android.content.res.Resources
|
||||||
|
import android.os.Build
|
||||||
import android.util.TypedValue
|
import android.util.TypedValue
|
||||||
import com.google.gson.Gson
|
import com.google.gson.Gson
|
||||||
import com.lizongying.mytv.api.TimeResponse
|
import com.lizongying.mytv.api.TimeResponse
|
||||||
@@ -74,6 +75,8 @@ object Utils {
|
|||||||
).toInt()
|
).toInt()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun isTmallDevice() = Build.MANUFACTURER.equals("Tmall", ignoreCase = true)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取可读写的目录
|
* 获取可读写的目录
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ class ApiClient {
|
|||||||
private val protoUrl = "https://capi.yangshipin.cn/"
|
private val protoUrl = "https://capi.yangshipin.cn/"
|
||||||
private val traceUrl = "https://btrace.yangshipin.cn/"
|
private val traceUrl = "https://btrace.yangshipin.cn/"
|
||||||
|
|
||||||
|
|
||||||
private var okHttpClient = getUnsafeOkHttpClient()
|
private var okHttpClient = getUnsafeOkHttpClient()
|
||||||
|
|
||||||
val yspApiService: YSPApiService by lazy {
|
val yspApiService: YSPApiService by lazy {
|
||||||
|
|||||||
@@ -64,6 +64,12 @@
|
|||||||
android:layout_marginTop="10dp"
|
android:layout_marginTop="10dp"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content" />
|
android:layout_height="wrap_content" />
|
||||||
|
<Switch
|
||||||
|
android:id="@+id/switch_boot_startup"
|
||||||
|
android:text="@string/title_boot_startup"
|
||||||
|
android:layout_marginTop="10dp"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
<ImageView
|
<ImageView
|
||||||
android:layout_width="300dp"
|
android:layout_width="300dp"
|
||||||
|
|||||||
@@ -7,6 +7,14 @@
|
|||||||
android:background="@color/black"
|
android:background="@color/black"
|
||||||
android:keepScreenOn="true">
|
android:keepScreenOn="true">
|
||||||
|
|
||||||
|
<SurfaceView
|
||||||
|
android:id="@+id/surface_view"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
app:resize_mode="fill"
|
||||||
|
app:use_controller="false" />
|
||||||
|
|
||||||
<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"
|
||||||
|
|||||||
@@ -3,4 +3,5 @@
|
|||||||
<string name="title_channel_reversal">换台反转</string>
|
<string name="title_channel_reversal">换台反转</string>
|
||||||
<string name="title_channel_num">数字选台</string>
|
<string name="title_channel_num">数字选台</string>
|
||||||
<string name="check_version">检查更新</string>
|
<string name="check_version">检查更新</string>
|
||||||
|
<string name="title_boot_startup">开机自启</string>
|
||||||
</resources>
|
</resources>
|
||||||
Reference in New Issue
Block a user