Search in sources :

Example 1 with PlayQueue

use of org.schabi.newpipe.playlist.PlayQueue in project NewPipe by TeamNewPipe.

the class VideoDetailFragment method openNormalPlayer.

private void openNormalPlayer(VideoStream selectedVideoStream) {
    Intent mIntent;
    boolean useOldPlayer = PlayerHelper.isUsingOldPlayer(activity) || (Build.VERSION.SDK_INT < 16);
    if (!useOldPlayer) {
        // ExoPlayer
        final PlayQueue playQueue = new SinglePlayQueue(currentInfo);
        mIntent = NavigationHelper.getPlayerIntent(activity, MainVideoPlayer.class, playQueue, getSelectedVideoStream().getResolution());
    } else {
        // Internal Player
        mIntent = new Intent(activity, PlayVideoActivity.class).putExtra(PlayVideoActivity.VIDEO_TITLE, currentInfo.getName()).putExtra(PlayVideoActivity.STREAM_URL, selectedVideoStream.getUrl()).putExtra(PlayVideoActivity.VIDEO_URL, currentInfo.getUrl()).putExtra(PlayVideoActivity.START_POSITION, currentInfo.getStartPosition());
    }
    startActivity(mIntent);
}
Also used : MainVideoPlayer(org.schabi.newpipe.player.MainVideoPlayer) SinglePlayQueue(org.schabi.newpipe.playlist.SinglePlayQueue) PlayQueue(org.schabi.newpipe.playlist.PlayQueue) Intent(android.content.Intent) SinglePlayQueue(org.schabi.newpipe.playlist.SinglePlayQueue) PlayVideoActivity(org.schabi.newpipe.player.old.PlayVideoActivity)

Example 2 with PlayQueue

use of org.schabi.newpipe.playlist.PlayQueue in project NewPipe by TeamNewPipe.

the class BasePlayer method handleIntent.

public void handleIntent(Intent intent) {
    if (DEBUG)
        Log.d(TAG, "handleIntent() called with: intent = [" + intent + "]");
    if (intent == null)
        return;
    // Resolve play queue
    if (!intent.hasExtra(PLAY_QUEUE_KEY))
        return;
    final String intentCacheKey = intent.getStringExtra(PLAY_QUEUE_KEY);
    final PlayQueue queue = SerializedCache.getInstance().take(intentCacheKey, PlayQueue.class);
    if (queue == null)
        return;
    // Resolve append intents
    if (intent.getBooleanExtra(APPEND_ONLY, false) && playQueue != null) {
        int sizeBeforeAppend = playQueue.size();
        playQueue.append(queue.getStreams());
        if (intent.getBooleanExtra(SELECT_ON_APPEND, false) && queue.getStreams().size() > 0) {
            playQueue.setIndex(sizeBeforeAppend);
        }
        return;
    }
    final int repeatMode = intent.getIntExtra(REPEAT_MODE, getRepeatMode());
    final float playbackSpeed = intent.getFloatExtra(PLAYBACK_SPEED, getPlaybackSpeed());
    final float playbackPitch = intent.getFloatExtra(PLAYBACK_PITCH, getPlaybackPitch());
    // Good to go...
    initPlayback(queue, repeatMode, playbackSpeed, playbackPitch);
}
Also used : PlayQueue(org.schabi.newpipe.playlist.PlayQueue) PlayerHelper.getTimeString(org.schabi.newpipe.player.helper.PlayerHelper.getTimeString)

Example 3 with PlayQueue

use of org.schabi.newpipe.playlist.PlayQueue in project NewPipe by TeamNewPipe.

the class MainVideoPlayer method readFrom.

@Override
@SuppressWarnings("unchecked")
public void readFrom(@NonNull Queue<Object> savedObjects) throws Exception {
    @NonNull final PlayQueue queue = (PlayQueue) savedObjects.poll();
    final int repeatMode = (int) savedObjects.poll();
    final float playbackSpeed = (float) savedObjects.poll();
    final float playbackPitch = (float) savedObjects.poll();
    @NonNull final String playbackQuality = (String) savedObjects.poll();
    playerImpl.setPlaybackQuality(playbackQuality);
    playerImpl.initPlayback(queue, repeatMode, playbackSpeed, playbackPitch);
    StateSaver.onDestroy(savedState);
}
Also used : NonNull(android.support.annotation.NonNull) PlayQueue(org.schabi.newpipe.playlist.PlayQueue)

Example 4 with PlayQueue

use of org.schabi.newpipe.playlist.PlayQueue in project NewPipe by TeamNewPipe.

the class VideoDetailFragment method openPopupPlayer.

private void openPopupPlayer(final boolean append) {
    if (!PermissionHelper.isPopupEnabled(activity)) {
        PermissionHelper.showPopupEnablementToast(activity);
        return;
    }
    final PlayQueue itemQueue = new SinglePlayQueue(currentInfo);
    if (append) {
        NavigationHelper.enqueueOnPopupPlayer(activity, itemQueue);
    } else {
        Toast.makeText(activity, R.string.popup_playing_toast, Toast.LENGTH_SHORT).show();
        final Intent intent = NavigationHelper.getPlayerIntent(activity, PopupVideoPlayer.class, itemQueue, getSelectedVideoStream().resolution);
        activity.startService(intent);
    }
}
Also used : SinglePlayQueue(org.schabi.newpipe.playlist.SinglePlayQueue) PlayQueue(org.schabi.newpipe.playlist.PlayQueue) Intent(android.content.Intent) SinglePlayQueue(org.schabi.newpipe.playlist.SinglePlayQueue)

Example 5 with PlayQueue

use of org.schabi.newpipe.playlist.PlayQueue in project NewPipe by TeamNewPipe.

the class BasePlayer method onPlaybackSynchronize.

@Override
public void onPlaybackSynchronize(@NonNull final PlayQueueItem item, @Nullable final StreamInfo info) {
    if (DEBUG)
        Log.d(TAG, "Playback - onPlaybackSynchronize() called with " + (info != null ? "available" : "null") + " info, " + "item=[" + item.getTitle() + "], url=[" + item.getUrl() + "]");
    if (simpleExoPlayer == null || playQueue == null)
        return;
    final boolean onPlaybackInitial = currentItem == null;
    final boolean hasPlayQueueItemChanged = currentItem != item;
    final boolean hasStreamInfoChanged = currentInfo != info;
    final int currentPlayQueueIndex = playQueue.indexOf(item);
    final int currentPlaylistIndex = simpleExoPlayer.getCurrentWindowIndex();
    final int currentPlaylistSize = simpleExoPlayer.getCurrentTimeline().getWindowCount();
    // when starting playback on the last item when not repeating, maybe auto queue
    if (info != null && currentPlayQueueIndex == playQueue.size() - 1 && getRepeatMode() == Player.REPEAT_MODE_OFF && PlayerHelper.isAutoQueueEnabled(context)) {
        final PlayQueue autoQueue = PlayerHelper.autoQueueOf(info, playQueue.getStreams());
        if (autoQueue != null)
            playQueue.append(autoQueue.getStreams());
    }
    // If nothing to synchronize
    if (!hasPlayQueueItemChanged && !hasStreamInfoChanged) {
        return;
    }
    currentItem = item;
    currentInfo = info;
    if (hasPlayQueueItemChanged) {
        // updates only to the stream info should not trigger another view count
        registerView();
        initThumbnail(info == null ? item.getThumbnailUrl() : info.getThumbnailUrl());
    }
    onMetadataChanged(item, info, currentPlayQueueIndex, hasPlayQueueItemChanged);
    // Check if on wrong window
    if (currentPlayQueueIndex != playQueue.getIndex()) {
        Log.e(TAG, "Playback - Play Queue may be desynchronized: item " + "index=[" + currentPlayQueueIndex + "], " + "queue index=[" + playQueue.getIndex() + "]");
    // Check if bad seek position
    } else if ((currentPlaylistSize > 0 && currentPlayQueueIndex >= currentPlaylistSize) || currentPlayQueueIndex < 0) {
        Log.e(TAG, "Playback - Trying to seek to invalid " + "index=[" + currentPlayQueueIndex + "] with " + "playlist length=[" + currentPlaylistSize + "]");
    // If not playing correct stream, change window position and sets flag
    // for synchronizing once window position is corrected
    // @see maybeCorrectSeekPosition()
    } else if (currentPlaylistIndex != currentPlayQueueIndex || onPlaybackInitial || !isPlaying()) {
        if (DEBUG)
            Log.d(TAG, "Playback - Rewinding to correct" + " index=[" + currentPlayQueueIndex + "]," + " from=[" + currentPlaylistIndex + "], size=[" + currentPlaylistSize + "].");
        isSynchronizing = true;
        simpleExoPlayer.seekToDefaultPosition(currentPlayQueueIndex);
    }
}
Also used : PlayQueue(org.schabi.newpipe.playlist.PlayQueue)

Aggregations

PlayQueue (org.schabi.newpipe.playlist.PlayQueue)5 Intent (android.content.Intent)2 SinglePlayQueue (org.schabi.newpipe.playlist.SinglePlayQueue)2 NonNull (android.support.annotation.NonNull)1 MainVideoPlayer (org.schabi.newpipe.player.MainVideoPlayer)1 PlayerHelper.getTimeString (org.schabi.newpipe.player.helper.PlayerHelper.getTimeString)1 PlayVideoActivity (org.schabi.newpipe.player.old.PlayVideoActivity)1