Search in sources :

Example 1 with AudioRequest

use of com.quran.labs.androidquran.service.util.AudioRequest in project quran_android by quran.

the class AyahPlaybackFragment method refreshView.

@Override
protected void refreshView() {
    final Context context = getActivity();
    if (context instanceof PagerActivity && start != null && end != null) {
        final AudioRequest lastRequest = ((PagerActivity) context).getLastAudioRequest();
        final SuraAyah start;
        final SuraAyah ending;
        if (lastRequest != null) {
            start = lastRequest.getRangeStart();
            ending = lastRequest.getRangeEnd();
            verseRepeatCount = lastRequest.getRepeatInfo().getRepeatCount();
            rangeRepeatCount = lastRequest.getRangeRepeatCount();
            shouldEnforce = lastRequest.shouldEnforceBounds();
            decidedStart = start;
            decidedEnd = ending;
            applyButton.setText(R.string.play_apply);
        } else {
            start = this.start;
            if (this.start.equals(end)) {
                final int startPage = quranInfo.getPageFromSuraAyah(start.sura, start.ayah);
                final int[] pageBounds = quranInfo.getPageBounds(startPage);
                ending = new SuraAyah(pageBounds[2], pageBounds[3]);
                shouldEnforce = false;
            } else {
                ending = end;
                shouldEnforce = true;
            }
            rangeRepeatCount = 0;
            verseRepeatCount = 0;
            decidedStart = null;
            decidedEnd = null;
            applyButton.setText(R.string.play_apply_and_play);
        }
        final int maxAyat = quranInfo.getNumAyahs(start.sura);
        if (maxAyat == -1) {
            return;
        }
        updateAyahSpinner(startAyahSpinner, startAyahAdapter, maxAyat, start.ayah);
        final int endAyat = (ending.sura == start.sura) ? maxAyat : quranInfo.getNumAyahs(ending.sura);
        updateAyahSpinner(endingAyahSpinner, endingAyahAdapter, endAyat, ending.ayah);
        startSuraSpinner.setSelection(start.sura - 1);
        endingSuraSpinner.setSelection(ending.sura - 1);
        repeatRangeSpinner.setSelection(repeatToPosition(rangeRepeatCount));
        repeatVerseSpinner.setSelection(repeatToPosition(verseRepeatCount));
        restrictToRange.setChecked(shouldEnforce);
    }
}
Also used : Context(android.content.Context) AudioRequest(com.quran.labs.androidquran.service.util.AudioRequest) SuraAyah(com.quran.labs.androidquran.data.SuraAyah) PagerActivity(com.quran.labs.androidquran.ui.PagerActivity)

Example 2 with AudioRequest

use of com.quran.labs.androidquran.service.util.AudioRequest in project quran_android by quran.

the class PagerActivity method playStreaming.

private void playStreaming(SuraAyah ayah, SuraAyah end, int page, QariItem item, int verseRepeat, int rangeRepeat, boolean enforceRange) {
    String qariUrl = audioUtils.getQariUrl(item);
    String dbFile = audioUtils.getQariDatabasePathIfGapless(this, item);
    if (!TextUtils.isEmpty(dbFile)) {
        // gapless audio is "download only"
        lastAudioDownloadRequest = getAudioDownloadRequest(ayah, end, page, item, verseRepeat, rangeRepeat, enforceRange);
        playAudioRequest(lastAudioDownloadRequest);
        return;
    }
    final SuraAyah ending;
    if (end != null) {
        ending = end;
    } else {
        // this won't be enforced unless the user sets a range
        // repeat, but we set it to a sane default anyway.
        ending = audioUtils.getLastAyahToPlay(ayah, page, quranSettings.getPreferredDownloadAmount(), isDualPages);
    }
    AudioRequest request = new StreamingAudioRequest(qariUrl, ayah, quranInfo.getNumAyahs(ayah.sura));
    request.setPlayBounds(ayah, ending);
    request.setEnforceBounds(enforceRange);
    request.setRangeRepeatCount(rangeRepeat);
    request.setVerseRepeatCount(verseRepeat);
    play(request);
    audioStatusBar.switchMode(AudioStatusBar.PLAYING_MODE);
    audioStatusBar.setRepeatCount(verseRepeat);
}
Also used : StreamingAudioRequest(com.quran.labs.androidquran.service.util.StreamingAudioRequest) DownloadAudioRequest(com.quran.labs.androidquran.service.util.DownloadAudioRequest) AudioRequest(com.quran.labs.androidquran.service.util.AudioRequest) SuraAyah(com.quran.labs.androidquran.data.SuraAyah) StreamingAudioRequest(com.quran.labs.androidquran.service.util.StreamingAudioRequest)

Example 3 with AudioRequest

use of com.quran.labs.androidquran.service.util.AudioRequest 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;
}
Also used : RepeatInfo(com.quran.labs.androidquran.service.util.RepeatInfo) AudioRequest(com.quran.labs.androidquran.service.util.AudioRequest) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent)

Aggregations

AudioRequest (com.quran.labs.androidquran.service.util.AudioRequest)3 SuraAyah (com.quran.labs.androidquran.data.SuraAyah)2 PendingIntent (android.app.PendingIntent)1 Context (android.content.Context)1 Intent (android.content.Intent)1 DownloadAudioRequest (com.quran.labs.androidquran.service.util.DownloadAudioRequest)1 RepeatInfo (com.quran.labs.androidquran.service.util.RepeatInfo)1 StreamingAudioRequest (com.quran.labs.androidquran.service.util.StreamingAudioRequest)1 PagerActivity (com.quran.labs.androidquran.ui.PagerActivity)1