-
Notifications
You must be signed in to change notification settings - Fork 482
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
MediaSourceFactory for different content types combined with the dynamic stream links #17
Comments
Possibly obvious question: Given the original 'dynamic' URL do you know whether it will resolve to a DASH or HLS URL? If you do know that in advance then you can just use Otherwise it sounds like you're looking for a 'do everything' |
Thanks for a quick reply. Regarding dynamic URL: yes, we could include stream type there & then set up mime type, but that's exactly what we'd like to avoid :) As for the draft commit you provided – this looks kinda promising. I'll take a deeper dive & get back to you |
I've dug into the example you provided and it's pretty much the same with what I've come up with. Thanks! |
We're currently improving out media architecture and there are obviously some things that can be done better. Currently, we support HLS & progressive content (DASH is also coming soon), so we need the Player to know what content it's going to play.
Normally, the player is able to figure out the content type itself from the URL when
DefaultMediaSourceFactory
is used. It takes a look at the item url increateMediaSource()
, determines the content type, and based on that loads the correspondentMediaSourceFactory
using reflection. So, if theMediaItem
url ends with.m3u8
,HlsMediaSourceFactory
will be used.However, this approach is not viable for us, since we're fetching the stream links dynamically (more on that here). So the url in MediaItem is not yet a valid one (it contains just information to fetch the link, smth like app://play?media_id=1). The actual url is fetched using
ResolvingDataSource
.Previously we were sending an additional field in our media responses from the backend that contained the available transport methods (HLS, DASH etc). Based on that, we were creating a correspondent
MediaSourceFactory
on the fly (thatMediaSourceFactory
was created withResolvingDataSource
). However, this seems to be a sort of hack that we'd like to avoid to make our app more scalable (not to mention that this does not fit into media3 architecture at all)After researching for some time, I've come with an idea. Smth relatively similar was already done here. So I decided to create a custom
MediaSource
extendingCompositeMediaSource
. It looks smth like this (unimportant parts are omitted):As you can see, it extends
CompositeMediaSource
& with the help of theLoader
resolves the actual url. After that, the actualMediaSource
is created using the wrappedDefaultMediaSourceFactory
& child source is prepared.This seems to be working, however, there are some things that do not feel right for me:
MediaSourceFactory
to theDynamicMediaSource
(I'm not sure if it's ok forMediaSource
to callMediaSourceFactory
methods)So is there any better way to achieve what I described or should I go with the code above?
The text was updated successfully, but these errors were encountered: