Search in sources :

Example 6 with Playable

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

the class PlayerWidgetService method onDestroy.

@Override
public void onDestroy() {
    super.onDestroy();
    Log.d(TAG, "Service is about to be destroyed");
    if (playbackService != null) {
        Playable playable = playbackService.getPlayable();
        if (playable != null && playable instanceof FeedMedia) {
            FeedMedia media = (FeedMedia) playable;
            if (media.hasAlmostEnded()) {
                Log.d(TAG, "smart mark as read");
                FeedItem item = media.getItem();
                DBWriter.markItemPlayed(item, FeedItem.PLAYED, false);
                DBWriter.removeQueueItem(this, item, false);
                DBWriter.addItemToPlaybackHistory(media);
                if (item.getFeed().getPreferences().getCurrentAutoDelete()) {
                    Log.d(TAG, "Delete " + media.toString());
                    DBWriter.deleteFeedMediaOfItem(this, media.getId());
                }
            }
        }
    }
    try {
        unbindService(mConnection);
    } catch (IllegalArgumentException e) {
        Log.w(TAG, "IllegalArgumentException when trying to unbind service");
    }
}
Also used : FeedItem(de.danoeh.antennapod.core.feed.FeedItem) Playable(de.danoeh.antennapod.core.util.playback.Playable) FeedMedia(de.danoeh.antennapod.core.feed.FeedMedia)

Example 7 with Playable

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

the class PlayerWidgetService method updateViews.

private void updateViews() {
    isUpdating = true;
    ComponentName playerWidget = new ComponentName(this, PlayerWidget.class);
    AppWidgetManager manager = AppWidgetManager.getInstance(this);
    RemoteViews views = new RemoteViews(getPackageName(), R.layout.player_widget);
    PendingIntent startMediaplayer = PendingIntent.getActivity(this, 0, PlaybackService.getPlayerActivityIntent(this), 0);
    Intent startApp = new Intent(getBaseContext(), MainActivity.class);
    startApp.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startApp.putExtra(MainActivity.EXTRA_FRAGMENT_TAG, QueueFragment.TAG);
    PendingIntent startAppPending = PendingIntent.getActivity(getBaseContext(), 0, startApp, PendingIntent.FLAG_UPDATE_CURRENT);
    boolean nothingPlaying = false;
    if (playbackService != null) {
        final Playable media = playbackService.getPlayable();
        if (media != null) {
            PlayerStatus status = playbackService.getStatus();
            views.setOnClickPendingIntent(R.id.layout_left, startMediaplayer);
            views.setTextViewText(R.id.txtvTitle, media.getEpisodeTitle());
            String progressString = getProgressString();
            if (progressString != null) {
                views.setViewVisibility(R.id.txtvProgress, View.VISIBLE);
                views.setTextViewText(R.id.txtvProgress, progressString);
            }
            if (status == PlayerStatus.PLAYING) {
                views.setImageViewResource(R.id.butPlay, R.drawable.ic_pause_white_24dp);
                if (Build.VERSION.SDK_INT >= 15) {
                    views.setContentDescription(R.id.butPlay, getString(R.string.pause_label));
                }
            } else {
                views.setImageViewResource(R.id.butPlay, R.drawable.ic_play_arrow_white_24dp);
                if (Build.VERSION.SDK_INT >= 15) {
                    views.setContentDescription(R.id.butPlay, getString(R.string.play_label));
                }
            }
            views.setOnClickPendingIntent(R.id.butPlay, createMediaButtonIntent());
        } else {
            nothingPlaying = true;
        }
    } else {
        nothingPlaying = true;
    }
    if (nothingPlaying) {
        // start the app if they click anything
        views.setOnClickPendingIntent(R.id.layout_left, startAppPending);
        views.setOnClickPendingIntent(R.id.butPlay, startAppPending);
        views.setViewVisibility(R.id.txtvProgress, View.INVISIBLE);
        views.setTextViewText(R.id.txtvTitle, this.getString(R.string.no_media_playing_label));
        views.setImageViewResource(R.id.butPlay, R.drawable.ic_play_arrow_white_24dp);
    }
    manager.updateAppWidget(playerWidget, views);
    isUpdating = false;
}
Also used : RemoteViews(android.widget.RemoteViews) Playable(de.danoeh.antennapod.core.util.playback.Playable) AppWidgetManager(android.appwidget.AppWidgetManager) PlayerStatus(de.danoeh.antennapod.core.service.playback.PlayerStatus) ComponentName(android.content.ComponentName) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent)

Example 8 with Playable

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

the class MediaplayerActivity method checkFavorite.

private void checkFavorite() {
    Playable playable = controller.getMedia();
    if (playable != null && playable instanceof FeedMedia) {
        FeedItem feedItem = ((FeedMedia) playable).getItem();
        if (feedItem != null) {
            Observable.fromCallable(() -> DBReader.getFeedItem(feedItem.getId())).subscribeOn(Schedulers.newThread()).observeOn(AndroidSchedulers.mainThread()).subscribe(item -> {
                boolean isFav = item.isTagged(FeedItem.TAG_FAVORITE);
                if (isFavorite != isFav) {
                    isFavorite = isFav;
                    invalidateOptionsMenu();
                }
            }, error -> Log.e(TAG, Log.getStackTraceString(error)));
        }
    }
}
Also used : FeedItem(de.danoeh.antennapod.core.feed.FeedItem) Playable(de.danoeh.antennapod.core.util.playback.Playable) FeedMedia(de.danoeh.antennapod.core.feed.FeedMedia)

Example 9 with Playable

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

the class MediaplayerActivity method loadMediaInfo.

/**
     * Load information about the media that is going to be played or currently
     * being played. This method will be called when the activity is connected
     * to the PlaybackService to ensure that the activity has the right
     * FeedMedia object.
     */
protected boolean loadMediaInfo() {
    Log.d(TAG, "loadMediaInfo()");
    if (controller == null || controller.getMedia() == null) {
        return false;
    }
    Playable media = controller.getMedia();
    SharedPreferences prefs = getSharedPreferences(PREFS, MODE_PRIVATE);
    showTimeLeft = prefs.getBoolean(PREF_SHOW_TIME_LEFT, false);
    onPositionObserverUpdate();
    checkFavorite();
    updatePlaybackSpeedButton();
    return true;
}
Also used : Playable(de.danoeh.antennapod.core.util.playback.Playable) SharedPreferences(android.content.SharedPreferences)

Example 10 with Playable

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

the class MediaplayerInfoActivity method onContextItemSelected.

@Override
public boolean onContextItemSelected(MenuItem item) {
    final int position = mPosition;
    // reset
    mPosition = -1;
    if (position < 0) {
        return false;
    }
    Feed feed = navDrawerData.feeds.get(position - navAdapter.getSubscriptionOffset());
    switch(item.getItemId()) {
        case R.id.mark_all_seen_item:
            DBWriter.markFeedSeen(feed.getId());
            return true;
        case R.id.mark_all_read_item:
            DBWriter.markFeedRead(feed.getId());
            return true;
        case R.id.rename_item:
            new RenameFeedDialog(this, feed).show();
            return true;
        case R.id.remove_item:
            final FeedRemover remover = new FeedRemover(this, feed) {

                @Override
                protected void onPostExecute(Void result) {
                    super.onPostExecute(result);
                }
            };
            ConfirmationDialog conDialog = new ConfirmationDialog(this, R.string.remove_feed_label, R.string.feed_delete_confirmation_msg) {

                @Override
                public void onConfirmButtonPressed(DialogInterface dialog) {
                    dialog.dismiss();
                    if (controller != null) {
                        Playable playable = controller.getMedia();
                        if (playable != null && playable instanceof FeedMedia) {
                            FeedMedia media = (FeedMedia) playable;
                            if (media.getItem().getFeed().getId() == feed.getId()) {
                                Log.d(TAG, "Currently playing episode is about to be deleted, skipping");
                                remover.skipOnCompletion = true;
                                if (controller.getStatus() == PlayerStatus.PLAYING) {
                                    sendBroadcast(new Intent(PlaybackService.ACTION_PAUSE_PLAY_CURRENT_EPISODE));
                                }
                            }
                        }
                    }
                    remover.executeAsync();
                }
            };
            conDialog.createNewDialog().show();
            return true;
        default:
            return super.onContextItemSelected(item);
    }
}
Also used : FeedRemover(de.danoeh.antennapod.core.asynctask.FeedRemover) DialogInterface(android.content.DialogInterface) Playable(de.danoeh.antennapod.core.util.playback.Playable) FeedMedia(de.danoeh.antennapod.core.feed.FeedMedia) RenameFeedDialog(de.danoeh.antennapod.dialog.RenameFeedDialog) Intent(android.content.Intent) Feed(de.danoeh.antennapod.core.feed.Feed) ConfirmationDialog(de.danoeh.antennapod.core.dialog.ConfirmationDialog)

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