Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement CronetEngine and HttpEngine support #7

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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),
dataSourceFactory = repository.getDataSourceFactory(item, app),
)

val uniqueId = Random.nextLong()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ 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
import androidx.media3.exoplayer.source.MergingMediaSource
Expand All @@ -47,7 +47,7 @@ internal class MediaSourceBuilder
(
private val repository: MediaRepository,
private val mutableErrorFlow: MutableSharedFlow<Exception>,
private val httpDataSourceFactory: HttpDataSource.Factory,
private val dataSourceFactory: DataSource.Factory,
) {
@OptIn(UnstableApi::class)

Expand Down Expand Up @@ -105,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)


Expand Down
uzu09811 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@

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.HttpDataSource
import androidx.media3.datasource.DataSource
import net.newpipe.newplayer.data.Chapter
import net.newpipe.newplayer.data.Stream
import net.newpipe.newplayer.data.Subtitle
Expand Down Expand Up @@ -114,8 +116,9 @@ interface MediaRepository {
/**
* Supply a custom [HttpDataSource.Factory]. This is important for Youtube.
*/
fun getHttpDataSourceFactory(item: String): HttpDataSource.Factory =
DefaultHttpDataSource.Factory()
fun getDataSourceFactory(item: String, context: Context): DataSource.Factory {
return DefaultHttpDataSource.Factory()
}

/**
* Get MediaMetadata information for a certain item. Please refer to the media3 documentation
Expand Down