Skip to content

Commit

Permalink
support stmp
Browse files Browse the repository at this point in the history
  • Loading branch information
lizongying committed Nov 30, 2024
1 parent b02c038 commit 52c7b8a
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 16 deletions.
4 changes: 4 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## 更新日誌

### v1.3.8.1

* 支持rtmp

### v1.3.8.0

* 優化遠程配置
Expand Down
5 changes: 3 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ plugins {

android {
namespace = "com.lizongying.mytv0"
compileSdk = 34
compileSdk = 35

defaultConfig {
applicationId = "com.lizongying.mytv0"
minSdk = 21
targetSdk = 34
targetSdk = 35
versionCode = getVersionCode()
versionName = getVersionName()
}
Expand Down Expand Up @@ -148,6 +148,7 @@ dependencies {
implementation(libs.media3.exoplayer.dash)
implementation(libs.media3.exoplayer.rtsp)
implementation(libs.media3.datasource.okhttp)
implementation(libs.media3.datasource.rtmp)

implementation(libs.nanohttpd)
implementation(libs.gua64)
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/lizongying/mytv0/Ext.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ val Context.appVersionCode: Long
* Return the version name of the app which is defined in build.gradle.
* eg:1.0.0
*/
val Context.appVersionName: String get() = packageInfo.versionName
val Context.appVersionName: String get() = packageInfo.versionName!!

val Context.appSignature: String
get() {
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/lizongying/mytv0/MainViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,14 @@ class MainViewModel : ViewModel() {
}

cacheConfig = getCache()
Log.i(TAG, "cacheConfig $cacheConfig")

if (cacheConfig.isEmpty()) {
cacheConfig = context.resources.openRawResource(R.raw.channels).bufferedReader()
.use { it.readText() }
Log.i(TAG, "cacheConfig $cacheConfig")
}

Log.i(TAG, "cacheConfig $cacheConfig")

try {
str2List(cacheConfig)
} catch (e: Exception) {
Expand Down
25 changes: 16 additions & 9 deletions app/src/main/java/com/lizongying/mytv0/MyTVExceptionHandler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package com.lizongying.mytv0
import android.content.Context
import android.os.Build
import android.util.Log
import kotlinx.coroutines.CoroutineScope
import com.lizongying.mytv0.requests.HttpClient
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withContext
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.RequestBody.Companion.toRequestBody
Expand All @@ -20,12 +21,14 @@ class MyTVExceptionHandler(val context: Context) : Thread.UncaughtExceptionHandl
)
}\n"

CoroutineScope(Dispatchers.IO).launch {
saveCrashInfoToFile(crashInfo)
runBlocking {
launch {
saveCrashInfoToFile(crashInfo)

withContext(Dispatchers.Main) {
android.os.Process.killProcess(android.os.Process.myPid())
exitProcess(1)
withContext(Dispatchers.Main) {
android.os.Process.killProcess(android.os.Process.myPid())
exitProcess(1)
}
}
}
}
Expand Down Expand Up @@ -55,14 +58,18 @@ class MyTVExceptionHandler(val context: Context) : Thread.UncaughtExceptionHandl

private suspend fun saveLog(crashInfo: String) {
withContext(Dispatchers.IO) {
val client = okhttp3.OkHttpClient.Builder().build()
val request = okhttp3.Request.Builder()
.url("https://lyrics.run/my-tv-0/v1/log")
.method("POST", crashInfo.toRequestBody("text/plain".toMediaType()))
.build()
try {
client.newCall(request).execute()
Log.i(TAG, "log success")
HttpClient.okHttpClient.newCall(request).execute().use { response ->
if (response.isSuccessful) {
Log.i(TAG, "log success")
} else {
Log.e(TAG, "log failed: ${response.code}")
}
}
} catch (e: Exception) {
e.printStackTrace()
}
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/com/lizongying/mytv0/data/SourceType.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ enum class SourceType {
HLS,
DASH,
RTSP,
RTMP,
PROGRESSIVE,
}
11 changes: 11 additions & 0 deletions app/src/main/java/com/lizongying/mytv0/models/TVModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import androidx.media3.common.MediaItem
import androidx.media3.common.util.UnstableApi
import androidx.media3.datasource.DataSource
import androidx.media3.datasource.DefaultHttpDataSource
import androidx.media3.datasource.rtmp.RtmpDataSource
import androidx.media3.exoplayer.dash.DashMediaSource
import androidx.media3.exoplayer.hls.HlsMediaSource
import androidx.media3.exoplayer.rtsp.RtspMediaSource
Expand Down Expand Up @@ -176,6 +177,9 @@ class TVModel(var tv: TV) : ViewModel() {
addSource(SourceType.DASH)
} else if (scheme.lowercase() == "rtsp") {
addSource(SourceType.RTSP)
} else if (scheme.lowercase() == "rtmp") {
// rtmp://ns8.indexforce.com/home/mystream
addSource(SourceType.RTMP)
} else {
// addSource(SourceType.UNKNOWN)
// addSource(SourceType.PROGRESSIVE)
Expand All @@ -192,6 +196,7 @@ class TVModel(var tv: TV) : ViewModel() {
SourceType.PROGRESSIVE,
SourceType.HLS,
SourceType.RTSP,
SourceType.RTMP,
SourceType.DASH,
SourceType.UNKNOWN
)) {
Expand Down Expand Up @@ -232,6 +237,12 @@ class TVModel(var tv: TV) : ViewModel() {
RtspMediaSource.Factory().setUserAgent(userAgent).createMediaSource(_mediaItem)
}

SourceType.RTMP -> {
val rtmpDataSource = RtmpDataSource.Factory()
ProgressiveMediaSource.Factory(rtmpDataSource)
.createMediaSource(_mediaItem)
}

SourceType.DASH -> DashMediaSource.Factory(httpDataSource).createMediaSource(_mediaItem)
SourceType.PROGRESSIVE -> ProgressiveMediaSource.Factory(httpDataSource)
.createMediaSource(_mediaItem)
Expand Down
3 changes: 2 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[versions]
desugar_jdk_libs = "2.0.4"
media3 = "1.4.0" # 1.3.0: 19 java8 1.2.1: 17 media3-datasource-okhttp:1.2.1:21
media3 = "1.5.0" # 1.3.0: 19 java8 1.2.1: 17 media3-datasource-okhttp:1.2.1:21
nanohttpd = "2.3.1"
gua64 = "1.4.5"
recyclerview = "1.3.2"
Expand Down Expand Up @@ -30,6 +30,7 @@ media3-exoplayer-hls = { module = "androidx.media3:media3-exoplayer-hls", versio
media3-exoplayer-dash = { module = "androidx.media3:media3-exoplayer-dash", version.ref = "media3" }
media3-exoplayer-rtsp = { module = "androidx.media3:media3-exoplayer-rtsp", version.ref = "media3" }
media3-datasource-okhttp = { module = "androidx.media3:media3-datasource-okhttp", version.ref = "media3" }
media3-datasource-rtmp = { module = "androidx.media3:media3-datasource-rtmp", version.ref = "media3" }

nanohttpd = { module = "org.nanohttpd:nanohttpd", version.ref = "nanohttpd" }
gua64 = { module = "io.github.lizongying:gua64", version.ref = "gua64" }
Expand Down
2 changes: 1 addition & 1 deletion version.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"version_code": 16975872, "version_name": "v1.3.8.0"}
{"version_code": 16975873, "version_name": "v1.3.8.1"}

0 comments on commit 52c7b8a

Please sign in to comment.