CachingRepository

class CachingRepository(val actualRepository: MediaRepository, requestDispatcher: CoroutineDispatcher = Dispatchers.Main) : MediaRepository

This is a meta media repository that functions as a cache. By default, NewPlayer itself does not cache anything, which is why it asks the repository for anything over and over again. If these requests are not cached your app might unnecessarily perform network requests or other IO. In order to prevent this use this media repository.

However, it's discouraged to use this cache if your app already has a cache. Use your own cache instead in order not to cache the same data twice. When using your own cache you will also be able to share cached data between your app and NewPlayer. (IE. NewPipe should not use this).

Parameters

actualRepository

the actual repository

requestDispatcher

the thread this repository should use to perform requests with. This should be the same thad as the one NewPlayer is in.

TODO: Maybe a (individual) timeout would be nice

Constructors

Link copied to clipboard
constructor(actualRepository: MediaRepository, requestDispatcher: CoroutineDispatcher = Dispatchers.Main)

Properties

Link copied to clipboard

Functions

Link copied to clipboard
fun flush()

Will flush the caches.

Link copied to clipboard
open suspend override fun getChapters(item: String): List<Chapter>

This should return the chapters associated with an item. If an item does not have chapters you may return an empty list.

Link copied to clipboard

Supply a custom HttpDataSource.Factory. This is important for Youtube.

Link copied to clipboard
open suspend override fun getMetaInfo(item: String): MediaMetadata

Get MediaMetadata information for a certain item. Please refer to the media3 documentation for MediaMetadata.

Link copied to clipboard
open suspend override fun getPreviewThumbnail(item: String, timestampInMs: Long): Bitmap?

This should return a thumbnail associated with the provided timestamp of the provided item. The reason this function does not simply return a Uri to a bitmap is that some platforms like Youtube provide the preview thumbnail as a collage of multiple thumbnails within one jpeg file. It is then the task of the client to crop this jpeg to only show the piece of that image that depicts the thumbnail for the given timestamp.

Link copied to clipboard

The amount of review thumbnails an item provides. This is used to tell async requesting tools how much requests to spawn to get all thumbnails. It's also used to calculate the correct keys for the caching repository.

Link copied to clipboard

Returns the information of the repository. Please see the documentation for RepoMetaInfo for more details.

Link copied to clipboard
open suspend override fun getStreams(item: String): List<Stream>

This should return all the Streams associated with an item.

Link copied to clipboard
open suspend override fun getSubtitles(item: String): List<Subtitle>

This should return all the Subtitles associated with an item.

Link copied to clipboard
open suspend override fun getTimestampLink(item: String, timestampInSeconds: Long): String

Should return the link to a certain timestamp of the video/audio stream associated by item. An example for a timestamp link would be this (don't watch it though its dangerous): https://www.youtube.com/watch?v=H8ZH_mkfPUY&t=19s