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

Reset MediaPlayer on Stop and Completion in Android #559

Merged
merged 1 commit into from
Oct 31, 2023

Conversation

efstathiosntonas
Copy link
Contributor

No description provided.

Copy link
Owner

@hyochan hyochan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@efstathiosntonas Thank you for your contribution to this! Could you kindly explain the result of having reset after stop?

@hyochan hyochan added 🍗 enhancement New feature or request 🤖 android Related to android labels Oct 31, 2023
@efstathiosntonas
Copy link
Contributor Author

efstathiosntonas commented Oct 31, 2023

@hyochan I've looked into other Android projects on GitHub that utilized MediaPlayer and most of them reset the player.

Besides that, here is a part from the docs:

There is a subtle but important difference between a newly constructed MediaPlayer object and the MediaPlayer object after reset() is called. It is a programming error to invoke methods such as getCurrentPosition(), getDuration(), getVideoHeight(), getVideoWidth(), setAudioAttributes(android.media.AudioAttributes), setLooping(boolean), setVolume(float, float), pause(), start(), stop(), seekTo(long, int), prepare() or prepareAsync() in the Idle state for both cases. If any of these methods is called right after a MediaPlayer object is constructed, the user supplied callback method OnErrorListener.onError() won't be called by the internal player engine and the object state remains unchanged; but if these methods are called right after reset(), the user supplied callback method OnErrorListener.onError() will be invoked by the internal player engine and the object will be transfered to the Error state

Copy link
Owner

@hyochan hyochan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Screenshot 2023-10-31 at 8 34 03 PM

Here's ChatGPT's response to this. According to it, we can skip it. However, considering that in this module, the mediaPlayer is reused in every scenario, I think it would be a good idea to include reset in each step.

LGTM!

@hyochan hyochan changed the title properly reset player on stop and onCompletionListener on Android Reset MediaPlayer on Stop and Completion in Android Oct 31, 2023
@hyochan hyochan merged commit 3f29896 into hyochan:main Oct 31, 2023
1 check passed
@hyochan hyochan mentioned this pull request Oct 31, 2023
hyochan added a commit that referenced this pull request Oct 31, 2023
Android Recorder Reset on Stop
Refactor: Eliminate Redundant Release Command

---------

Co-authored-by: Efstathios Ntonas <stathis@hikiapp.com>
Co-authored-by: hyochan <dooboolab@gmail.com>
@efstathiosntonas
Copy link
Contributor Author

perfect! thanks @hyochan

@efstathiosntonas efstathiosntonas deleted the properly-reset-player branch October 31, 2023 11:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤖 android Related to android 🍗 enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants