-
Notifications
You must be signed in to change notification settings - Fork 6k
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
Allow MediaSource instances to be reused #3498
Comments
Media sources shouldn't be reused (documented here). This includes the dynamic concatenating media source as well as the single playlist item media sources. |
Could/should we add some assertions that check this and give a developer friendly error message? Seems like an easy mistake to make. |
I think we can also make DynamicConcatenatingMediaSource reusable (despite the general guideline). This would deliberately allow reusing the wrapping dynamic media source. Marking this as enhancement to do this. |
To clarify: this enhancement tracks reusing media sources in general. Reusing just the DynamicConcatenatingMediaSource wouldn't make sense if the contained media sources can't be reused. |
GitHub:#3498 ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=183253017
GitHub:#3498 ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=183369041
GitHub:#3498 ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=183373647
GitHub:#3498 ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=183378776
…ources. This removes some boiler-plate code for compostite sources and will also simplify resuing media source in the future (because this class can keep track of child listeners). Issue:#3498 ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=183387123
GitHub:#3498 ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=183391117
GitHub:#3498 ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=183392095
Issue:#3498 ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=183648419
Also fixes a bug where deferred media periods were kept in the list for an unprepared media source although the media period was already released. Issue:#3498 ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=183800889
This make sure all media sources can be reprepared after being released. Issue:#3498 ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=183990416
@tonihei @ojw28 it is great to see that MediaSource can be reused. I still not see javadoc update for it in dev-v2. Do you plan it for 2.7.0 or it must be in the release after? I have a couple question about this:
Thanks. |
The current updates mentioned above are only one part of making MediaSource reusable. You should now be able to re-prepare with the same media source. However, we are still working on the possibility to reuse media source in parallel, e.g. adding them twice to a ConcatenatingMediaSource. That's also why we haven't updated the docs yet because we only do this after the feature is fully implemented and ready to use. It will most likely be part of 2.7.0. For the second question: |
Up to now we use a boolean "preventListenerNotification" to suppress updates while other operations are still in progress. This ensures, for example, that only one initial timeline is issued even for multiple child sources. As soon as we allow to reuse the same instance, it becomes increasingly difficult to manage this manual listener notification suppression. Therefore, this change schedules an update as a new message on the playback thread immediately after the current message. This way, we also ensure that all simultaneous updates within one looper message iteration are reported together. Issue:#3498 ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=187180342
This is achieved by adding a BaseMediaSource which keeps a reference count of the number of times the source has been prepared and forwards to the actual implementations only once, such that only minimal changes are needed for each media source. Issue:#3498 ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=187186691
Especially the cast demo app benefits from this feature as it can keep its ConcatenatingMediaSource all the time without having to repopulate it when switching players. Issue:#3498 ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=187866048
Closing this issue as the feature is now available in the dev-branch. |
@prat-z Sorry, this will be the only restriction. Using the same media source simultaneously from multiple players would require us to synchronize the access to the source which we currently avoid by using it from one player at a time only. However, creating a media source isn't that cost-intensive and this is really mostly a convenience feature. So you wouldn't save much by avoiding to create a new media source for your second player anyway. This feature is already in the dev-branch if you want to try it out. And it's going to be part of release 2.8. |
@tonihei The problem with creating a new media source is that I am using HLSMediaSource, and creating a new data source means loosing out on the downloaded bytes of the same video, and a buffering state while switching to and from full screen mode. |
@prat-z Reusing media source wouldn't solve that I'm afraid. To keep the buffered video data when switching to and from full screen mode, you need to make sure to keep the same player instance. Please have a look around our issue tracker for fullscreen related issues. There are also various suggestions on the web how to implement fullscreen switching with ExoPlayer. Because of the different behavior on different Android versions, there is unfortunately no single, simple way to do this. If you have more question regarding full-screen switching, please open a new issue. |
Issue description
Passing the same DynamicConcatenatingMediaSource to a new SimpleExoPlayer instance doubles the internal mediaSourceHolders which in turn breaks the Player behaviour
Reproduction steps
Put the activity in background and then bring the app in the foreground.
Version of ExoPlayer being used
r2.5.4
Device(s) and version(s) of Android being used
Samsung Galaxy S7, Android 7.0
The text was updated successfully, but these errors were encountered: