Search in sources :

Example 1 with AudioPlaybackInfo

use of com.quran.labs.androidquran.dao.audio.AudioPlaybackInfo in project quran_android by quran.

the class AudioService method handleIntent.

private void handleIntent(Intent intent) {
    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 (audioQueue != null && audioRequest != null) {
                sura = audioQueue.getCurrentSura();
                ayah = audioQueue.getCurrentAyah();
                repeatCount = audioRequest.getRepeatInfo();
            }
            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) {
            audioRequest = playInfo;
            final SuraAyah start = audioRequest.getStart();
            audioEventPresenter.onAyahPlayback(start);
            final boolean basmallah = !playInfo.isGapless() && SuraAyahExtensionKt.requiresBasmallah(start);
            audioQueue = new AudioQueue(quranInfo, audioRequest, new AudioPlaybackInfo(start, 1, 1, basmallah));
            Timber.d("audio request has changed...");
            if (player != null) {
                player.stop();
            }
            state = State.Stopped;
            Timber.d("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)) {
        final AudioRequest playInfo = intent.getParcelableExtra(EXTRA_PLAY_INFO);
        if (playInfo != null && audioQueue != null) {
            audioQueue = audioQueue.withUpdatedAudioRequest(playInfo);
            audioRequest = playInfo;
        }
    } else {
        MediaButtonReceiver.handleIntent(mediaSession, intent);
    }
}
Also used : AudioRequest(com.quran.labs.androidquran.dao.audio.AudioRequest) AudioPlaybackInfo(com.quran.labs.androidquran.dao.audio.AudioPlaybackInfo) SuraAyah(com.quran.data.model.SuraAyah) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) AudioQueue(com.quran.labs.androidquran.presenter.audio.service.AudioQueue)

Aggregations

PendingIntent (android.app.PendingIntent)1 Intent (android.content.Intent)1 SuraAyah (com.quran.data.model.SuraAyah)1 AudioPlaybackInfo (com.quran.labs.androidquran.dao.audio.AudioPlaybackInfo)1 AudioRequest (com.quran.labs.androidquran.dao.audio.AudioRequest)1 AudioQueue (com.quran.labs.androidquran.presenter.audio.service.AudioQueue)1