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

Always replace the playing request #1114

Merged
merged 1 commit into from
Mar 21, 2019
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -158,12 +158,6 @@ public static class AudioUpdateIntent {
// so user can pass in a serializable LegacyAudioRequest to the intent
public static final String EXTRA_PLAY_INFO = "com.quran.labs.androidquran.PLAY_INFO";

// ignore the passed in play info if we're already playing
public static final String EXTRA_IGNORE_IF_PLAYING = "com.quran.labs.androidquran.IGNORE_IF_PLAYING";

// used to override what is playing now (stop then play)
public static final String EXTRA_STOP_IF_PLAYING = "com.quran.labs.androidquran.STOP_IF_PLAYING";

// indicates the state our service:
private enum State {
Stopped, // media player is stopped and not prepared to play
Expand Down Expand Up @@ -415,20 +409,15 @@ private void handleIntent(Intent intent) {
} else if (ACTION_PLAYBACK.equals(action)) {
AudioRequest playInfo = intent.getParcelableExtra(EXTRA_PLAY_INFO);
if (playInfo != null) {
if (State.Stopped == state ||
!intent.getBooleanExtra(EXTRA_IGNORE_IF_PLAYING, false)) {
audioRequest = playInfo;

final SuraAyah start = audioRequest.getStart();
final boolean basmallah = !playInfo.isGapless() &&
SuraAyahExtensionKt.requiresBasmallah(start);
audioQueue = new AudioQueue(quranInfo, audioRequest,
new AudioPlaybackInfo(start, 1, 1, basmallah));
Crashlytics.log("audio request has changed...");
}
}
audioRequest = playInfo;

final SuraAyah start = audioRequest.getStart();
final boolean basmallah = !playInfo.isGapless() &&
SuraAyahExtensionKt.requiresBasmallah(start);
audioQueue = new AudioQueue(quranInfo, audioRequest,
new AudioPlaybackInfo(start, 1, 1, basmallah));
Crashlytics.log("audio request has changed...");

if (intent.getBooleanExtra(EXTRA_STOP_IF_PLAYING, false)) {
if (player != null) {
player.stop();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ public class PagerActivity extends QuranActionBarActivity implements
private int highlightedSura = -1;
private int highlightedAyah = -1;
private int ayahToolBarTotalHeight;
private boolean shouldOverridePlaying = false;
private DefaultDownloadReceiver downloadReceiver;
private boolean needsPermissionToDownloadOver3g = true;
private AlertDialog promptDialog = null;
Expand Down Expand Up @@ -1442,20 +1441,15 @@ public void onPlayPressed() {

private void playFromAyah(int page, int startSura, int startAyah) {
final SuraAyah start = new SuraAyah(startSura, startAyah);
playFromAyah(start, null, page, 0, 0, false, false);
playFromAyah(start, null, page, 0, 0, false);
}

public void playFromAyah(SuraAyah start,
SuraAyah end,
int page,
int verseRepeat,
int rangeRepeat,
boolean enforceRange,
boolean force) {
if (force) {
shouldOverridePlaying = true;
}

boolean enforceRange) {
final SuraAyah ending = end != null ? end :
audioUtils.getLastAyahToPlay(start, page,
quranSettings.getPreferredDownloadAmount(), isDualPages);
Expand Down Expand Up @@ -1499,16 +1493,6 @@ public void handlePlayback(AudioRequest request) {
audioStatusBar.setRepeatCount(request.getRepeatInfo());
}

if (shouldOverridePlaying) {
// force the current audio to stop and start playing new request
i.putExtra(AudioService.EXTRA_STOP_IF_PLAYING, true);
shouldOverridePlaying = false;
}
// just a playback request, so tell audio service to just continue
// playing (and don't store new audio data) if it was already playing
else {
i.putExtra(AudioService.EXTRA_IGNORE_IF_PLAYING, true);
}
Crashlytics.log("starting foreground service for audio playback");
ContextCompat.startForegroundService(this, i);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ private void apply() {
}
}
pagerActivity.playFromAyah(currentStart, currentEnding, page, verseRepeat,
rangeRepeat, enforceRange, true);
rangeRepeat, enforceRange);
} else if (shouldEnforce != enforceRange ||
rangeRepeatCount != rangeRepeat ||
verseRepeatCount != verseRepeat) {
Expand All @@ -162,7 +162,7 @@ private void apply() {
rangeRepeat, verseRepeat, enforceRange)) {
// audio stopped in the process, let's start it
pagerActivity.playFromAyah(currentStart, currentEnding, page, verseRepeat,
rangeRepeat, enforceRange, true);
rangeRepeat, enforceRange);
}
}
pagerActivity.endAyahMode();
Expand Down