use of com.quran.labs.androidquran.service.util.RepeatInfo in project quran_android by quran.
the class AudioService method onStartCommand.
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
if (intent == null) {
// handle a crash that occurs where intent comes in as null
if (State.Stopped == state) {
handler.removeCallbacksAndMessages(null);
stopSelf();
}
return START_NOT_STICKY;
}
final String action = intent.getAction();
if (ACTION_CONNECT.equals(action)) {
if (State.Stopped == state) {
processStopRequest(true);
} else {
int sura = -1;
int ayah = -1;
int repeatCount = -200;
int state = AudioUpdateIntent.PLAYING;
if (State.Paused == this.state) {
state = AudioUpdateIntent.PAUSED;
}
if (audioRequest != null) {
sura = audioRequest.getCurrentSura();
ayah = audioRequest.getCurrentAyah();
final RepeatInfo repeatInfo = audioRequest.getRepeatInfo();
if (repeatInfo != null) {
repeatCount = repeatInfo.getRepeatCount();
}
}
Intent updateIntent = new Intent(AudioUpdateIntent.INTENT_NAME);
updateIntent.putExtra(AudioUpdateIntent.STATUS, state);
updateIntent.putExtra(AudioUpdateIntent.SURA, sura);
updateIntent.putExtra(AudioUpdateIntent.AYAH, ayah);
updateIntent.putExtra(AudioUpdateIntent.REPEAT_COUNT, repeatCount);
updateIntent.putExtra(AudioUpdateIntent.REQUEST, audioRequest);
broadcastManager.sendBroadcast(updateIntent);
}
} 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;
Crashlytics.log("audio request has changed...");
}
}
if (intent.getBooleanExtra(EXTRA_STOP_IF_PLAYING, false)) {
if (player != null) {
player.stop();
}
state = State.Stopped;
Crashlytics.log("stop if playing...");
}
processTogglePlaybackRequest();
} else if (ACTION_PLAY.equals(action)) {
processPlayRequest();
} else if (ACTION_PAUSE.equals(action)) {
processPauseRequest();
} else if (ACTION_SKIP.equals(action)) {
processSkipRequest();
} else if (ACTION_STOP.equals(action)) {
processStopRequest();
} else if (ACTION_REWIND.equals(action)) {
processRewindRequest();
} else if (ACTION_UPDATE_REPEAT.equals(action)) {
if (audioRequest != null) {
// set the repeat info if applicable
final int verseRepeatCount = intent.getIntExtra(EXTRA_VERSE_REPEAT_COUNT, audioRequest.getVerseRepeatCount());
audioRequest.setVerseRepeatCount(verseRepeatCount);
// set the range repeat count
final int rangeRepeatCount = intent.getIntExtra(EXTRA_RANGE_REPEAT_COUNT, audioRequest.getRangeRepeatCount());
audioRequest.setRangeRepeatCount(rangeRepeatCount);
// set the enforce range flag
if (intent.hasExtra(EXTRA_RANGE_RESTRICT)) {
final boolean enforceRange = intent.getBooleanExtra(EXTRA_RANGE_RESTRICT, false);
audioRequest.setEnforceBounds(enforceRange);
}
}
} else {
MediaButtonReceiver.handleIntent(mediaSession, intent);
}
// we don't want the service to restart if killed
return START_NOT_STICKY;
}
Aggregations