From 197cc9b85f7877e63265c9e0879a2f75d7a90b36 Mon Sep 17 00:00:00 2001 From: uzu09811 <168120233+uzu09811@users.noreply.github.com> Date: Wed, 6 Nov 2024 19:16:19 +0530 Subject: [PATCH 1/4] Allow using non-http data sources (e.g. cronet) --- .../src/main/java/net/newpipe/newplayer/NewPlayerImpl.kt | 2 +- .../net/newpipe/newplayer/logic/MediaSourceBuilder.kt | 3 ++- .../net/newpipe/newplayer/repository/MediaRepository.kt | 9 +++++++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/new-player/src/main/java/net/newpipe/newplayer/NewPlayerImpl.kt b/new-player/src/main/java/net/newpipe/newplayer/NewPlayerImpl.kt index 1cf25d15..f6963d76 100644 --- a/new-player/src/main/java/net/newpipe/newplayer/NewPlayerImpl.kt +++ b/new-player/src/main/java/net/newpipe/newplayer/NewPlayerImpl.kt @@ -501,7 +501,7 @@ internalPlayStream(mediaSource: MediaSource, playMode: PlayMode) { val builder = MediaSourceBuilder( repository = repository, mutableErrorFlow = mutableErrorFlow, - httpDataSourceFactory = repository.getHttpDataSourceFactory(item), + httpDataSourceFactory = repository.getHttpDataSourceFactory(item, app), ) val uniqueId = Random.nextLong() diff --git a/new-player/src/main/java/net/newpipe/newplayer/logic/MediaSourceBuilder.kt b/new-player/src/main/java/net/newpipe/newplayer/logic/MediaSourceBuilder.kt index 9c7aebca..4de3994a 100644 --- a/new-player/src/main/java/net/newpipe/newplayer/logic/MediaSourceBuilder.kt +++ b/new-player/src/main/java/net/newpipe/newplayer/logic/MediaSourceBuilder.kt @@ -24,6 +24,7 @@ import androidx.annotation.OptIn import androidx.media3.common.MediaItem import androidx.media3.common.util.UnstableApi import androidx.media3.datasource.HttpDataSource +import androidx.media3.datasource.DataSource import androidx.media3.exoplayer.dash.DashMediaSource import androidx.media3.exoplayer.source.MediaSource import androidx.media3.exoplayer.source.MergingMediaSource @@ -47,7 +48,7 @@ internal class MediaSourceBuilder ( private val repository: MediaRepository, private val mutableErrorFlow: MutableSharedFlow, - private val httpDataSourceFactory: HttpDataSource.Factory, + private val httpDataSourceFactory: DataSource.Factory, ) { @OptIn(UnstableApi::class) diff --git a/new-player/src/main/java/net/newpipe/newplayer/repository/MediaRepository.kt b/new-player/src/main/java/net/newpipe/newplayer/repository/MediaRepository.kt index 6db9d253..f3ce08b8 100644 --- a/new-player/src/main/java/net/newpipe/newplayer/repository/MediaRepository.kt +++ b/new-player/src/main/java/net/newpipe/newplayer/repository/MediaRepository.kt @@ -20,14 +20,18 @@ package net.newpipe.newplayer.repository +import android.os.Build +import android.content.Context import android.graphics.Bitmap import androidx.media3.common.MediaMetadata import androidx.media3.datasource.DefaultHttpDataSource +import androidx.media3.datasource.DataSource import androidx.media3.datasource.HttpDataSource import net.newpipe.newplayer.data.Chapter import net.newpipe.newplayer.data.Stream import net.newpipe.newplayer.data.Subtitle import net.newpipe.newplayer.data.StreamTrack +import java.util.concurrent.Executors /** * You, dear Developer who uses NewPlayer, will want to implement MediaRepository. @@ -114,8 +118,9 @@ interface MediaRepository { /** * Supply a custom [HttpDataSource.Factory]. This is important for Youtube. */ - fun getHttpDataSourceFactory(item: String): HttpDataSource.Factory = - DefaultHttpDataSource.Factory() + fun getHttpDataSourceFactory(item: String, context: Context): DataSource.Factory { + return DefaultHttpDataSource.Factory() + } /** * Get MediaMetadata information for a certain item. Please refer to the media3 documentation From d2ae01ae715ac972b53c72480e230e1e40626b6b Mon Sep 17 00:00:00 2001 From: uzu09811 <168120233+uzu09811@users.noreply.github.com> Date: Tue, 12 Nov 2024 09:54:34 +0530 Subject: [PATCH 2/4] Remove unused imports --- .../src/main/java/net/newpipe/newplayer/NewPlayerImpl.kt | 2 +- .../java/net/newpipe/newplayer/logic/MediaSourceBuilder.kt | 7 +++---- .../net/newpipe/newplayer/repository/MediaRepository.kt | 4 +--- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/new-player/src/main/java/net/newpipe/newplayer/NewPlayerImpl.kt b/new-player/src/main/java/net/newpipe/newplayer/NewPlayerImpl.kt index f6963d76..c04fcb72 100644 --- a/new-player/src/main/java/net/newpipe/newplayer/NewPlayerImpl.kt +++ b/new-player/src/main/java/net/newpipe/newplayer/NewPlayerImpl.kt @@ -501,7 +501,7 @@ internalPlayStream(mediaSource: MediaSource, playMode: PlayMode) { val builder = MediaSourceBuilder( repository = repository, mutableErrorFlow = mutableErrorFlow, - httpDataSourceFactory = repository.getHttpDataSourceFactory(item, app), + DataSourceFactory = repository.getDataSourceFactory(item, app), ) val uniqueId = Random.nextLong() diff --git a/new-player/src/main/java/net/newpipe/newplayer/logic/MediaSourceBuilder.kt b/new-player/src/main/java/net/newpipe/newplayer/logic/MediaSourceBuilder.kt index 4de3994a..dc94c83b 100644 --- a/new-player/src/main/java/net/newpipe/newplayer/logic/MediaSourceBuilder.kt +++ b/new-player/src/main/java/net/newpipe/newplayer/logic/MediaSourceBuilder.kt @@ -23,7 +23,6 @@ package net.newpipe.newplayer.logic import androidx.annotation.OptIn import androidx.media3.common.MediaItem import androidx.media3.common.util.UnstableApi -import androidx.media3.datasource.HttpDataSource import androidx.media3.datasource.DataSource import androidx.media3.exoplayer.dash.DashMediaSource import androidx.media3.exoplayer.source.MediaSource @@ -48,7 +47,7 @@ internal class MediaSourceBuilder ( private val repository: MediaRepository, private val mutableErrorFlow: MutableSharedFlow, - private val httpDataSourceFactory: DataSource.Factory, + private val DataSourceFactory: DataSource.Factory, ) { @OptIn(UnstableApi::class) @@ -106,10 +105,10 @@ internal suspend fun buildMediaSource( @OptIn(UnstableApi::class) private fun toMediaSource(mediaItem: MediaItem, stream: Stream): MediaSource = if (stream.isDashOrHls) - DashMediaSource.Factory(httpDataSourceFactory) + DashMediaSource.Factory(DataSourceFactory) .createMediaSource(mediaItem) else - ProgressiveMediaSource.Factory(httpDataSourceFactory) + ProgressiveMediaSource.Factory(DataSourceFactory) .createMediaSource(mediaItem) diff --git a/new-player/src/main/java/net/newpipe/newplayer/repository/MediaRepository.kt b/new-player/src/main/java/net/newpipe/newplayer/repository/MediaRepository.kt index f3ce08b8..442674ef 100644 --- a/new-player/src/main/java/net/newpipe/newplayer/repository/MediaRepository.kt +++ b/new-player/src/main/java/net/newpipe/newplayer/repository/MediaRepository.kt @@ -26,12 +26,10 @@ import android.graphics.Bitmap import androidx.media3.common.MediaMetadata import androidx.media3.datasource.DefaultHttpDataSource import androidx.media3.datasource.DataSource -import androidx.media3.datasource.HttpDataSource import net.newpipe.newplayer.data.Chapter import net.newpipe.newplayer.data.Stream import net.newpipe.newplayer.data.Subtitle import net.newpipe.newplayer.data.StreamTrack -import java.util.concurrent.Executors /** * You, dear Developer who uses NewPlayer, will want to implement MediaRepository. @@ -118,7 +116,7 @@ interface MediaRepository { /** * Supply a custom [HttpDataSource.Factory]. This is important for Youtube. */ - fun getHttpDataSourceFactory(item: String, context: Context): DataSource.Factory { + fun getDataSourceFactory(item: String, context: Context): DataSource.Factory { return DefaultHttpDataSource.Factory() } From 49c6f46ab7aafb7e8a1bb431b692bd0959a9dce7 Mon Sep 17 00:00:00 2001 From: uzu09811 <168120233+uzu09811@users.noreply.github.com> Date: Tue, 12 Nov 2024 09:54:43 +0530 Subject: [PATCH 3/4] Remove unused imports From 924d63ebe8d5b8872194145753d43054f44317dc Mon Sep 17 00:00:00 2001 From: uzu09811 <168120233+uzu09811@users.noreply.github.com> Date: Tue, 12 Nov 2024 09:58:16 +0530 Subject: [PATCH 4/4] typo --- .../src/main/java/net/newpipe/newplayer/NewPlayerImpl.kt | 2 +- .../java/net/newpipe/newplayer/logic/MediaSourceBuilder.kt | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/new-player/src/main/java/net/newpipe/newplayer/NewPlayerImpl.kt b/new-player/src/main/java/net/newpipe/newplayer/NewPlayerImpl.kt index c04fcb72..d12ebceb 100644 --- a/new-player/src/main/java/net/newpipe/newplayer/NewPlayerImpl.kt +++ b/new-player/src/main/java/net/newpipe/newplayer/NewPlayerImpl.kt @@ -501,7 +501,7 @@ internalPlayStream(mediaSource: MediaSource, playMode: PlayMode) { val builder = MediaSourceBuilder( repository = repository, mutableErrorFlow = mutableErrorFlow, - DataSourceFactory = repository.getDataSourceFactory(item, app), + dataSourceFactory = repository.getDataSourceFactory(item, app), ) val uniqueId = Random.nextLong() diff --git a/new-player/src/main/java/net/newpipe/newplayer/logic/MediaSourceBuilder.kt b/new-player/src/main/java/net/newpipe/newplayer/logic/MediaSourceBuilder.kt index dc94c83b..e4da2cbf 100644 --- a/new-player/src/main/java/net/newpipe/newplayer/logic/MediaSourceBuilder.kt +++ b/new-player/src/main/java/net/newpipe/newplayer/logic/MediaSourceBuilder.kt @@ -47,7 +47,7 @@ internal class MediaSourceBuilder ( private val repository: MediaRepository, private val mutableErrorFlow: MutableSharedFlow, - private val DataSourceFactory: DataSource.Factory, + private val dataSourceFactory: DataSource.Factory, ) { @OptIn(UnstableApi::class) @@ -105,10 +105,10 @@ internal suspend fun buildMediaSource( @OptIn(UnstableApi::class) private fun toMediaSource(mediaItem: MediaItem, stream: Stream): MediaSource = if (stream.isDashOrHls) - DashMediaSource.Factory(DataSourceFactory) + DashMediaSource.Factory(dataSourceFactory) .createMediaSource(mediaItem) else - ProgressiveMediaSource.Factory(DataSourceFactory) + ProgressiveMediaSource.Factory(dataSourceFactory) .createMediaSource(mediaItem)