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

Can I use android.support.v7.util.ListUpdateCallback to update current playlist in ExoPlayer ? #4852

Closed
herintsoaRazaf opened this issue Sep 21, 2018 · 2 comments
Assignees
Labels

Comments

@herintsoaRazaf
Copy link

herintsoaRazaf commented Sep 21, 2018

Hi,

I'm trying to reorder the current playlist from ConcatenatingMediaSource mediaSources instance. If we supposed that we have a DiffUtil.DiffResult instance between the current playlist and a new one, can we use the interface android.support.v7.util.ListUpdateCallback to apply the change to the current playlist like :

diffResult.dispatchUpdatesTo(object : ListUpdateCallback {
                        override fun onChanged(position: Int, count: Int, payload: Any?) {
                            Timber.d("ListUpdateCallback.onChanged(position = $position, count = $count, payload = $payload)")
                        }

                        override fun onMoved(fromPosition: Int, toPosition: Int) {
                            Timber.d("ListUpdateCallback.onMoved(fromPosition = $fromPosition, toPosition = $toPosition)")
                            mediaSources.moveMediaSource(fromPosition, toPosition)
                        }

                        override fun onInserted(position: Int, count: Int) {
                            Timber.d("ListUpdateCallback.onInserted(position = $position, count = $count)")
                        }

                        override fun onRemoved(position: Int, count: Int) {
                            Timber.d("ListUpdateCallback.onRemoved(position = $position, count = $count)")
                            removeInMediaSource(position, 0, count)
                        }

                        private fun removeInMediaSource(position: Int, removedCount: Int, count: Int) {
                            if (removedCount >= count || mediaSources.size == position)
                                return

                            mediaSources.removeMediaSource(position) {
                                removeInMediaSource(position, removedCount + 1, count)
                            }
                        }

                    })

Is this callback implementation correct ?

I am interested only by the remove and move action on the playlist.

@andrewlewis andrewlewis self-assigned this Sep 21, 2018
@andrewlewis
Copy link
Collaborator

The overall approach looks fine. Were you running into issues with it? The dev-v2 branch has range-based removal which will help simplify removeInMediaSource (see also #4542).

@herintsoaRazaf
Copy link
Author

I just ask if some of you have already use this kind of implementation before to change the playlist on ExoPlayer.

@ojw28 ojw28 closed this as completed Oct 15, 2018
@google google locked and limited conversation to collaborators May 16, 2019
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