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

Android: synchronous prepare #872

Closed

Conversation

fdietze
Copy link
Contributor

@fdietze fdietze commented May 5, 2021

Android:
If you try to seek immediately after calling setUrl, the following errors are reported:

error: MediaPlayer error with what:MEDIA_ERROR_UNKNOWN {extra:-2147483646}
Attempt to perform seekTo in wrong state: mPlayer=0x766f3e8b00, mCurrentState=0
error (-38, 0)

The problem lies in prepareAsync() being used. setUrl then reports that the player is ready, but in most cases it's not. Using prepare() instead fixes the problem.

I tested it for mp3 files and mp3 urls.

The documentation states:

For streams, you should call prepareAsync(), which returns immediately, rather than blocking until enough data has been buffered.

I interpret this as: It can still be used for streams, it's just blocking a bit longer until enough data is buffered for playing.

fixes:
#266

Might fix:
#865 #843

@luanpotter
Copy link
Member

I already have a prepared variable that is set to false when the player is not prepared, and then I have a Prepare Listener that updates that variable. the reason to use prepareAsync is to not lock the main thread while the player prepares, which can take a while.

I think the real issue is one of:

  • we are not reseting prepare to false properly when it should, thus it is kept as true from previous usage
  • seek is not correctly checking the prepare variable before attempting modify player state

@luanpotter
Copy link
Member

Closing this as we should not do sync prepare on the main thread. We can consider if there are any issues with the current setting of the prepared variable anyway on followups.

@luanpotter luanpotter closed this Apr 3, 2022
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

Successfully merging this pull request may close these issues.

None yet

2 participants