Skip to content

Error: Play not buffered data #3

@AndriiChemer

Description

@AndriiChemer

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
                        }
                    }
                }
            }
        }

    })

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions