-Fixed set index ignoring selection to current index when queue at current index changed.

-Modified popup player to disable rendering when screen is off.
This commit is contained in:
John Zhen Mo 2017-10-14 22:54:25 -07:00
parent d54a6e0b0e
commit eb9770e3ba
3 changed files with 45 additions and 14 deletions

View File

@ -53,7 +53,6 @@ import android.widget.Toast;
import com.google.android.exoplayer2.PlaybackParameters;
import com.google.android.exoplayer2.Player;
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector;
import org.schabi.newpipe.BuildConfig;
import org.schabi.newpipe.MainActivity;
@ -67,8 +66,6 @@ import org.schabi.newpipe.extractor.services.youtube.YoutubeStreamExtractor;
import org.schabi.newpipe.extractor.stream.StreamInfo;
import org.schabi.newpipe.player.event.PlayerEventListener;
import org.schabi.newpipe.player.old.PlayVideoActivity;
import org.schabi.newpipe.player.playback.MediaSourceManager;
import org.schabi.newpipe.playlist.PlayQueue;
import org.schabi.newpipe.playlist.PlayQueueItem;
import org.schabi.newpipe.playlist.SinglePlayQueue;
import org.schabi.newpipe.report.ErrorActivity;
@ -593,6 +590,9 @@ public final class PopupVideoPlayer extends Service {
intentFilter.addAction(ACTION_PLAY_PAUSE);
intentFilter.addAction(ACTION_OPEN_DETAIL);
intentFilter.addAction(ACTION_REPEAT);
intentFilter.addAction(Intent.ACTION_SCREEN_ON);
intentFilter.addAction(Intent.ACTION_SCREEN_OFF);
}
@Override
@ -612,6 +612,12 @@ public final class PopupVideoPlayer extends Service {
case ACTION_REPEAT:
onRepeatClicked();
break;
case Intent.ACTION_SCREEN_ON:
enableVideoRenderer(true);
break;
case Intent.ACTION_SCREEN_OFF:
enableVideoRenderer(false);
break;
}
}
@ -663,6 +669,20 @@ public final class PopupVideoPlayer extends Service {
showAndAnimateControl(R.drawable.ic_replay_white, false);
}
/*//////////////////////////////////////////////////////////////////////////
// Utils
//////////////////////////////////////////////////////////////////////////*/
public void enableVideoRenderer(final boolean enable) {
final int videoRendererIndex = getVideoRendererIndex();
if (trackSelector != null && videoRendererIndex != -1) {
trackSelector.setRendererDisabled(videoRendererIndex, !enable);
}
}
/*//////////////////////////////////////////////////////////////////////////
// Getters
//////////////////////////////////////////////////////////////////////////*/
@SuppressWarnings("WeakerAccess")
public TextView getResizingIndicator() {

View File

@ -63,6 +63,7 @@ import com.google.android.exoplayer2.ui.AspectRatioFrameLayout;
import org.schabi.newpipe.R;
import org.schabi.newpipe.extractor.MediaFormat;
import org.schabi.newpipe.extractor.stream.AudioStream;
import org.schabi.newpipe.extractor.stream.StreamInfo;
import org.schabi.newpipe.extractor.stream.VideoStream;
import org.schabi.newpipe.playlist.PlayQueueItem;
@ -106,7 +107,6 @@ public abstract class VideoPlayer extends BasePlayer implements SimpleExoPlayer.
private static final TrackSelection.Factory FIXED_FACTORY = new FixedTrackSelection.Factory();
private List<TrackGroupInfo> trackGroupInfos;
private int videoRendererIndex = -1;
private TrackGroupArray videoTrackGroups;
private TrackGroup selectedVideoTrackGroup;
@ -414,11 +414,9 @@ public abstract class VideoPlayer extends BasePlayer implements SimpleExoPlayer.
if (trackSelector.getCurrentMappedTrackInfo() == null) return;
qualityTextView.setVisibility(View.GONE);
for (int t = 0; t < simpleExoPlayer.getRendererCount(); t++) {
if (simpleExoPlayer.getRendererType(t) == C.TRACK_TYPE_VIDEO) {
videoRendererIndex = t;
}
}
final int videoRendererIndex = getVideoRendererIndex();
if (videoRendererIndex == -1) return;
videoTrackGroups = trackSelector.getCurrentMappedTrackInfo().getTrackGroups(videoRendererIndex);
final TrackSelection trackSelection = trackSelections.get(videoRendererIndex);
if (trackSelection != null) {
@ -544,9 +542,12 @@ public abstract class VideoPlayer extends BasePlayer implements SimpleExoPlayer.
}
trackSelector.setParameters(parameters);
final int videoRendererIndex = getVideoRendererIndex();
if (videoRendererIndex != -1) {
// Override the selection with the selected quality in case of different frame rate
final MappingTrackSelector.SelectionOverride override = new MappingTrackSelector.SelectionOverride(FIXED_FACTORY, info.group, info.track);
trackSelector.setSelectionOverride(videoRendererIndex, videoTrackGroups, override);
}
return true;
} else if (playbackSpeedPopupMenuGroupId == menuItem.getGroupId()) {
@ -626,6 +627,18 @@ public abstract class VideoPlayer extends BasePlayer implements SimpleExoPlayer.
// Utils
//////////////////////////////////////////////////////////////////////////*/
public int getVideoRendererIndex() {
if (simpleExoPlayer == null) return -1;
for (int t = 0; t < simpleExoPlayer.getRendererCount(); t++) {
if (simpleExoPlayer.getRendererType(t) == C.TRACK_TYPE_VIDEO) {
return t;
}
}
return -1;
}
public String resolutionStringOf(final Format format) {
final String frameRate = format.frameRate > 0 ? String.valueOf((int) format.frameRate) : "";
return Math.min(format.width, format.height) + "p" + frameRate;

View File

@ -194,8 +194,6 @@ public abstract class PlayQueue implements Serializable {
* Will emit a {@link SelectEvent} if the index is not the current playing index.
* */
public synchronized void setIndex(final int index) {
if (index == getIndex()) return;
final int oldIndex = getIndex();
int newIndex = index;