diff --git a/new-player/src/main/java/net/newpipe/newplayer/MediaRepository.kt b/new-player/src/main/java/net/newpipe/newplayer/MediaRepository.kt index 26013b8..84560ce 100644 --- a/new-player/src/main/java/net/newpipe/newplayer/MediaRepository.kt +++ b/new-player/src/main/java/net/newpipe/newplayer/MediaRepository.kt @@ -24,12 +24,12 @@ import android.net.Uri import androidx.media3.common.PlaybackException import net.newpipe.newplayer.utils.Thumbnail -data class Chapter(val chapterStartInMs: Long, val chapterTitle: String?, val thumbnail: Thumbnail?) +data class Chapter(val chapterStartInMs: Long, val chapterTitle: String?, val thumbnail: Uri?) data class MetaInfo( val title: String, val channelName: String, - val thumbnail: Thumbnail?, + val thumbnail: Uri?, val lengthInS: Int ) @@ -44,7 +44,7 @@ interface MediaRepository { suspend fun getAvailableSubtitleVariants(item: String): List suspend fun getSubtitle(item: String, variant: String): Uri - suspend fun getPreviewThumbnails(item: String): HashMap? + suspend fun getPreviewThumbnails(item: String): HashMap? suspend fun getChapters(item: String): List suspend fun getTimestampLink(item: String, timestampInSeconds: Long): String diff --git a/new-player/src/main/java/net/newpipe/newplayer/model/ChapterItem.kt b/new-player/src/main/java/net/newpipe/newplayer/model/ChapterItem.kt deleted file mode 100644 index 5ea9c73..0000000 --- a/new-player/src/main/java/net/newpipe/newplayer/model/ChapterItem.kt +++ /dev/null @@ -1,32 +0,0 @@ -/* NewPlayer - * - * @author Christian Schabesberger - * - * Copyright (C) NewPipe e.V. 2024 - * - * NewPlayer is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * NewPlayer is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with NewPlayer. If not, see . - * - */ - - - -package net.newpipe.newplayer.model - -import net.newpipe.newplayer.utils.Thumbnail - -data class ChapterItem( - val title: String, - val offsetInMs: Long, - val thumbnail: Thumbnail -) diff --git a/new-player/src/main/java/net/newpipe/newplayer/model/PlayListItem.kt b/new-player/src/main/java/net/newpipe/newplayer/model/PlayListItem.kt index 0e62da8..dc70d97 100644 --- a/new-player/src/main/java/net/newpipe/newplayer/model/PlayListItem.kt +++ b/new-player/src/main/java/net/newpipe/newplayer/model/PlayListItem.kt @@ -21,6 +21,7 @@ package net.newpipe.newplayer.model +import android.net.Uri import androidx.media3.common.Player import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.async @@ -34,7 +35,7 @@ data class PlaylistItem( val creator: String, val id: String, val uniqueId: Long, - val thumbnail: Thumbnail?, + val thumbnail: Uri?, val lengthInS: Int ) { companion object { @@ -84,7 +85,7 @@ suspend fun getPlaylistItemsFromExoplayer( idLookupTable: HashMap ) = with(CoroutineScope(coroutineContext)) { - (0..player.mediaItemCount - 1).map { index -> + (0.. val mediaItem = player.getMediaItemAt(index) val uniqueId = mediaItem.mediaId.toLong() val id = idLookupTable.get(uniqueId) diff --git a/new-player/src/main/java/net/newpipe/newplayer/ui/videoplayer/streamselect/ChapterItem.kt b/new-player/src/main/java/net/newpipe/newplayer/ui/videoplayer/streamselect/ChapterItem.kt index 68a956a..0be1b65 100644 --- a/new-player/src/main/java/net/newpipe/newplayer/ui/videoplayer/streamselect/ChapterItem.kt +++ b/new-player/src/main/java/net/newpipe/newplayer/ui/videoplayer/streamselect/ChapterItem.kt @@ -21,6 +21,7 @@ package net.newpipe.newplayer.ui.videoplayer.streamselect +import android.net.Uri import androidx.compose.animation.AnimatedVisibility import androidx.compose.animation.core.tween import androidx.compose.animation.fadeIn @@ -55,10 +56,7 @@ import net.newpipe.newplayer.NewPlayerException import net.newpipe.newplayer.R import net.newpipe.newplayer.ui.theme.VideoPlayerTheme import net.newpipe.newplayer.ui.videoplayer.ITEM_CORNER_SHAPE -import net.newpipe.newplayer.utils.BitmapThumbnail -import net.newpipe.newplayer.utils.OnlineThumbnail import net.newpipe.newplayer.utils.Thumbnail -import net.newpipe.newplayer.utils.VectorThumbnail import net.newpipe.newplayer.utils.getLocale import net.newpipe.newplayer.utils.getTimeStringFromMs @@ -77,7 +75,7 @@ fun isActiveChapter(chapterId: Int, chapters: List, playbackPosition: L fun ChapterItem( modifier: Modifier = Modifier, id: Int, - thumbnail: Thumbnail?, + thumbnail: Uri?, chapterTitle: String, chapterStartInMs: Long, onClicked: (Int) -> Unit, diff --git a/new-player/src/main/java/net/newpipe/newplayer/utils/Thumbnail.kt b/new-player/src/main/java/net/newpipe/newplayer/utils/Thumbnail.kt deleted file mode 100644 index 8814edd..0000000 --- a/new-player/src/main/java/net/newpipe/newplayer/utils/Thumbnail.kt +++ /dev/null @@ -1,32 +0,0 @@ -/* NewPlayer - * - * @author Christian Schabesberger - * - * Copyright (C) NewPipe e.V. 2024 - * - * NewPlayer is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * NewPlayer is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with NewPlayer. If not, see . - */ - -package net.newpipe.newplayer.utils - -import android.graphics.Bitmap -import android.graphics.drawable.VectorDrawable -import androidx.compose.ui.graphics.ImageBitmap -import androidx.compose.ui.graphics.vector.ImageVector - -interface Thumbnail - -data class OnlineThumbnail(val url: String) : Thumbnail -data class BitmapThumbnail(val img: ImageBitmap) : Thumbnail -data class VectorThumbnail(val vec:ImageVector) : Thumbnail \ No newline at end of file diff --git a/new-player/src/main/java/net/newpipe/newplayer/utils/utils.kt b/new-player/src/main/java/net/newpipe/newplayer/utils/utils.kt index 2d09bd2..2cd2322 100644 --- a/new-player/src/main/java/net/newpipe/newplayer/utils/utils.kt +++ b/new-player/src/main/java/net/newpipe/newplayer/utils/utils.kt @@ -25,6 +25,7 @@ import android.app.Activity import android.content.Context import android.content.ContextWrapper import android.graphics.drawable.shapes.Shape +import android.net.Uri import android.view.WindowManager import androidx.compose.foundation.Image import androidx.compose.foundation.layout.WindowInsets @@ -152,7 +153,7 @@ fun getTimeStringFromMs( @Composable fun Thumbnail( modifier: Modifier = Modifier, - thumbnail: Thumbnail?, + thumbnail: Uri?, contentDescription: String, shape: androidx.compose.ui.graphics.Shape? = null ) { @@ -163,31 +164,17 @@ fun Thumbnail( .clip(shape) } - when (thumbnail) { - is OnlineThumbnail -> AsyncImage( + if (thumbnail != null) { + AsyncImage( modifier = modifier, - model = thumbnail.url, + model = thumbnail, contentDescription = contentDescription, ) - - is BitmapThumbnail -> Image( - modifier = modifier, - bitmap = thumbnail.img, - contentDescription = contentDescription - ) - - is VectorThumbnail -> Image( - modifier = modifier, - imageVector = thumbnail.vec, - contentDescription = contentDescription - ) - - null -> Image( + } else { + Image( modifier = modifier, painter = painterResource(R.drawable.tiny_placeholder), contentDescription = contentDescription ) } -} - - +} \ No newline at end of file diff --git a/test-app/src/main/java/net/newpipe/newplayer/testapp/TestMediaRepository.kt b/test-app/src/main/java/net/newpipe/newplayer/testapp/TestMediaRepository.kt index 285f062..2dd2b9b 100644 --- a/test-app/src/main/java/net/newpipe/newplayer/testapp/TestMediaRepository.kt +++ b/test-app/src/main/java/net/newpipe/newplayer/testapp/TestMediaRepository.kt @@ -6,7 +6,6 @@ import androidx.media3.common.PlaybackException import net.newpipe.newplayer.Chapter import net.newpipe.newplayer.MediaRepository import net.newpipe.newplayer.MetaInfo -import net.newpipe.newplayer.utils.OnlineThumbnail import net.newpipe.newplayer.utils.Thumbnail import okhttp3.OkHttpClient import okhttp3.Request @@ -27,14 +26,14 @@ class TestMediaRepository(val context: Context) : MediaRepository { "6502" -> MetaInfo( title = context.getString(R.string.ccc_6502_title), channelName = context.getString(R.string.ccc_6502_channel), - thumbnail = OnlineThumbnail(context.getString(R.string.ccc_6502_thumbnail)), + thumbnail = Uri.parse(context.getString(R.string.ccc_6502_thumbnail)), lengthInS = context.resources.getInteger(R.integer.ccc_6502_length) ) "imu" -> MetaInfo( title = context.getString(R.string.ccc_imu_title), channelName = context.getString(R.string.ccc_imu_channel), - thumbnail = OnlineThumbnail(context.getString(R.string.ccc_imu_thumbnail)), + thumbnail = Uri.parse(context.getString(R.string.ccc_imu_thumbnail)), lengthInS = context.resources.getInteger(R.integer.ccc_imu_length) ) @@ -84,7 +83,7 @@ class TestMediaRepository(val context: Context) : MediaRepository { } ) - override suspend fun getPreviewThumbnails(item: String): HashMap? { + override suspend fun getPreviewThumbnails(item: String): HashMap? { val templateUrl = when (item) { "6502" -> context.getString(R.string.ccc_6502_preview_thumbnails) "imu" -> context.getString(R.string.ccc_imu_preview_thumbnails) @@ -99,11 +98,11 @@ class TestMediaRepository(val context: Context) : MediaRepository { else -> throw Exception("Unknown stream: $item") } - var thumbMap = HashMap() + var thumbMap = HashMap() for (i in 1..thumbCount) { val timeStamp = (i - 1) * 10 * 1000 - thumbMap.put(timeStamp.toLong(), OnlineThumbnail(String.format(templateUrl, i))) + thumbMap.put(timeStamp.toLong(), Uri.parse(String.format(templateUrl, i))) } return thumbMap @@ -121,14 +120,14 @@ class TestMediaRepository(val context: Context) : MediaRepository { Chapter( it.toLong(), chapterTitle = "Dummy Chapter at timestamp $it", thumbnail = when (item) { - "6502" -> OnlineThumbnail( + "6502" -> Uri.parse( String.format( context.getString(R.string.ccc_6502_preview_thumbnails), it / (10 * 1000) ) ) - "imu" -> OnlineThumbnail( + "imu" -> Uri.parse( String.format( context.getString(R.string.ccc_imu_preview_thumbnails), it / (10 * 1000)