Search in sources :

Example 26 with Playable

use of de.danoeh.antennapod.core.util.playback.Playable in project AntennaPod by AntennaPod.

the class MediaplayerActivity method setupGUI.

protected void setupGUI() {
    setContentView(getContentViewResourceId());
    sbPosition = (SeekBar) findViewById(R.id.sbPosition);
    txtvPosition = (TextView) findViewById(R.id.txtvPosition);
    SharedPreferences prefs = getSharedPreferences(PREFS, MODE_PRIVATE);
    showTimeLeft = prefs.getBoolean(PREF_SHOW_TIME_LEFT, false);
    Log.d("timeleft", showTimeLeft ? "true" : "false");
    txtvLength = (TextView) findViewById(R.id.txtvLength);
    if (txtvLength != null) {
        txtvLength.setOnClickListener(v -> {
            showTimeLeft = !showTimeLeft;
            Playable media = controller.getMedia();
            if (media == null) {
                return;
            }
            String length;
            if (showTimeLeft) {
                length = "-" + Converter.getDurationStringLong(media.getDuration() - media.getPosition());
            } else {
                length = Converter.getDurationStringLong(media.getDuration());
            }
            txtvLength.setText(length);
            SharedPreferences.Editor editor = prefs.edit();
            editor.putBoolean(PREF_SHOW_TIME_LEFT, showTimeLeft);
            editor.apply();
            Log.d("timeleft on click", showTimeLeft ? "true" : "false");
        });
    }
    butRev = (ImageButton) findViewById(R.id.butRev);
    txtvRev = (TextView) findViewById(R.id.txtvRev);
    if (txtvRev != null) {
        txtvRev.setText(String.valueOf(UserPreferences.getRewindSecs()));
    }
    butPlay = (ImageButton) findViewById(R.id.butPlay);
    butFF = (ImageButton) findViewById(R.id.butFF);
    txtvFF = (TextView) findViewById(R.id.txtvFF);
    if (txtvFF != null) {
        txtvFF.setText(String.valueOf(UserPreferences.getFastFowardSecs()));
    }
    butSkip = (ImageButton) findViewById(R.id.butSkip);
    // SEEKBAR SETUP
    sbPosition.setOnSeekBarChangeListener(this);
    if (butRev != null) {
        butRev.setOnClickListener(v -> onRewind());
        butRev.setOnLongClickListener(new View.OnLongClickListener() {

            int choice;

            @Override
            public boolean onLongClick(View v) {
                int checked = 0;
                int rewindSecs = UserPreferences.getRewindSecs();
                final int[] values = getResources().getIntArray(R.array.seek_delta_values);
                final String[] choices = new String[values.length];
                for (int i = 0; i < values.length; i++) {
                    if (rewindSecs == values[i]) {
                        checked = i;
                    }
                    choices[i] = String.valueOf(values[i]) + " " + getString(R.string.time_seconds);
                }
                choice = values[checked];
                AlertDialog.Builder builder = new AlertDialog.Builder(MediaplayerActivity.this);
                builder.setTitle(R.string.pref_rewind);
                builder.setSingleChoiceItems(choices, checked, (dialog, which) -> choice = values[which]);
                builder.setNegativeButton(R.string.cancel_label, null);
                builder.setPositiveButton(R.string.confirm_label, (dialog, which) -> {
                    UserPreferences.setPrefRewindSecs(choice);
                    if (txtvRev != null) {
                        txtvRev.setText(String.valueOf(choice));
                    }
                });
                builder.create().show();
                return true;
            }
        });
    }
    butPlay.setOnClickListener(v -> onPlayPause());
    if (butFF != null) {
        butFF.setOnClickListener(v -> onFastForward());
        butFF.setOnLongClickListener(new View.OnLongClickListener() {

            int choice;

            @Override
            public boolean onLongClick(View v) {
                int checked = 0;
                int rewindSecs = UserPreferences.getFastFowardSecs();
                final int[] values = getResources().getIntArray(R.array.seek_delta_values);
                final String[] choices = new String[values.length];
                for (int i = 0; i < values.length; i++) {
                    if (rewindSecs == values[i]) {
                        checked = i;
                    }
                    choices[i] = String.valueOf(values[i]) + " " + getString(R.string.time_seconds);
                }
                choice = values[checked];
                AlertDialog.Builder builder = new AlertDialog.Builder(MediaplayerActivity.this);
                builder.setTitle(R.string.pref_fast_forward);
                builder.setSingleChoiceItems(choices, checked, (dialog, which) -> choice = values[which]);
                builder.setNegativeButton(R.string.cancel_label, null);
                builder.setPositiveButton(R.string.confirm_label, (dialog, which) -> {
                    UserPreferences.setPrefFastForwardSecs(choice);
                    if (txtvFF != null) {
                        txtvFF.setText(String.valueOf(choice));
                    }
                });
                builder.create().show();
                return true;
            }
        });
    }
    if (butSkip != null) {
        butSkip.setOnClickListener(v -> sendBroadcast(new Intent(PlaybackService.ACTION_SKIP_CURRENT_EPISODE)));
    }
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) Converter(de.danoeh.antennapod.core.util.Converter) PlaybackController(de.danoeh.antennapod.core.util.playback.PlaybackController) ImageButton(android.widget.ImageButton) Bundle(android.os.Bundle) SleepTimerDialog(de.danoeh.antennapod.dialog.SleepTimerDialog) Uri(android.net.Uri) AndroidSchedulers(rx.android.schedulers.AndroidSchedulers) Intent(android.content.Intent) PixelFormat(android.graphics.PixelFormat) TypedArray(android.content.res.TypedArray) MenuItem(android.view.MenuItem) Observable(rx.Observable) UserPreferences(de.danoeh.antennapod.core.preferences.UserPreferences) SeekBar(android.widget.SeekBar) CheckBox(android.widget.CheckBox) MenuInflater(android.view.MenuInflater) Locale(java.util.Locale) ShareUtils(de.danoeh.antennapod.core.util.ShareUtils) Toast(android.widget.Toast) Menu(android.view.Menu) Schedulers(rx.schedulers.Schedulers) View(android.view.View) Button(android.widget.Button) OnSeekBarChangeListener(android.widget.SeekBar.OnSeekBarChangeListener) StorageUtils(de.danoeh.antennapod.core.util.StorageUtils) Playable(de.danoeh.antennapod.core.util.playback.Playable) Build(android.os.Build) TargetApi(android.annotation.TargetApi) Log(android.util.Log) MediaPlayerError(de.danoeh.antennapod.core.util.playback.MediaPlayerError) PlaybackService(de.danoeh.antennapod.core.service.playback.PlaybackService) FeedMedia(de.danoeh.antennapod.core.feed.FeedMedia) R(de.danoeh.antennapod.R) VariableSpeedDialog(de.danoeh.antennapod.dialog.VariableSpeedDialog) Color(android.graphics.Color) FeedItem(de.danoeh.antennapod.core.feed.FeedItem) FontAwesomeIcons(com.joanzapata.iconify.fonts.FontAwesomeIcons) IconDrawable(com.joanzapata.iconify.IconDrawable) AlertDialog(android.support.v7.app.AlertDialog) TextView(android.widget.TextView) Glide(com.bumptech.glide.Glide) SharedPreferences(android.content.SharedPreferences) DBWriter(de.danoeh.antennapod.core.storage.DBWriter) Flavors(de.danoeh.antennapod.core.util.Flavors) DBReader(de.danoeh.antennapod.core.storage.DBReader) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) DBTasks(de.danoeh.antennapod.core.storage.DBTasks) SharedPreferences(android.content.SharedPreferences) Intent(android.content.Intent) View(android.view.View) TextView(android.widget.TextView) Playable(de.danoeh.antennapod.core.util.playback.Playable)

Example 27 with Playable

use of de.danoeh.antennapod.core.util.playback.Playable in project AntennaPod by AntennaPod.

the class MediaplayerActivity method onPrepareOptionsMenu.

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);
    if (controller == null) {
        return false;
    }
    Playable media = controller.getMedia();
    menu.findItem(R.id.support_item).setVisible(media != null && media.getPaymentLink() != null && (media instanceof FeedMedia) && ((FeedMedia) media).getItem() != null && ((FeedMedia) media).getItem().getFlattrStatus().flattrable());
    boolean hasWebsiteLink = media != null && media.getWebsiteLink() != null;
    menu.findItem(R.id.visit_website_item).setVisible(hasWebsiteLink);
    boolean isItemAndHasLink = media != null && (media instanceof FeedMedia) && ((FeedMedia) media).getItem() != null && ((FeedMedia) media).getItem().getLink() != null;
    menu.findItem(R.id.share_link_item).setVisible(isItemAndHasLink);
    menu.findItem(R.id.share_link_with_position_item).setVisible(isItemAndHasLink);
    boolean isItemHasDownloadLink = media != null && (media instanceof FeedMedia) && ((FeedMedia) media).getDownload_url() != null;
    menu.findItem(R.id.share_download_url_item).setVisible(isItemHasDownloadLink);
    menu.findItem(R.id.share_download_url_with_position_item).setVisible(isItemHasDownloadLink);
    menu.findItem(R.id.share_item).setVisible(hasWebsiteLink || isItemAndHasLink || isItemHasDownloadLink);
    menu.findItem(R.id.add_to_favorites_item).setVisible(false);
    menu.findItem(R.id.remove_from_favorites_item).setVisible(false);
    if (media != null && media instanceof FeedMedia) {
        menu.findItem(R.id.add_to_favorites_item).setVisible(!isFavorite);
        menu.findItem(R.id.remove_from_favorites_item).setVisible(isFavorite);
    }
    boolean sleepTimerSet = controller.sleepTimerActive();
    boolean sleepTimerNotSet = controller.sleepTimerNotActive();
    menu.findItem(R.id.set_sleeptimer_item).setVisible(sleepTimerNotSet);
    menu.findItem(R.id.disable_sleeptimer_item).setVisible(sleepTimerSet);
    if (this instanceof AudioplayerActivity) {
        int[] attrs = { R.attr.action_bar_icon_color };
        TypedArray ta = obtainStyledAttributes(UserPreferences.getTheme(), attrs);
        int textColor = ta.getColor(0, Color.GRAY);
        ta.recycle();
        menu.findItem(R.id.audio_controls).setIcon(new IconDrawable(this, FontAwesomeIcons.fa_sliders).color(textColor).actionBarSize());
    } else {
        menu.findItem(R.id.audio_controls).setVisible(false);
    }
    return true;
}
Also used : Playable(de.danoeh.antennapod.core.util.playback.Playable) FeedMedia(de.danoeh.antennapod.core.feed.FeedMedia) TypedArray(android.content.res.TypedArray) IconDrawable(com.joanzapata.iconify.IconDrawable)

Example 28 with Playable

use of de.danoeh.antennapod.core.util.playback.Playable in project AntennaPod by AntennaPod.

the class VideoplayerActivity method loadMediaInfo.

@Override
protected boolean loadMediaInfo() {
    if (!super.loadMediaInfo() || controller == null) {
        return false;
    }
    Playable media = controller.getMedia();
    if (media != null) {
        getSupportActionBar().setSubtitle(media.getEpisodeTitle());
        getSupportActionBar().setTitle(media.getFeedTitle());
        return true;
    }
    return false;
}
Also used : Playable(de.danoeh.antennapod.core.util.playback.Playable)

Example 29 with Playable

use of de.danoeh.antennapod.core.util.playback.Playable in project AntennaPod by AntennaPod.

the class PlaybackServiceMediaPlayerTest method testPlayMediaObjectStreamNoStartPrepare.

public void testPlayMediaObjectStreamNoStartPrepare() throws InterruptedException {
    final Context c = getInstrumentation().getTargetContext();
    final CountDownLatch countDownLatch = new CountDownLatch(4);
    PlaybackServiceMediaPlayer.PSMPCallback callback = new DefaultPSMPCallback() {

        @Override
        public void statusChanged(LocalPSMP.PSMPInfo newInfo) {
            try {
                checkPSMPInfo(newInfo);
                if (newInfo.playerStatus == PlayerStatus.ERROR)
                    throw new IllegalStateException("MediaPlayer error");
                if (countDownLatch.getCount() == 0) {
                    fail();
                } else if (countDownLatch.getCount() == 4) {
                    assertEquals(PlayerStatus.INITIALIZING, newInfo.playerStatus);
                } else if (countDownLatch.getCount() == 3) {
                    assertEquals(PlayerStatus.INITIALIZED, newInfo.playerStatus);
                } else if (countDownLatch.getCount() == 2) {
                    assertEquals(PlayerStatus.PREPARING, newInfo.playerStatus);
                } else if (countDownLatch.getCount() == 1) {
                    assertEquals(PlayerStatus.PREPARED, newInfo.playerStatus);
                }
                countDownLatch.countDown();
            } catch (AssertionFailedError e) {
                if (assertionError == null)
                    assertionError = e;
            }
        }
    };
    PlaybackServiceMediaPlayer psmp = new LocalPSMP(c, callback);
    Playable p = writeTestPlayable(PLAYABLE_FILE_URL, null);
    psmp.playMediaObject(p, true, false, true);
    boolean res = countDownLatch.await(LATCH_TIMEOUT_SECONDS, TimeUnit.SECONDS);
    if (assertionError != null)
        throw assertionError;
    assertTrue(res);
    assertTrue(psmp.getPSMPInfo().playerStatus == PlayerStatus.PREPARED);
    psmp.shutdown();
}
Also used : Context(android.content.Context) Playable(de.danoeh.antennapod.core.util.playback.Playable) LocalPSMP(de.danoeh.antennapod.core.service.playback.LocalPSMP) PlaybackServiceMediaPlayer(de.danoeh.antennapod.core.service.playback.PlaybackServiceMediaPlayer) CountDownLatch(java.util.concurrent.CountDownLatch) AssertionFailedError(junit.framework.AssertionFailedError)

Example 30 with Playable

use of de.danoeh.antennapod.core.util.playback.Playable in project AntennaPod by AntennaPod.

the class PlaybackServiceMediaPlayerTest method testPlayMediaObjectLocalStartNoPrepare.

public void testPlayMediaObjectLocalStartNoPrepare() throws InterruptedException {
    final Context c = getInstrumentation().getTargetContext();
    final CountDownLatch countDownLatch = new CountDownLatch(2);
    PlaybackServiceMediaPlayer.PSMPCallback callback = new DefaultPSMPCallback() {

        @Override
        public void statusChanged(LocalPSMP.PSMPInfo newInfo) {
            try {
                checkPSMPInfo(newInfo);
                if (newInfo.playerStatus == PlayerStatus.ERROR)
                    throw new IllegalStateException("MediaPlayer error");
                if (countDownLatch.getCount() == 0) {
                    fail();
                } else if (countDownLatch.getCount() == 2) {
                    assertEquals(PlayerStatus.INITIALIZING, newInfo.playerStatus);
                    countDownLatch.countDown();
                } else {
                    assertEquals(PlayerStatus.INITIALIZED, newInfo.playerStatus);
                    countDownLatch.countDown();
                }
            } catch (AssertionFailedError e) {
                if (assertionError == null)
                    assertionError = e;
            }
        }
    };
    PlaybackServiceMediaPlayer psmp = new LocalPSMP(c, callback);
    Playable p = writeTestPlayable(PLAYABLE_FILE_URL, PLAYABLE_LOCAL_URL);
    psmp.playMediaObject(p, false, true, false);
    boolean res = countDownLatch.await(LATCH_TIMEOUT_SECONDS, TimeUnit.SECONDS);
    if (assertionError != null)
        throw assertionError;
    assertTrue(res);
    assertTrue(psmp.getPSMPInfo().playerStatus == PlayerStatus.INITIALIZED);
    assertTrue(psmp.isStartWhenPrepared());
    psmp.shutdown();
}
Also used : Context(android.content.Context) Playable(de.danoeh.antennapod.core.util.playback.Playable) LocalPSMP(de.danoeh.antennapod.core.service.playback.LocalPSMP) PlaybackServiceMediaPlayer(de.danoeh.antennapod.core.service.playback.PlaybackServiceMediaPlayer) CountDownLatch(java.util.concurrent.CountDownLatch) AssertionFailedError(junit.framework.AssertionFailedError)

Aggregations

Playable (de.danoeh.antennapod.core.util.playback.Playable)40 Context (android.content.Context)15 CountDownLatch (java.util.concurrent.CountDownLatch)15 LocalPSMP (de.danoeh.antennapod.core.service.playback.LocalPSMP)11 PlaybackServiceMediaPlayer (de.danoeh.antennapod.core.service.playback.PlaybackServiceMediaPlayer)11 AssertionFailedError (junit.framework.AssertionFailedError)11 FeedMedia (de.danoeh.antennapod.core.feed.FeedMedia)8 FeedItem (de.danoeh.antennapod.core.feed.FeedItem)7 Intent (android.content.Intent)4 PlaybackServiceTaskManager (de.danoeh.antennapod.core.service.playback.PlaybackServiceTaskManager)4 Timeline (de.danoeh.antennapod.core.util.playback.Timeline)4 SharedPreferences (android.content.SharedPreferences)3 TypedArray (android.content.res.TypedArray)3 IconDrawable (com.joanzapata.iconify.IconDrawable)3 TargetApi (android.annotation.TargetApi)2 Color (android.graphics.Color)2 PixelFormat (android.graphics.PixelFormat)2 Uri (android.net.Uri)2 Build (android.os.Build)2 Bundle (android.os.Bundle)2