dsa28s / compose-video

Video UI Component for Jetpack Compose (Powered by androidx.media3)
https://dsa28s.github.io/compose-video/
Apache License 2.0
252 stars 32 forks source link

Setting DataSource.Factory #18

Open mikedawson opened 10 months ago

mikedawson commented 10 months ago

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 commented 10 months ago

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