Search in sources :

Example 31 with Playable

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

the class VideoplayerActivity method loadMediaInfo.

protected void loadMediaInfo() {
    Log.d(TAG, "loadMediaInfo()");
    if (controller == null || controller.getMedia() == null) {
        return;
    }
    showTimeLeft = UserPreferences.shouldShowRemainingTime();
    onPositionObserverUpdate();
    checkFavorite();
    Playable media = controller.getMedia();
    if (media != null) {
        getSupportActionBar().setSubtitle(media.getEpisodeTitle());
        getSupportActionBar().setTitle(media.getFeedTitle());
    }
}
Also used : Playable(de.danoeh.antennapod.model.playback.Playable)

Example 32 with Playable

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

the class VideoplayerActivity method onOptionsItemSelected.

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == R.id.player_go_to_picture_in_picture) {
        compatEnterPictureInPicture();
        return true;
    }
    if (item.getItemId() == android.R.id.home) {
        Intent intent = new Intent(VideoplayerActivity.this, MainActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
        finish();
        return true;
    }
    if (controller == null) {
        return false;
    }
    Playable media = controller.getMedia();
    if (media == null) {
        return false;
    }
    // some options option requires FeedItem
    @Nullable final FeedItem feedItem = getFeedItem(media);
    if (item.getItemId() == R.id.add_to_favorites_item && feedItem != null) {
        DBWriter.addFavoriteItem(feedItem);
        isFavorite = true;
        invalidateOptionsMenu();
    } else if (item.getItemId() == R.id.remove_from_favorites_item && feedItem != null) {
        DBWriter.removeFavoriteItem(feedItem);
        isFavorite = false;
        invalidateOptionsMenu();
    } else if (item.getItemId() == R.id.disable_sleeptimer_item || item.getItemId() == R.id.set_sleeptimer_item) {
        new SleepTimerDialog().show(getSupportFragmentManager(), "SleepTimerDialog");
    } else if (item.getItemId() == R.id.audio_controls) {
        PlaybackControlsDialog dialog = PlaybackControlsDialog.newInstance();
        dialog.show(getSupportFragmentManager(), "playback_controls");
    } else if (item.getItemId() == R.id.open_feed_item && feedItem != null) {
        Intent intent = MainActivity.getIntentToOpenFeed(this, feedItem.getFeedId());
        startActivity(intent);
    } else if (item.getItemId() == R.id.visit_website_item) {
        IntentUtils.openInBrowser(VideoplayerActivity.this, getWebsiteLinkWithFallback(media));
    } else if (item.getItemId() == R.id.share_item && feedItem != null) {
        ShareDialog shareDialog = ShareDialog.newInstance(feedItem);
        shareDialog.show(getSupportFragmentManager(), "ShareEpisodeDialog");
    } else {
        return false;
    }
    return true;
}
Also used : ShareDialog(de.danoeh.antennapod.dialog.ShareDialog) FeedItem(de.danoeh.antennapod.model.feed.FeedItem) Playable(de.danoeh.antennapod.model.playback.Playable) PlaybackControlsDialog(de.danoeh.antennapod.dialog.PlaybackControlsDialog) SleepTimerDialog(de.danoeh.antennapod.dialog.SleepTimerDialog) Intent(android.content.Intent) Nullable(androidx.annotation.Nullable)

Example 33 with Playable

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

the class PlaybackVolumeUpdaterTest method noChangeIfNoFeedMediaPlaying.

@Test
public void noChangeIfNoFeedMediaPlaying() {
    PlaybackVolumeUpdater playbackVolumeUpdater = new PlaybackVolumeUpdater();
    when(mediaPlayer.getPlayerStatus()).thenReturn(PlayerStatus.PAUSED);
    Playable noFeedMedia = mock(Playable.class);
    when(mediaPlayer.getPlayable()).thenReturn(noFeedMedia);
    playbackVolumeUpdater.updateVolumeIfNecessary(mediaPlayer, FEED_ID, VolumeAdaptionSetting.OFF);
    verify(mediaPlayer, never()).pause(anyBoolean(), anyBoolean());
    verify(mediaPlayer, never()).resume();
}
Also used : Playable(de.danoeh.antennapod.model.playback.Playable) Test(org.junit.Test)

Example 34 with Playable

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

the class PlayableUtils method createFeedMediaInstance.

private static Playable createFeedMediaInstance(SharedPreferences pref) {
    Playable result = null;
    long mediaId = pref.getLong(FeedMedia.PREF_MEDIA_ID, -1);
    if (mediaId != -1) {
        result = DBReader.getFeedMedia(mediaId);
    }
    return result;
}
Also used : Playable(de.danoeh.antennapod.model.playback.Playable)

Example 35 with Playable

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

the class CastPsmp method onRemoteMediaPlayerStatusUpdated.

private void onRemoteMediaPlayerStatusUpdated() {
    MediaStatus status = remoteMediaClient.getMediaStatus();
    if (status == null) {
        Log.d(TAG, "Received null MediaStatus");
        return;
    } else {
        Log.d(TAG, "Received remote status/media update. New state=" + status.getPlayerState());
    }
    int state = status.getPlayerState();
    int oldState = remoteState;
    remoteMedia = status.getMediaInfo();
    boolean mediaChanged = !CastUtils.matches(remoteMedia, media);
    boolean stateChanged = state != oldState;
    if (!mediaChanged && !stateChanged) {
        Log.d(TAG, "Both media and state haven't changed, so nothing to do");
        return;
    }
    Playable currentMedia = mediaChanged ? localVersion(remoteMedia) : media;
    Playable oldMedia = media;
    int position = (int) status.getStreamPosition();
    // check for incompatible states
    if ((state == MediaStatus.PLAYER_STATE_PLAYING || state == MediaStatus.PLAYER_STATE_PAUSED) && currentMedia == null) {
        Log.w(TAG, "RemoteMediaPlayer returned playing or pausing state, but with no media");
        state = MediaStatus.PLAYER_STATE_UNKNOWN;
        stateChanged = oldState != MediaStatus.PLAYER_STATE_UNKNOWN;
    }
    if (stateChanged) {
        remoteState = state;
    }
    if (mediaChanged && stateChanged && oldState == MediaStatus.PLAYER_STATE_PLAYING && state != MediaStatus.PLAYER_STATE_IDLE) {
        callback.onPlaybackPause(null, INVALID_TIME);
        // We don't want setPlayerStatus to handle the onPlaybackPause callback
        setPlayerStatus(PlayerStatus.INDETERMINATE, currentMedia);
    }
    setBuffering(state == MediaStatus.PLAYER_STATE_BUFFERING);
    switch(state) {
        case MediaStatus.PLAYER_STATE_PLAYING:
            if (!stateChanged) {
                // These steps are necessary because they won't be performed by setPlayerStatus()
                if (position >= 0) {
                    currentMedia.setPosition(position);
                }
                currentMedia.onPlaybackStart();
            }
            setPlayerStatus(PlayerStatus.PLAYING, currentMedia, position);
            break;
        case MediaStatus.PLAYER_STATE_PAUSED:
            setPlayerStatus(PlayerStatus.PAUSED, currentMedia, position);
            break;
        case MediaStatus.PLAYER_STATE_BUFFERING:
            setPlayerStatus((mediaChanged || playerStatus == PlayerStatus.PREPARING) ? PlayerStatus.PREPARING : PlayerStatus.SEEKING, currentMedia, currentMedia != null ? currentMedia.getPosition() : INVALID_TIME);
            break;
        case MediaStatus.PLAYER_STATE_IDLE:
            int reason = status.getIdleReason();
            switch(reason) {
                case MediaStatus.IDLE_REASON_CANCELED:
                    // Essentially means stopped at the request of a user
                    callback.onPlaybackEnded(null, true);
                    setPlayerStatus(PlayerStatus.STOPPED, currentMedia);
                    if (oldMedia != null) {
                        if (position >= 0) {
                            oldMedia.setPosition(position);
                        }
                        callback.onPostPlayback(oldMedia, false, false, false);
                    }
                    // onPlaybackEnded pretty much takes care of updating the UI
                    return;
                case MediaStatus.IDLE_REASON_INTERRUPTED:
                    // Not sure if currentMedia already reflects the to be loaded one
                    if (mediaChanged && oldState == MediaStatus.PLAYER_STATE_PLAYING) {
                        callback.onPlaybackPause(null, INVALID_TIME);
                        setPlayerStatus(PlayerStatus.INDETERMINATE, currentMedia);
                    }
                    setPlayerStatus(PlayerStatus.PREPARING, currentMedia);
                    break;
                case MediaStatus.IDLE_REASON_NONE:
                    // This probably only happens when we connected but no command has been sent yet.
                    setPlayerStatus(PlayerStatus.INITIALIZED, currentMedia);
                    break;
                case MediaStatus.IDLE_REASON_FINISHED:
                    // This is our onCompletionListener...
                    if (mediaChanged && currentMedia != null) {
                        media = currentMedia;
                    }
                    endPlayback(true, false, true, true);
                    return;
                case MediaStatus.IDLE_REASON_ERROR:
                    Log.w(TAG, "Got an error status from the Chromecast. " + "Skipping, if possible, to the next episode...");
                    EventBus.getDefault().post(new PlayerErrorEvent("Chromecast error code 1"));
                    endPlayback(false, false, true, true);
                    return;
                default:
                    return;
            }
            break;
        case MediaStatus.PLAYER_STATE_UNKNOWN:
            if (playerStatus != PlayerStatus.INDETERMINATE || media != currentMedia) {
                setPlayerStatus(PlayerStatus.INDETERMINATE, currentMedia);
            }
            break;
        default:
            Log.w(TAG, "Remote media state undetermined!");
    }
    if (mediaChanged) {
        callback.onMediaChanged(true);
        if (oldMedia != null) {
            callback.onPostPlayback(oldMedia, false, false, currentMedia != null);
        }
    }
}
Also used : Playable(de.danoeh.antennapod.model.playback.Playable) PlayerErrorEvent(de.danoeh.antennapod.event.PlayerErrorEvent) MediaStatus(com.google.android.gms.cast.MediaStatus)

Aggregations

Playable (de.danoeh.antennapod.model.playback.Playable)35 Context (android.content.Context)14 CountDownLatch (java.util.concurrent.CountDownLatch)13 LocalPSMP (de.danoeh.antennapod.core.service.playback.LocalPSMP)11 PlaybackServiceMediaPlayer (de.danoeh.antennapod.playback.base.PlaybackServiceMediaPlayer)11 Test (org.junit.Test)11 UiThreadTest (androidx.test.annotation.UiThreadTest)10 AssertionFailedError (junit.framework.AssertionFailedError)9 MediumTest (androidx.test.filters.MediumTest)8 FeedMedia (de.danoeh.antennapod.model.feed.FeedMedia)8 LayoutInflater (android.view.LayoutInflater)3 Nullable (androidx.annotation.Nullable)3 PlayerErrorEvent (de.danoeh.antennapod.event.PlayerErrorEvent)3 FeedItem (de.danoeh.antennapod.model.feed.FeedItem)3 FeedPreferences (de.danoeh.antennapod.model.feed.FeedPreferences)3 Intent (android.content.Intent)2 Bundle (android.os.Bundle)2 Log (android.util.Log)2 View (android.view.View)2 ViewGroup (android.view.ViewGroup)2