Skip to content

Commit

Permalink
Allow using non-http data sources (e.g. cronet)
Browse files Browse the repository at this point in the history
  • Loading branch information
uzu09811 authored and Stypox committed Nov 10, 2024
1 parent 89d6f16 commit 197cc9b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -47,7 +48,7 @@ internal class MediaSourceBuilder
(
private val repository: MediaRepository,
private val mutableErrorFlow: MutableSharedFlow<Exception>,
private val httpDataSourceFactory: HttpDataSource.Factory,
private val httpDataSourceFactory: DataSource.Factory,
) {
@OptIn(UnstableApi::class)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 197cc9b

Please sign in to comment.