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

Fix #1801: Audio player running after closing #4629

Merged

Conversation

KevinGitonga
Copy link
Contributor

@KevinGitonga KevinGitonga commented Sep 28, 2022

Explanation

Fix #1801
This fix adds check in the implemented playStatusLiveData to complete audioPause request if any is pending while the playerStatus keeps changing. When user clicks on pause audio icon and the UI disappears there is a delay in audio actually pausing. Adding a check in playStatusLiveData completes pause pending request fast enough to prevent it from playing.

Essential Checklist

  • The PR title and explanation each start with "Fix #bugnum: " (If this PR fixes part of an issue, prefix the title with "Fix part of #bugnum: ...".)
  • Any changes to scripts/assets files have their rationale included in the PR explanation.
  • The PR follows the style guide.
  • The PR does not contain any unnecessary code changes from Android Studio (reference).
  • The PR is made from a branch that's not called "develop" and is up-to-date with "develop".
  • The PR is assigned to the appropriate reviewers (reference).

For UI-specific PRs only

If your PR includes UI-related changes, then:

  • Add screenshots for portrait/landscape for both a tablet & phone of the before & after UI changes
  • For the screenshots above, include both English and pseudo-localized (RTL) screenshots (see RTL guide)
  • Add a video showing the full UX flow with a screen reader enabled (see accessibility guide)
  • Add a screenshot demonstrating that you ran affected Espresso tests locally & that they're passing

Before changes demo

20220928_111629.mp4

After changes demo

20220928_112012.mp4

Copy link
Sponsor Member

@BenHenning BenHenning left a comment

Choose a reason for hiding this comment

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

Thanks @KevinGitonga. I can see this conceptually working (though per the videos it seems like it does functionally work), but I think some clarity is needed into why this particular approach works since it doesn't seem to exactly be "throttle control" for pausing per my comment.

Once we finalize the solution, I think you can go ahead with writing tests. That being said, until then you should consider marking this PR as 'Draft' since it isn't technically complete yet (and thus not ready for a full review).

@oppiabot
Copy link

oppiabot bot commented Oct 18, 2022

Hi @KevinGitonga, I'm going to mark this PR as stale because it hasn't had any updates for 7 days. If no further activity occurs within 7 days, it will be automatically closed so that others can take up the issue.
If you are still working on this PR, please make a follow-up commit within 3 days (and submit it for review, if applicable). Please also let us know if you are stuck so we can help you!

@oppiabot oppiabot bot added the stale Corresponds to items that haven't seen a recent update and may be automatically closed. label Oct 18, 2022
@oppiabot oppiabot bot closed this Oct 25, 2022
@KevinGitonga KevinGitonga reopened this Oct 25, 2022
@oppiabot oppiabot bot removed the stale Corresponds to items that haven't seen a recent update and may be automatically closed. label Oct 25, 2022
@oppiabot
Copy link

oppiabot bot commented Nov 8, 2022

Hi @KevinGitonga, I'm going to mark this PR as stale because it hasn't had any updates for 7 days. If no further activity occurs within 7 days, it will be automatically closed so that others can take up the issue.
If you are still working on this PR, please make a follow-up commit within 3 days (and submit it for review, if applicable). Please also let us know if you are stuck so we can help you!

@oppiabot oppiabot bot added the stale Corresponds to items that haven't seen a recent update and may be automatically closed. label Nov 8, 2022
@oppiabot oppiabot bot closed this Nov 15, 2022
@KevinGitonga KevinGitonga reopened this Jan 17, 2023
@oppiabot oppiabot bot removed the stale Corresponds to items that haven't seen a recent update and may be automatically closed. label Jan 17, 2023
@KevinGitonga
Copy link
Contributor Author

KevinGitonga commented Jan 23, 2023

Hi @BenHenning yet to assert this in tests as it seems complex on grounds that the AudioPlayer is restarted when the user clicks on continue button to proceed to the next lesson in the Exploration, Also not able to find a suitable way to invoke ShadowMediaPlayer for this context. The cause of Audio Playing after the user clicks the pause button while playing on a given exploration might be caused by the below issue [1].

[1]. After observing my logs data the audio player continues to play since the audio player is not in a “prepared” state. This state is checked as noted here before actually performing a pause through the audioPlayerController in AudioViewModel here. The pause will be skipped as the player is not in a “prepared” state hence why audio will continue to play once the state changes to prepared here which is the expected behavior. This is despite the player ui fragment being hidden.

The solution which works for this issue is to insert an if statement to check if a previous pause request exists as the state changes inside of this observer directly and if at the moment we have a pending request which was not executed when pauseAudio was initially invoked here. This will work if only the state is “prepared” and we have a “pending” request to pause the audio player. Kindly PTAL and advice your thoughts on this.

@BenHenning
Copy link
Sponsor Member

Thanks for the write-up @KevinGitonga. As discussed during the meeting earlier, I think the next steps here are carefully documenting the solution & why the code works/shouldn't change if we can't actually verify this in a test.

@BenHenning BenHenning removed their assignment Jan 24, 2023
@KevinGitonga
Copy link
Contributor Author

Thanks @BenHenning

After observing my logs data the audio player continues to play since the audio player is not in a “prepared” state. This state is checked as noted here before actually performing a pause through the audioPlayerController in AudioViewModel here. The pause will be skipped as the player is not in a “prepared” state hence why audio will continue to play once the state changes to prepared here which is the expected behavior. This is despite the player view fragment being hidden.

The solution which works for this issue is to insert an if statement to check if a previous pause request exists as the state changes inside of this observer directly and if at the moment we have a pending request which was not executed when pauseAudio was initially invoked here. This will work if only the state is “prepared” and we have a “pending” request to pause the audio player.

The main reasons why this fix cannot be checked through tests in platforms available is because of system constraint's in testing audio. I could also not come up with a suitable way to test this after researching how to undertake this. For this scenario we would require to listen the state of audio or check the state of the player buttons which would not be applicable since the audio player view itself has already been hidden from the UI as part of the pause process.

I have added comments and links to this comments and the issue itself in the code to assist other developers understand the reasons for the checks.

Copy link
Sponsor Member

@BenHenning BenHenning left a comment

Choose a reason for hiding this comment

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

Thanks @KevinGitonga! Left one follow-up comment, otherwise the PR LGTM. PTAL.

Copy link
Sponsor Member

@BenHenning BenHenning left a comment

Choose a reason for hiding this comment

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

Thanks @KevinGitonga. I think you missed responding to the comment thread, but otherwise the PR LGTM.

@oppiabot
Copy link

oppiabot bot commented Feb 1, 2023

Unassigning @BenHenning since they have already approved the PR.

@oppiabot oppiabot bot added the PR: LGTM label Feb 1, 2023
@BenHenning BenHenning enabled auto-merge (squash) February 1, 2023 23:52
@BenHenning BenHenning merged commit 3eeb281 into oppia:develop Feb 2, 2023
supreme96 pushed a commit to supreme96/oppia-android that referenced this pull request Feb 24, 2023
## Explanation

Fix oppia#1801
This fix adds check in the implemented playStatusLiveData to complete
audioPause request if any is pending while the playerStatus keeps
changing. When user clicks on pause audio icon and the UI disappears
there is a delay in audio actually pausing. Adding a check in
playStatusLiveData completes pause pending request fast enough to
prevent it from playing.

## Essential Checklist
<!-- Please tick the relevant boxes by putting an "x" in them. -->
- [x] The PR title and explanation each start with "Fix #bugnum: " (If
this PR fixes part of an issue, prefix the title with "Fix part of
#bugnum: ...".)
- [ ] Any changes to
[scripts/assets](https://github.com/oppia/oppia-android/tree/develop/scripts/assets)
files have their rationale included in the PR explanation.
- [x] The PR follows the [style
guide](https://github.com/oppia/oppia-android/wiki/Coding-style-guide).
- [x] The PR does not contain any unnecessary code changes from Android
Studio
([reference](https://github.com/oppia/oppia-android/wiki/Guidance-on-submitting-a-PR#undo-unnecessary-changes)).
- [x] The PR is made from a branch that's **not** called "develop" and
is up-to-date with "develop".
- [x] The PR is **assigned** to the appropriate reviewers
([reference](https://github.com/oppia/oppia-android/wiki/Guidance-on-submitting-a-PR#clarification-regarding-assignees-and-reviewers-section)).

## For UI-specific PRs only
<!-- Delete these section if this PR does not include UI-related
changes. -->
If your PR includes UI-related changes, then:
- Add screenshots for portrait/landscape for both a tablet & phone of
the before & after UI changes
- For the screenshots above, include both English and pseudo-localized
(RTL) screenshots (see [RTL
guide](https://github.com/oppia/oppia-android/wiki/RTL-Guidelines))
- Add a video showing the full UX flow with a screen reader enabled (see
[accessibility
guide](https://github.com/oppia/oppia-android/wiki/Accessibility-(A11y)-Guide))
- Add a screenshot demonstrating that you ran affected Espresso tests
locally & that they're passing

## Before changes demo

https://user-images.githubusercontent.com/20886444/192735111-6baf46f8-3531-49f8-83d6-98277dc74c6d.mp4

## After changes demo

https://user-images.githubusercontent.com/20886444/192735968-13b7e2b5-e296-4978-9194-4df5b807897b.mp4

---------

Co-authored-by: Ben Henning <ben@oppia.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Audio player running after closing
2 participants