remove Thumbnail class and replace it with Uri
This commit is contained in:
parent
0744d43b20
commit
5710596972
|
@ -24,12 +24,12 @@ import android.net.Uri
|
||||||
import androidx.media3.common.PlaybackException
|
import androidx.media3.common.PlaybackException
|
||||||
import net.newpipe.newplayer.utils.Thumbnail
|
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(
|
data class MetaInfo(
|
||||||
val title: String,
|
val title: String,
|
||||||
val channelName: String,
|
val channelName: String,
|
||||||
val thumbnail: Thumbnail?,
|
val thumbnail: Uri?,
|
||||||
val lengthInS: Int
|
val lengthInS: Int
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ interface MediaRepository {
|
||||||
suspend fun getAvailableSubtitleVariants(item: String): List<String>
|
suspend fun getAvailableSubtitleVariants(item: String): List<String>
|
||||||
suspend fun getSubtitle(item: String, variant: String): Uri
|
suspend fun getSubtitle(item: String, variant: String): Uri
|
||||||
|
|
||||||
suspend fun getPreviewThumbnails(item: String): HashMap<Long, Thumbnail>?
|
suspend fun getPreviewThumbnails(item: String): HashMap<Long, Uri>?
|
||||||
suspend fun getChapters(item: String): List<Chapter>
|
suspend fun getChapters(item: String): List<Chapter>
|
||||||
|
|
||||||
suspend fun getTimestampLink(item: String, timestampInSeconds: Long): String
|
suspend fun getTimestampLink(item: String, timestampInSeconds: Long): String
|
||||||
|
|
|
@ -1,32 +0,0 @@
|
||||||
/* NewPlayer
|
|
||||||
*
|
|
||||||
* @author Christian Schabesberger
|
|
||||||
*
|
|
||||||
* Copyright (C) NewPipe e.V. 2024 <code(at)newpipe-ev.de>
|
|
||||||
*
|
|
||||||
* 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 <http://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
package net.newpipe.newplayer.model
|
|
||||||
|
|
||||||
import net.newpipe.newplayer.utils.Thumbnail
|
|
||||||
|
|
||||||
data class ChapterItem(
|
|
||||||
val title: String,
|
|
||||||
val offsetInMs: Long,
|
|
||||||
val thumbnail: Thumbnail
|
|
||||||
)
|
|
|
@ -21,6 +21,7 @@
|
||||||
|
|
||||||
package net.newpipe.newplayer.model
|
package net.newpipe.newplayer.model
|
||||||
|
|
||||||
|
import android.net.Uri
|
||||||
import androidx.media3.common.Player
|
import androidx.media3.common.Player
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.async
|
import kotlinx.coroutines.async
|
||||||
|
@ -34,7 +35,7 @@ data class PlaylistItem(
|
||||||
val creator: String,
|
val creator: String,
|
||||||
val id: String,
|
val id: String,
|
||||||
val uniqueId: Long,
|
val uniqueId: Long,
|
||||||
val thumbnail: Thumbnail?,
|
val thumbnail: Uri?,
|
||||||
val lengthInS: Int
|
val lengthInS: Int
|
||||||
) {
|
) {
|
||||||
companion object {
|
companion object {
|
||||||
|
@ -84,7 +85,7 @@ suspend fun getPlaylistItemsFromExoplayer(
|
||||||
idLookupTable: HashMap<Long, String>
|
idLookupTable: HashMap<Long, String>
|
||||||
) =
|
) =
|
||||||
with(CoroutineScope(coroutineContext)) {
|
with(CoroutineScope(coroutineContext)) {
|
||||||
(0..player.mediaItemCount - 1).map { index ->
|
(0..<player.mediaItemCount).map { index ->
|
||||||
val mediaItem = player.getMediaItemAt(index)
|
val mediaItem = player.getMediaItemAt(index)
|
||||||
val uniqueId = mediaItem.mediaId.toLong()
|
val uniqueId = mediaItem.mediaId.toLong()
|
||||||
val id = idLookupTable.get(uniqueId)
|
val id = idLookupTable.get(uniqueId)
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
|
|
||||||
package net.newpipe.newplayer.ui.videoplayer.streamselect
|
package net.newpipe.newplayer.ui.videoplayer.streamselect
|
||||||
|
|
||||||
|
import android.net.Uri
|
||||||
import androidx.compose.animation.AnimatedVisibility
|
import androidx.compose.animation.AnimatedVisibility
|
||||||
import androidx.compose.animation.core.tween
|
import androidx.compose.animation.core.tween
|
||||||
import androidx.compose.animation.fadeIn
|
import androidx.compose.animation.fadeIn
|
||||||
|
@ -55,10 +56,7 @@ import net.newpipe.newplayer.NewPlayerException
|
||||||
import net.newpipe.newplayer.R
|
import net.newpipe.newplayer.R
|
||||||
import net.newpipe.newplayer.ui.theme.VideoPlayerTheme
|
import net.newpipe.newplayer.ui.theme.VideoPlayerTheme
|
||||||
import net.newpipe.newplayer.ui.videoplayer.ITEM_CORNER_SHAPE
|
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.Thumbnail
|
||||||
import net.newpipe.newplayer.utils.VectorThumbnail
|
|
||||||
import net.newpipe.newplayer.utils.getLocale
|
import net.newpipe.newplayer.utils.getLocale
|
||||||
import net.newpipe.newplayer.utils.getTimeStringFromMs
|
import net.newpipe.newplayer.utils.getTimeStringFromMs
|
||||||
|
|
||||||
|
@ -77,7 +75,7 @@ fun isActiveChapter(chapterId: Int, chapters: List<Chapter>, playbackPosition: L
|
||||||
fun ChapterItem(
|
fun ChapterItem(
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
id: Int,
|
id: Int,
|
||||||
thumbnail: Thumbnail?,
|
thumbnail: Uri?,
|
||||||
chapterTitle: String,
|
chapterTitle: String,
|
||||||
chapterStartInMs: Long,
|
chapterStartInMs: Long,
|
||||||
onClicked: (Int) -> Unit,
|
onClicked: (Int) -> Unit,
|
||||||
|
|
|
@ -1,32 +0,0 @@
|
||||||
/* NewPlayer
|
|
||||||
*
|
|
||||||
* @author Christian Schabesberger
|
|
||||||
*
|
|
||||||
* Copyright (C) NewPipe e.V. 2024 <code(at)newpipe-ev.de>
|
|
||||||
*
|
|
||||||
* 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 <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
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
|
|
|
@ -25,6 +25,7 @@ import android.app.Activity
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.ContextWrapper
|
import android.content.ContextWrapper
|
||||||
import android.graphics.drawable.shapes.Shape
|
import android.graphics.drawable.shapes.Shape
|
||||||
|
import android.net.Uri
|
||||||
import android.view.WindowManager
|
import android.view.WindowManager
|
||||||
import androidx.compose.foundation.Image
|
import androidx.compose.foundation.Image
|
||||||
import androidx.compose.foundation.layout.WindowInsets
|
import androidx.compose.foundation.layout.WindowInsets
|
||||||
|
@ -152,7 +153,7 @@ fun getTimeStringFromMs(
|
||||||
@Composable
|
@Composable
|
||||||
fun Thumbnail(
|
fun Thumbnail(
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
thumbnail: Thumbnail?,
|
thumbnail: Uri?,
|
||||||
contentDescription: String,
|
contentDescription: String,
|
||||||
shape: androidx.compose.ui.graphics.Shape? = null
|
shape: androidx.compose.ui.graphics.Shape? = null
|
||||||
) {
|
) {
|
||||||
|
@ -163,31 +164,17 @@ fun Thumbnail(
|
||||||
.clip(shape)
|
.clip(shape)
|
||||||
}
|
}
|
||||||
|
|
||||||
when (thumbnail) {
|
if (thumbnail != null) {
|
||||||
is OnlineThumbnail -> AsyncImage(
|
AsyncImage(
|
||||||
modifier = modifier,
|
modifier = modifier,
|
||||||
model = thumbnail.url,
|
model = thumbnail,
|
||||||
contentDescription = contentDescription,
|
contentDescription = contentDescription,
|
||||||
)
|
)
|
||||||
|
} else {
|
||||||
is BitmapThumbnail -> Image(
|
Image(
|
||||||
modifier = modifier,
|
|
||||||
bitmap = thumbnail.img,
|
|
||||||
contentDescription = contentDescription
|
|
||||||
)
|
|
||||||
|
|
||||||
is VectorThumbnail -> Image(
|
|
||||||
modifier = modifier,
|
|
||||||
imageVector = thumbnail.vec,
|
|
||||||
contentDescription = contentDescription
|
|
||||||
)
|
|
||||||
|
|
||||||
null -> Image(
|
|
||||||
modifier = modifier,
|
modifier = modifier,
|
||||||
painter = painterResource(R.drawable.tiny_placeholder),
|
painter = painterResource(R.drawable.tiny_placeholder),
|
||||||
contentDescription = contentDescription
|
contentDescription = contentDescription
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,6 @@ import androidx.media3.common.PlaybackException
|
||||||
import net.newpipe.newplayer.Chapter
|
import net.newpipe.newplayer.Chapter
|
||||||
import net.newpipe.newplayer.MediaRepository
|
import net.newpipe.newplayer.MediaRepository
|
||||||
import net.newpipe.newplayer.MetaInfo
|
import net.newpipe.newplayer.MetaInfo
|
||||||
import net.newpipe.newplayer.utils.OnlineThumbnail
|
|
||||||
import net.newpipe.newplayer.utils.Thumbnail
|
import net.newpipe.newplayer.utils.Thumbnail
|
||||||
import okhttp3.OkHttpClient
|
import okhttp3.OkHttpClient
|
||||||
import okhttp3.Request
|
import okhttp3.Request
|
||||||
|
@ -27,14 +26,14 @@ class TestMediaRepository(val context: Context) : MediaRepository {
|
||||||
"6502" -> MetaInfo(
|
"6502" -> MetaInfo(
|
||||||
title = context.getString(R.string.ccc_6502_title),
|
title = context.getString(R.string.ccc_6502_title),
|
||||||
channelName = context.getString(R.string.ccc_6502_channel),
|
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)
|
lengthInS = context.resources.getInteger(R.integer.ccc_6502_length)
|
||||||
)
|
)
|
||||||
|
|
||||||
"imu" -> MetaInfo(
|
"imu" -> MetaInfo(
|
||||||
title = context.getString(R.string.ccc_imu_title),
|
title = context.getString(R.string.ccc_imu_title),
|
||||||
channelName = context.getString(R.string.ccc_imu_channel),
|
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)
|
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<Long, Thumbnail>? {
|
override suspend fun getPreviewThumbnails(item: String): HashMap<Long, Uri>? {
|
||||||
val templateUrl = when (item) {
|
val templateUrl = when (item) {
|
||||||
"6502" -> context.getString(R.string.ccc_6502_preview_thumbnails)
|
"6502" -> context.getString(R.string.ccc_6502_preview_thumbnails)
|
||||||
"imu" -> context.getString(R.string.ccc_imu_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")
|
else -> throw Exception("Unknown stream: $item")
|
||||||
}
|
}
|
||||||
|
|
||||||
var thumbMap = HashMap<Long, Thumbnail>()
|
var thumbMap = HashMap<Long, Uri>()
|
||||||
|
|
||||||
for (i in 1..thumbCount) {
|
for (i in 1..thumbCount) {
|
||||||
val timeStamp = (i - 1) * 10 * 1000
|
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
|
return thumbMap
|
||||||
|
@ -121,14 +120,14 @@ class TestMediaRepository(val context: Context) : MediaRepository {
|
||||||
Chapter(
|
Chapter(
|
||||||
it.toLong(), chapterTitle = "Dummy Chapter at timestamp $it",
|
it.toLong(), chapterTitle = "Dummy Chapter at timestamp $it",
|
||||||
thumbnail = when (item) {
|
thumbnail = when (item) {
|
||||||
"6502" -> OnlineThumbnail(
|
"6502" -> Uri.parse(
|
||||||
String.format(
|
String.format(
|
||||||
context.getString(R.string.ccc_6502_preview_thumbnails),
|
context.getString(R.string.ccc_6502_preview_thumbnails),
|
||||||
it / (10 * 1000)
|
it / (10 * 1000)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
"imu" -> OnlineThumbnail(
|
"imu" -> Uri.parse(
|
||||||
String.format(
|
String.format(
|
||||||
context.getString(R.string.ccc_imu_preview_thumbnails),
|
context.getString(R.string.ccc_imu_preview_thumbnails),
|
||||||
it / (10 * 1000)
|
it / (10 * 1000)
|
||||||
|
|
Loading…
Reference in New Issue