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

How to lazy load media source for a playlist in ExoPlayer? #7087

Closed
Cubxity opened this issue Mar 14, 2020 · 9 comments
Closed

How to lazy load media source for a playlist in ExoPlayer? #7087

Cubxity opened this issue Mar 14, 2020 · 9 comments
Assignees
Labels

Comments

@Cubxity
Copy link

Cubxity commented Mar 14, 2020

When filing a question:

[REQUIRED] Searched documentation and issues

  • I have looked at questions on Stackoverflow

[REQUIRED] Question

I would like to lazily load media sources for a playlist. When the user clicks previous/next, then I will call the API to retrieve the streaming URI for the previous/next video in the playlist.
For example:

@marcbaechinger
Copy link
Contributor

If you are using the ConcatenatingMediaSource you can choose to have the child media source lazily prepared by passing the useLazyInitialization flag accordingly to the constructor.

I'm not quite sure what your use case is. It may be the above is not enough. You may also want to look into the ResolvingDataSource which allows you to wait with setting up the end point on a data source level.

@Cubxity
Copy link
Author

Cubxity commented Mar 16, 2020

Are there any examples regarding this feature?

@Cubxity
Copy link
Author

Cubxity commented Mar 16, 2020

Also, ResolvingDataSource only resolves the DataSpec lazily not the MediaSource itself.

@marcbaechinger
Copy link
Contributor

Can you explain you r use case a little bit? If resolving data source is not sufficient, I reckon that the type of the MediaSource can change between being added to the playlist and starting to play? So you don't know whether it is an adaptive stream (eg. DASH/HSL) or a progressive stream?

Like in your steps above the type of MediaSource is not known until step "The app created the media source"?

@Cubxity
Copy link
Author

Cubxity commented Mar 16, 2020

So basically I only have basic data about each media in the playlist. F.ex id, title, thumbnails, etc. I don't know anything about the type of the stream until the streaming data is loaded. I would like to load the streaming data lazily upon previous/next.

@marcbaechinger
Copy link
Contributor

In this case I don't think there is something which helps you out of the box.

You can look into creating your own MediaSource which acts as a facade and when prepare() is called, fetches the uri, detects what type of media source is required and creates it internally. If you go down that route I recommend looking into CompositeMediaSource which is an abstract implementation which might be helpful for implementing what you want. You can check subclasses of CompositeMediaSource like the ClippingMediaSource just to learn about how to use the CompositeMediaSource.

Of course you can also only just rely on the MediaSource interface.

@Cubxity
Copy link
Author

Cubxity commented Mar 16, 2020

Thanks for the info. Do you know what apps like YouTube, Spotify does?

@marcbaechinger
Copy link
Contributor

I don't think they have such a requirement because they know beforehand what type of media source to use. They just populate a playlist with a MediaSource of a certain type and a uri.

@marcbaechinger
Copy link
Contributor

Closing due to inactivity. Please reopen if required.

@google google locked and limited conversation to collaborators Jun 23, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants