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

Setting DataSource.Factory #18

Open
mikedawson opened this issue Jan 16, 2024 · 1 comment
Open

Setting DataSource.Factory #18

mikedawson opened this issue Jan 16, 2024 · 1 comment
Labels
enhancement New feature or request
Milestone

Comments

@mikedawson
Copy link

Hi,

I really, really, like this library. Much much easier to use than the 400+ line ExoPlayer "getting started" demo.

I needed to use the OkHttp DataSource (to enable playing videos that a user has downloaded offline via an OkHttp interceptor I made).

The current function signatures don't allow setting the DataSource.Factory. I made a fork with an option for the HttpDataSource here:

https://github.com/UstadMobile/compose-video

Add argument:

httpDataSourceFactory: HttpDataSource.Factory = remember {
        DefaultHttpDataSource.Factory()
    },

Use it:

.apply {
                val cache = VideoPlayerCacheManager.getCache()
                if (cache != null) {
                    val cacheDataSourceFactory = CacheDataSource.Factory()
                        .setCache(cache)
                        .setUpstreamDataSourceFactory(DefaultDataSource.Factory(context, httpDataSourceFactory))
                    setMediaSourceFactory(DefaultMediaSourceFactory(cacheDataSourceFactory))
                } else {
                    setMediaSourceFactory(DefaultMediaSourceFactory(httpDataSourceFactory))
                }
            }

It's now working with OkHttpDataSource. I'm not sure if that is the most elegant API. Maybe accepting the DataSource.Factory itself would be an option?

I'm happy to tidy submit this into a pull request if that helps.

@dsa28s
Copy link
Owner

dsa28s commented Jan 17, 2024

@mikedawson Hello mikedawson! I appreciate submit your issue. I think your suggestion is very useful. So, please submit pull request? Thank you!

@dsa28s dsa28s added the enhancement New feature or request label Jan 17, 2024
@dsa28s dsa28s added this to the 1.3.0 milestone Jan 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants