Skip to content

Commit

Permalink
✨ 节目进度
Browse files Browse the repository at this point in the history
  • Loading branch information
yaoxieyoulei committed Apr 25, 2024
1 parent 2e288f9 commit b149ba6
Show file tree
Hide file tree
Showing 10 changed files with 115 additions and 38 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
</div>
<p>使用Android原生开发的电视直播软件</p>

<img src="https://github.com/yaoxieyoulei/my_tv/blob/main/screenshots/shot_1.png?raw=true" width="96%"/>
<img src="./screenshots/Screenshot_panel.png" width="96%"/>
<br/>
<img src="https://github.com/yaoxieyoulei/my_tv/blob/main/screenshots/shot_3.png?raw=true" width="48%"/>
<img src="https://github.com/yaoxieyoulei/my_tv/blob/main/screenshots/shot_2.png?raw=true" width="48%"/>
<img src="./screenshots/Screenshot_temp_panel.png" width="48%"/>
<img src="./screenshots/Screenshot_settings.png" width="48%"/>
</div>

## 使用
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,7 @@ data class EpgProgramme(
) {
companion object {
fun EpgProgramme.isLive() = System.currentTimeMillis() in startAt..<endAt
fun EpgProgramme.progress() =
(System.currentTimeMillis() - startAt).toFloat() / (endAt - startAt)
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package top.yogiczy.mytv.ui.screens.panel.components

import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.fillMaxSize
Expand All @@ -18,6 +20,7 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha
Expand All @@ -40,6 +43,7 @@ import top.yogiczy.mytv.data.entities.Epg
import top.yogiczy.mytv.data.entities.Epg.Companion.currentProgrammes
import top.yogiczy.mytv.data.entities.EpgProgramme
import top.yogiczy.mytv.data.entities.EpgProgramme.Companion.isLive
import top.yogiczy.mytv.data.entities.EpgProgramme.Companion.progress
import top.yogiczy.mytv.data.entities.EpgProgrammeList
import top.yogiczy.mytv.data.entities.Iptv
import top.yogiczy.mytv.tvmaterial.StandardDialog
Expand All @@ -58,6 +62,7 @@ fun PanelIptvItem(
iptv: Iptv = Iptv.EMPTY,
onIptvSelected: () -> Unit = {},
epg: Epg? = null,
currentProgramme: EpgProgramme? = epg?.currentProgrammes()?.now,
initialFocused: Boolean = false,
onFavoriteChange: () -> Unit = {},
) {
Expand All @@ -75,6 +80,7 @@ fun PanelIptvItem(
}

Card(
onClick = { },
modifier = modifier
.width(130.dp)
.height(54.dp)
Expand Down Expand Up @@ -109,27 +115,44 @@ fun PanelIptvItem(
focusedContainerColor = MaterialTheme.colorScheme.onBackground,
focusedContentColor = MaterialTheme.colorScheme.background,
),
onClick = { },
) {
Column(
modifier = Modifier
.fillMaxSize()
// .align(Alignment.Start)
.padding(horizontal = 8.dp, vertical = 4.dp),
verticalArrangement = Arrangement.SpaceAround
) {
Text(
text = iptv.name,
style = MaterialTheme.typography.bodyLarge,
maxLines = 1,
)
Box {
Column(
modifier = Modifier
.fillMaxSize()
.padding(horizontal = 8.dp, vertical = 4.dp),
verticalArrangement = Arrangement.SpaceAround
) {
Text(
text = iptv.name,
style = MaterialTheme.typography.bodyLarge,
maxLines = 1,
)

Text(
text = epg?.currentProgrammes()?.now?.title ?: "",
style = MaterialTheme.typography.labelSmall,
maxLines = 1,
modifier = Modifier.alpha(0.8f),
)
Text(
text = currentProgramme?.title ?: "",
style = MaterialTheme.typography.labelSmall,
maxLines = 1,
modifier = Modifier.alpha(0.8f),
)

}

// 节目进度条
if (SP.uiShowEpgProgrammeProgress && currentProgramme != null) {
Box(
modifier = Modifier
.align(Alignment.BottomStart)
.fillMaxWidth(currentProgramme.progress())
.height(3.dp)
.background(
if (isFocused)
MaterialTheme.colorScheme.surface.copy(alpha = 0.8f)
else
MaterialTheme.colorScheme.onSurface.copy(alpha = 0.8f)
),
)
}
}
}

Expand All @@ -149,10 +172,20 @@ private fun PanelIptvItemPreview() {
) {
PanelIptvItem(
iptv = Iptv.EXAMPLE,
currentProgramme = EpgProgramme(
startAt = System.currentTimeMillis() - 100000,
endAt = System.currentTimeMillis() + 200000,
title = "新闻联播",
),
)

PanelIptvItem(
iptv = Iptv.EXAMPLE,
currentProgramme = EpgProgramme(
startAt = System.currentTimeMillis() - 100000,
endAt = System.currentTimeMillis() + 200000,
title = "新闻联播",
),
initialFocused = true,
)
}
Expand Down Expand Up @@ -237,13 +270,19 @@ private fun PanelIptvItemEpgDialogPreview() {
EpgProgrammeList(
listOf(
EpgProgramme(
startAt = 1713861600000, endAt = 1713865200000, title = "新闻联播"
startAt = System.currentTimeMillis() - 200000,
endAt = System.currentTimeMillis() - 100000,
title = "新闻联播"
),
EpgProgramme(
startAt = 1714016065000, endAt = 1714026265000, title = "新闻联播1"
startAt = System.currentTimeMillis() - 100000,
endAt = System.currentTimeMillis() + 100000,
title = "新闻联播1"
),
EpgProgramme(
startAt = 1713861600000, endAt = 1713865200000, title = "新闻联播"
startAt = System.currentTimeMillis() + 100000,
endAt = System.currentTimeMillis() + 200000,
title = "新闻联播2"
),
)
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.view.SurfaceView
import androidx.annotation.OptIn
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
Expand All @@ -12,6 +13,7 @@ import androidx.compose.runtime.mutableFloatStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.viewinterop.AndroidView
Expand All @@ -23,7 +25,6 @@ import androidx.media3.common.util.UnstableApi
import androidx.media3.exoplayer.DecoderReuseEvaluation
import androidx.media3.exoplayer.ExoPlayer
import androidx.media3.exoplayer.analytics.AnalyticsListener
import androidx.media3.exoplayer.util.EventLogger
import top.yogiczy.mytv.ui.rememberChildPadding
import top.yogiczy.mytv.ui.screens.video.components.VideoDetailInfo
import top.yogiczy.mytv.ui.utils.SP
Expand All @@ -37,9 +38,11 @@ fun VideoScreen(
val context = LocalContext.current
val childPadding = rememberChildPadding()

Box {
Box(modifier = modifier.fillMaxSize()) {
AndroidView(
modifier = modifier.aspectRatio(state.aspectRatio),
modifier = Modifier
.align(Alignment.Center)
.aspectRatio(state.aspectRatio),
factory = {
// PlayerView 切换视频时黑屏闪烁,使用 SurfaceView 代替
SurfaceView(context)
Expand Down Expand Up @@ -161,7 +164,6 @@ fun rememberExoPlayerState(

DisposableEffect(Unit) {
exoPlayer.addListener(listener)
exoPlayer.addAnalyticsListener(EventLogger())
exoPlayer.addAnalyticsListener(metadataListener)

onDispose {
Expand Down
19 changes: 13 additions & 6 deletions app/src/main/java/top/yogiczy/mytv/ui/utils/HttpServer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ object HttpServer : Loggable() {

appBootLaunch = SP.appBootLaunch,

debugShowFps = SP.debugShowFps,
debugShowPlayerInfo = SP.debugShowPlayerInfo,

iptvChannelChangeFlip = SP.iptvChannelChangeFlip,
iptvSourceSimplify = SP.iptvSourceSimplify,
iptvSourceCachedAt = SP.iptvSourceCachedAt,
Expand All @@ -102,8 +105,7 @@ object HttpServer : Loggable() {
epgXmlUrl = SP.epgXmlUrl,
epgRefreshTimeThreshold = SP.epgRefreshTimeThreshold,

debugShowFps = SP.debugShowFps,
debugShowPlayerInfo = SP.debugShowPlayerInfo,
uiShowEpgProgrammeProgress = SP.uiShowEpgProgrammeProgress,
)
)
)
Expand All @@ -117,6 +119,9 @@ object HttpServer : Loggable() {
val body = request.getBody<JSONObjectBody>().get()
SP.appBootLaunch = body.get("appBootLaunch") as Boolean

SP.debugShowFps = body.get("debugShowFps").toString().toBoolean()
SP.debugShowPlayerInfo = body.get("debugShowPlayerInfo").toString().toBoolean()

SP.iptvChannelChangeFlip = body.get("iptvChannelChangeFlip").toString().toBoolean()
SP.iptvSourceSimplify = body.get("iptvSourceSimplify").toString().toBoolean()
SP.iptvSourceCachedAt = body.get("iptvSourceCachedAt").toString().toLong()
Expand All @@ -129,8 +134,8 @@ object HttpServer : Loggable() {
SP.epgXmlUrl = body.get("epgXmlUrl").toString()
SP.epgRefreshTimeThreshold = body.get("epgRefreshTimeThreshold").toString().toInt()

SP.debugShowFps = body.get("debugShowFps").toString().toBoolean()
SP.debugShowPlayerInfo = body.get("debugShowPlayerInfo").toString().toBoolean()
SP.uiShowEpgProgrammeProgress =
body.get("uiShowEpgProgrammeProgress").toString().toBoolean()

wrapResponse(response).send("success")
}
Expand Down Expand Up @@ -198,6 +203,9 @@ private data class AllSettings(

val appBootLaunch: Boolean,

val debugShowFps: Boolean,
val debugShowPlayerInfo: Boolean,

val iptvChannelChangeFlip: Boolean,
val iptvSourceSimplify: Boolean,
val iptvSourceCachedAt: Long,
Expand All @@ -210,6 +218,5 @@ private data class AllSettings(
val epgXmlUrl: String,
val epgRefreshTimeThreshold: Int,

val debugShowFps: Boolean,
val debugShowPlayerInfo: Boolean,
val uiShowEpgProgrammeProgress: Boolean,
)
14 changes: 12 additions & 2 deletions app/src/main/java/top/yogiczy/mytv/ui/utils/SP.kt
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ object SP {
/** 直播源历史列表 */
IPTV_SOURCE_URL_HISTORY_LIST,

/** 直播源频道收藏 */
/** 直播源频道收藏列表 */
IPTV_CHANNEL_FAVORITE_LIST,

/** ==================== 节目单 ==================== */
Expand All @@ -76,6 +76,10 @@ object SP {

/** epg历史列表 */
EPG_XML_URL_HISTORY_LIST,

/** ==================== 界面 ==================== */
/** 显示节目进度 */
UI_SHOW_EPG_PROGRAMME_PROGRESS,
}

/** ==================== 应用 ==================== */
Expand Down Expand Up @@ -142,7 +146,7 @@ object SP {
get() = sp.getStringSet(KEY.IPTV_SOURCE_URL_HISTORY_LIST.name, emptySet()) ?: emptySet()
set(value) = sp.edit().putStringSet(KEY.IPTV_SOURCE_URL_HISTORY_LIST.name, value).apply()

/** 直播源频道收藏 */
/** 直播源频道收藏列表 */
var iptvChannelFavoriteList: Set<String>
get() = sp.getStringSet(KEY.IPTV_CHANNEL_FAVORITE_LIST.name, emptySet()) ?: emptySet()
set(value) = sp.edit().putStringSet(KEY.IPTV_CHANNEL_FAVORITE_LIST.name, value).apply()
Expand Down Expand Up @@ -177,4 +181,10 @@ object SP {
var epgXmlUrlHistoryList: Set<String>
get() = sp.getStringSet(KEY.EPG_XML_URL_HISTORY_LIST.name, emptySet()) ?: emptySet()
set(value) = sp.edit().putStringSet(KEY.EPG_XML_URL_HISTORY_LIST.name, value).apply()

/** ==================== 界面 ==================== */
/** 显示节目进度 */
var uiShowEpgProgrammeProgress: Boolean
get() = sp.getBoolean(KEY.UI_SHOW_EPG_PROGRAMME_PROGRESS.name, false)
set(value) = sp.edit().putBoolean(KEY.UI_SHOW_EPG_PROGRAMME_PROGRESS.name, value).apply()
}
19 changes: 18 additions & 1 deletion app/src/main/res/raw/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,15 @@
</van-cell>
</van-cell-group>

<van-cell-group inset title="界面">
<van-cell label="在频道项底部显示当前节目进度条" title="显示节目进度">
<template #extra>
<van-switch @change="confirmSettings" size="24"
v-model="settings.uiShowEpgProgrammeProgress" />
</template>
</van-cell>
</van-cell-group>

<van-cell-group inset title="调试">
<van-cell label="在屏幕左上角显示fps和柱状图" title="显示fps">
<template #extra>
Expand All @@ -196,6 +205,14 @@
</template>
</van-cell>
</van-cell-group>

<!-- <van-tabbar>
<van-tabbar-item name="home" icon="tv-o">直播源</van-tabbar-item>
<van-tabbar-item name="search" icon="list-switch">节目单</van-tabbar-item>
<van-tabbar-item name="friends" icon="brush-o">界面</van-tabbar-item>
<van-tabbar-item name="setting" icon="setting-o">应用</van-tabbar-item>
<van-tabbar-item name="setting" icon="bulb-o">调试</van-tabbar-item>
</van-tabbar> -->
</template>

<van-empty image="network" v-else />
Expand All @@ -205,7 +222,7 @@
<script>
const { createApp, ref, onMounted, watch, nextTick } = Vue

const baseUrl = "http://127.0.0.1:10481"
const baseUrl = ""

async function requestApi(url, config) {
const resp = await fetch(`${baseUrl}${url}`, config)
Expand Down
Binary file added screenshots/Screenshot_panel.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 added screenshots/Screenshot_settings.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 added screenshots/Screenshot_temp_panel.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit b149ba6

Please sign in to comment.