Skip to content

Commit

Permalink
Merge pull request #2539 from quran/fix_some_crashes
Browse files Browse the repository at this point in the history
Fix and catch some crashes
  • Loading branch information
ahmedre authored Jan 12, 2024
2 parents d067daa + 63cd8ff commit df9308e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -682,9 +682,15 @@ class AudioService : Service(), OnCompletionListener, OnPreparedListener,

private fun processUpdatePlaybackSpeed(speed: Float) {
if (State.Playing === state && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
player?.playbackParams?.let { params ->
params.setSpeed(speed)
player?.playbackParams = params
try {
player?.playbackParams?.let { params ->
params.setSpeed(speed)
player?.playbackParams = params
}
} catch (e: Exception) {
// catch an Android 6 crash [IllegalStateException], and report the speed since some
// non-Android 6 devices also crash here, but with [IllegalArgumentException]
Timber.e(e, "Failed to set speed to $speed")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,13 +239,15 @@ private void sendNoOpMessage(int id) {

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
// if it's a download, it wants to be a foreground service.
// quickly start as foreground before actually enqueueing the request.
if (ACTION_DOWNLOAD_URL.equals(intent.getAction())) {
notifier.notifyDownloadStarting();
}
if (intent != null) {
// if it's a download, it wants to be a foreground service.
// quickly start as foreground before actually enqueueing the request.
if (ACTION_DOWNLOAD_URL.equals(intent.getAction())) {
notifier.notifyDownloadStarting();
}

handleOnStartCommand(intent, startId);
handleOnStartCommand(intent, startId);
}
return START_NOT_STICKY;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.quran.labs.androidquran.ui

import android.app.BackgroundServiceStartNotAllowedException
import android.app.SearchManager
import android.content.ComponentName
import android.content.Context
Expand Down Expand Up @@ -160,9 +161,14 @@ class QuranActivity : AppCompatActivity(),
Completable.timer(500, MILLISECONDS)
.observeOn(AndroidSchedulers.mainThread())
.subscribe {
startService(
try {
startService(
audioUtils.getAudioIntent(this@QuranActivity, AudioService.ACTION_STOP)
)
)
} catch (illegalStateException: IllegalStateException) {
// do nothing, we might be in the background
// onPause should have stopped us from needing this, but it sometimes happens
}
}
)
}
Expand Down

0 comments on commit df9308e

Please sign in to comment.