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

Error: Play not buffered data #3

Open
AndriiChemer opened this issue Jul 1, 2021 · 0 comments
Open

Error: Play not buffered data #3

AndriiChemer opened this issue Jul 1, 2021 · 0 comments

Comments

@AndriiChemer
Copy link

I had a problem when I was playing a long audio URL, for example, after 800 seconds, I had an error because the data was not buffered. It seems to me that this hook solves this problem

       player.setOnBufferingUpdateListener(object : MediaPlayer.OnBufferingUpdateListener {
        override fun onBufferingUpdate(mp: MediaPlayer?, percent: Int) {
            if (shouldSeekTo > 0) {

                mp?.let {
                    val duration = it.duration
                    val startFromInPercentage = ((shouldSeekTo * 100) / duration)

                    Log.d("WrappedMediaPlayer", "onBufferingUpdate: $percent\trequired: $startFromInPercentage")

                    if (percent > startFromInPercentage) {
                        if (!it.isPlaying) {
                            mp.start()
                            ref.handleIsPlaying()
                            playing = true
                        }

                        it.seekTo(shouldSeekTo)
                        shouldSeekTo = -1
                    } else {
                        if (it.isPlaying) {
                            it.pause()
                            playing = false
                        }
                    }
                }
            }
        }

    })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant