merge StreamVariant and stream

This commit is contained in:
Christian Schabesberger 2024-09-16 12:23:12 +02:00
parent 2fee9e59f6
commit ac97d4ee1f
3 changed files with 53 additions and 73 deletions

View File

@ -23,7 +23,6 @@ package net.newpipe.newplayer
import android.net.Uri
import androidx.media3.common.MediaMetadata
import androidx.media3.common.PlaybackException
import net.newpipe.newplayer.utils.Thumbnail
data class Chapter(val chapterStartInMs: Long, val chapterTitle: String?, val thumbnail: Uri?)
@ -34,16 +33,21 @@ enum class StreamType {
DYNAMIC
}
data class StreamVariant(
data class Stream(
val streamUri: Uri,
val identifier: String,
val streamType: StreamType,
val language: String?,
val streamVariantIdentifier: String
val mimeType: String? = null,
) {
override fun equals(other: Any?) =
other is StreamVariant
other is Stream
&& other.streamUri == streamUri
&& other.streamType == streamType
&& other.language == language
&& other.streamVariantIdentifier == streamVariantIdentifier
&& other.identifier == identifier
&& other.mimeType == mimeType
}
data class RepoMetaInfo(
@ -51,9 +55,9 @@ data class RepoMetaInfo(
val pullsDataFromNetwrok: Boolean
)
data class Stream(
val streamUri: Uri,
val mimeType: String? = null
data class Subtitle(
val uri: Uri,
val identifier: String
)
interface MediaRepository {
@ -62,11 +66,9 @@ interface MediaRepository {
suspend fun getMetaInfo(item: String): MediaMetadata
suspend fun getAvailableStreamVariants(item: String): List<StreamVariant>
suspend fun getStream(item: String, streamVariantSelector: StreamVariant): Stream
suspend fun getStreams(item: String): List<Stream>
suspend fun getAvailableSubtitleVariants(item: String): List<String>
suspend fun getSubtitle(item: String, variant: String): Uri
suspend fun getSubtitles(item: String): List<Subtitle>
suspend fun getPreviewThumbnails(item: String): HashMap<Long, Uri>?
suspend fun getChapters(item: String): List<Chapter>

View File

@ -25,10 +25,6 @@ class MediaSourceBuilder(
suspend fun buildMediaSource(item: String) {
val availableStreamVariants = repository.getAvailableStreamVariants(item)
val tracks: Tracks? = null
MergingMediaSource
}
@OptIn(UnstableApi::class)

View File

@ -11,7 +11,7 @@ import net.newpipe.newplayer.MediaRepository
import net.newpipe.newplayer.RepoMetaInfo
import net.newpipe.newplayer.Stream
import net.newpipe.newplayer.StreamType
import net.newpipe.newplayer.StreamVariant
import net.newpipe.newplayer.Subtitle
import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.Response
@ -62,81 +62,63 @@ class TestMediaRepository(val context: Context) : MediaRepository {
else -> throw Exception("Unknown stream: $item")
}
override suspend fun getAvailableStreamVariants(item: String): List<StreamVariant> =
override suspend fun getStreams(item: String) =
when (item) {
"6502" -> listOf(
StreamVariant(
Stream(
streamUri = Uri.parse(context.getString(R.string.ccc_6502_video)),
mimeType = null,
streamType = StreamType.AUDIO_AND_VIDEO,
language = "Deutsch",
streamVariantIdentifier = "576p",
),
identifier = "576p",
)
)
"portrait" -> listOf(
StreamVariant(
Stream(
streamUri = Uri.parse(context.getString(R.string.portrait_video_example)),
mimeType = null,
streamType = StreamType.AUDIO_AND_VIDEO,
language = null,
streamVariantIdentifier = "720p",
),
identifier = "720p",
)
)
"imu" -> listOf(
StreamVariant(
streamType = StreamType.AUDIO_AND_VIDEO,
language = "Deutsch",
streamVariantIdentifier = "1080p",
),
StreamVariant(
streamType = StreamType.AUDIO_AND_VIDEO,
language = "Deutsch",
streamVariantIdentifier = "576p",
)
)
else -> throw Exception("Unknown stream: $item")
}
override suspend fun getAvailableSubtitleVariants(item: String): List<String> {
TODO("Not yet implemented")
}
override suspend fun getStream(item: String, streamVariantSelector: StreamVariant) =
when (item) {
"6502" -> Stream(
streamUri = Uri.parse(context.getString(R.string.ccc_6502_video)),
mimeType = null
)
"portrait" -> Stream(
streamUri = Uri.parse(context.getString(R.string.portrait_video_example)),
mimeType = null
)
"imu" -> when (streamVariantSelector.streamVariantIdentifier) {
"1080p" -> Stream(
Stream(
streamUri = Uri.parse(context.getString(R.string.ccc_imu_1080_mp4)),
mimeType = null
)
mimeType = null,
streamType = StreamType.AUDIO_AND_VIDEO,
language = "Deutsch",
identifier = "1080p",
),
"576p" -> Stream(
Stream(
streamUri = Uri.parse(context.getString(R.string.ccc_imu_576_mp4)),
mimeType = null
mimeType = null,
streamType = StreamType.AUDIO_AND_VIDEO,
language = "Deutsch",
identifier = "576p"
)
)
else -> throw Exception("Unknown stream selector for $item: $streamVariantSelector")
else -> throw Exception("Unknown item: $item")
}
else -> throw Exception("Unknown stream: $item")
}
override suspend fun getSubtitle(item: String, variant: String) =
Uri.parse(
override suspend fun getSubtitles(item: String) =
when (item) {
"imu" -> context.getString(R.string.ccc_imu_subtitles)
else -> ""
}
"imu" -> listOf(
Subtitle(
Uri.parse(context.getString(R.string.ccc_imu_subtitles)),
"english"
)
)
else -> emptyList()
}
override suspend fun getPreviewThumbnails(item: String): HashMap<Long, Uri>? {
val templateUrl = when (item) {