merge StreamVariant and stream
This commit is contained in:
parent
2fee9e59f6
commit
ac97d4ee1f
|
@ -23,7 +23,6 @@ package net.newpipe.newplayer
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import androidx.media3.common.MediaMetadata
|
import androidx.media3.common.MediaMetadata
|
||||||
import androidx.media3.common.PlaybackException
|
import androidx.media3.common.PlaybackException
|
||||||
import net.newpipe.newplayer.utils.Thumbnail
|
|
||||||
|
|
||||||
data class Chapter(val chapterStartInMs: Long, val chapterTitle: String?, val thumbnail: Uri?)
|
data class Chapter(val chapterStartInMs: Long, val chapterTitle: String?, val thumbnail: Uri?)
|
||||||
|
|
||||||
|
@ -34,16 +33,21 @@ enum class StreamType {
|
||||||
DYNAMIC
|
DYNAMIC
|
||||||
}
|
}
|
||||||
|
|
||||||
data class StreamVariant(
|
data class Stream(
|
||||||
|
val streamUri: Uri,
|
||||||
|
val identifier: String,
|
||||||
val streamType: StreamType,
|
val streamType: StreamType,
|
||||||
val language: String?,
|
val language: String?,
|
||||||
val streamVariantIdentifier: String
|
val mimeType: String? = null,
|
||||||
) {
|
) {
|
||||||
override fun equals(other: Any?) =
|
override fun equals(other: Any?) =
|
||||||
other is StreamVariant
|
other is Stream
|
||||||
|
&& other.streamUri == streamUri
|
||||||
&& other.streamType == streamType
|
&& other.streamType == streamType
|
||||||
&& other.language == language
|
&& other.language == language
|
||||||
&& other.streamVariantIdentifier == streamVariantIdentifier
|
&& other.identifier == identifier
|
||||||
|
&& other.mimeType == mimeType
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
data class RepoMetaInfo(
|
data class RepoMetaInfo(
|
||||||
|
@ -51,9 +55,9 @@ data class RepoMetaInfo(
|
||||||
val pullsDataFromNetwrok: Boolean
|
val pullsDataFromNetwrok: Boolean
|
||||||
)
|
)
|
||||||
|
|
||||||
data class Stream(
|
data class Subtitle(
|
||||||
val streamUri: Uri,
|
val uri: Uri,
|
||||||
val mimeType: String? = null
|
val identifier: String
|
||||||
)
|
)
|
||||||
|
|
||||||
interface MediaRepository {
|
interface MediaRepository {
|
||||||
|
@ -62,11 +66,9 @@ interface MediaRepository {
|
||||||
|
|
||||||
suspend fun getMetaInfo(item: String): MediaMetadata
|
suspend fun getMetaInfo(item: String): MediaMetadata
|
||||||
|
|
||||||
suspend fun getAvailableStreamVariants(item: String): List<StreamVariant>
|
suspend fun getStreams(item: String): List<Stream>
|
||||||
suspend fun getStream(item: String, streamVariantSelector: StreamVariant): Stream
|
|
||||||
|
|
||||||
suspend fun getAvailableSubtitleVariants(item: String): List<String>
|
suspend fun getSubtitles(item: String): List<Subtitle>
|
||||||
suspend fun getSubtitle(item: String, variant: String): Uri
|
|
||||||
|
|
||||||
suspend fun getPreviewThumbnails(item: String): HashMap<Long, Uri>?
|
suspend fun getPreviewThumbnails(item: String): HashMap<Long, Uri>?
|
||||||
suspend fun getChapters(item: String): List<Chapter>
|
suspend fun getChapters(item: String): List<Chapter>
|
||||||
|
|
|
@ -25,10 +25,6 @@ class MediaSourceBuilder(
|
||||||
suspend fun buildMediaSource(item: String) {
|
suspend fun buildMediaSource(item: String) {
|
||||||
val availableStreamVariants = repository.getAvailableStreamVariants(item)
|
val availableStreamVariants = repository.getAvailableStreamVariants(item)
|
||||||
|
|
||||||
|
|
||||||
val tracks: Tracks? = null
|
|
||||||
MergingMediaSource
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@OptIn(UnstableApi::class)
|
@OptIn(UnstableApi::class)
|
||||||
|
|
|
@ -11,7 +11,7 @@ import net.newpipe.newplayer.MediaRepository
|
||||||
import net.newpipe.newplayer.RepoMetaInfo
|
import net.newpipe.newplayer.RepoMetaInfo
|
||||||
import net.newpipe.newplayer.Stream
|
import net.newpipe.newplayer.Stream
|
||||||
import net.newpipe.newplayer.StreamType
|
import net.newpipe.newplayer.StreamType
|
||||||
import net.newpipe.newplayer.StreamVariant
|
import net.newpipe.newplayer.Subtitle
|
||||||
import okhttp3.OkHttpClient
|
import okhttp3.OkHttpClient
|
||||||
import okhttp3.Request
|
import okhttp3.Request
|
||||||
import okhttp3.Response
|
import okhttp3.Response
|
||||||
|
@ -62,81 +62,63 @@ class TestMediaRepository(val context: Context) : MediaRepository {
|
||||||
else -> throw Exception("Unknown stream: $item")
|
else -> throw Exception("Unknown stream: $item")
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun getAvailableStreamVariants(item: String): List<StreamVariant> =
|
|
||||||
|
override suspend fun getStreams(item: String) =
|
||||||
when (item) {
|
when (item) {
|
||||||
"6502" -> listOf(
|
"6502" -> listOf(
|
||||||
StreamVariant(
|
Stream(
|
||||||
|
streamUri = Uri.parse(context.getString(R.string.ccc_6502_video)),
|
||||||
|
mimeType = null,
|
||||||
streamType = StreamType.AUDIO_AND_VIDEO,
|
streamType = StreamType.AUDIO_AND_VIDEO,
|
||||||
language = "Deutsch",
|
language = "Deutsch",
|
||||||
streamVariantIdentifier = "576p",
|
identifier = "576p",
|
||||||
),
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
"portrait" -> listOf(
|
"portrait" -> listOf(
|
||||||
StreamVariant(
|
Stream(
|
||||||
|
streamUri = Uri.parse(context.getString(R.string.portrait_video_example)),
|
||||||
|
mimeType = null,
|
||||||
streamType = StreamType.AUDIO_AND_VIDEO,
|
streamType = StreamType.AUDIO_AND_VIDEO,
|
||||||
language = null,
|
language = null,
|
||||||
streamVariantIdentifier = "720p",
|
identifier = "720p",
|
||||||
),
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
"imu" -> listOf(
|
"imu" -> listOf(
|
||||||
StreamVariant(
|
Stream(
|
||||||
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(
|
|
||||||
streamUri = Uri.parse(context.getString(R.string.ccc_imu_1080_mp4)),
|
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)),
|
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) =
|
override suspend fun getSubtitles(item: String) =
|
||||||
Uri.parse(
|
|
||||||
when (item) {
|
when (item) {
|
||||||
"imu" -> context.getString(R.string.ccc_imu_subtitles)
|
"imu" -> listOf(
|
||||||
else -> ""
|
Subtitle(
|
||||||
}
|
Uri.parse(context.getString(R.string.ccc_imu_subtitles)),
|
||||||
|
"english"
|
||||||
)
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
else -> emptyList()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
override suspend fun getPreviewThumbnails(item: String): HashMap<Long, Uri>? {
|
override suspend fun getPreviewThumbnails(item: String): HashMap<Long, Uri>? {
|
||||||
val templateUrl = when (item) {
|
val templateUrl = when (item) {
|
||||||
|
|
Loading…
Reference in New Issue