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 #5451 : java.lang.IllegalStateException - Media player has not been previously initialized #5474

Closed
Closed
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -125,24 +125,33 @@ class AudioPlayerController @Inject constructor(

private fun setMediaPlayerListeners() {
mediaPlayer.setOnCompletionListener {
completed = true
stopUpdatingSeekBar()
playProgress?.value =
AsyncResult.Success(PlayProgress(PlayStatus.COMPLETED, 0, duration))
audioLock.withLock {
completed = true
stopUpdatingSeekBar()
playProgress?.value =
AsyncResult.Success(PlayProgress(PlayStatus.COMPLETED, 0, duration))
}
}
mediaPlayer.setOnPreparedListener {
prepared = true
duration = it.duration
playProgress?.value =
AsyncResult.Success(PlayProgress(PlayStatus.PREPARED, 0, duration))
audioLock.withLock {
prepared = true
duration = it.duration
playProgress?.value =
AsyncResult.Success(PlayProgress(PlayStatus.PREPARED, 0, duration))
}
}
mediaPlayer.setOnErrorListener { _, what, extra ->
playProgress?.value =
AsyncResult.Failure(
AudioPlayerException("Audio Player put in error state with what: $what and extra: $extra")
)
releaseMediaPlayer()
initializeMediaPlayer()
audioLock.withLock {
playProgress?.value =
AsyncResult.Failure(
AudioPlayerException(
"Audio Player put in error state with what: $what " +
"and extra: $extra"
)
)
releaseMediaPlayer()
initializeMediaPlayer()
}
// Indicates that error was handled and to not invoke completion listener.
return@setOnErrorListener true
}
Expand Down Expand Up @@ -251,11 +260,12 @@ class AudioPlayerController @Inject constructor(
*/
fun releaseMediaPlayer() {
audioLock.withLock {
check(mediaPlayerActive) { "Media player has not been previously initialized" }
Copy link
Collaborator

@theMr17 theMr17 Jul 30, 2024

Choose a reason for hiding this comment

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

can anyone help me to understand why did some checks fail?

Hi @subhajitxyz, removal of this message is causing the check to fail. The test testController_notInitialized_releasePlayer_fails asserts this exception to be thrown with the message.

Here is the stacktrace of the failing check:
https://github.com/oppia/oppia-android/actions/runs/10132648197/job/28016870105?pr=5474#step:13:1878

if (mediaPlayerActive) {
mediaPlayer.release()
}
mediaPlayerActive = false
isReleased = true
prepared = false
mediaPlayer.release()
stopUpdatingSeekBar()
playProgress = null
}
Expand Down
Loading