mirror of
https://github.com/androidx/media.git
synced 2025-05-17 12:39:52 +08:00
Fixes for retries
- Fix issue in ExoPlayerImpl where the timeline was null'd but onTimelineChanged was not fired. - Add the ability to not reset the timeline. This is useful for retries where you know the timeline will be the same as it was previously. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=135797577
This commit is contained in:
parent
83107cc25d
commit
29f3eb5e5a
@ -97,6 +97,9 @@ import java.util.Locale;
|
||||
|
||||
@Override
|
||||
public void onTimelineChanged(Timeline timeline, Object manifest) {
|
||||
if (timeline == null) {
|
||||
return;
|
||||
}
|
||||
int periodCount = timeline.getPeriodCount();
|
||||
int windowCount = timeline.getWindowCount();
|
||||
Log.d(TAG, "sourceInfo [periodCount=" + periodCount + ", windowCount=" + windowCount);
|
||||
|
@ -101,6 +101,7 @@ public class PlayerActivity extends Activity implements OnClickListener, ExoPlay
|
||||
}
|
||||
|
||||
private Handler mainHandler;
|
||||
private Timeline.Window window;
|
||||
private EventLogger eventLogger;
|
||||
private SimpleExoPlayerView simpleExoPlayerView;
|
||||
private LinearLayout debugRootView;
|
||||
@ -115,7 +116,7 @@ public class PlayerActivity extends Activity implements OnClickListener, ExoPlay
|
||||
private boolean playerNeedsSource;
|
||||
|
||||
private boolean shouldAutoPlay;
|
||||
private boolean shouldRestorePosition;
|
||||
private boolean isTimelineStatic;
|
||||
private int playerWindow;
|
||||
private long playerPosition;
|
||||
|
||||
@ -127,6 +128,7 @@ public class PlayerActivity extends Activity implements OnClickListener, ExoPlay
|
||||
shouldAutoPlay = true;
|
||||
mediaDataSourceFactory = buildDataSourceFactory(true);
|
||||
mainHandler = new Handler();
|
||||
window = new Timeline.Window();
|
||||
if (CookieHandler.getDefault() != DEFAULT_COOKIE_MANAGER) {
|
||||
CookieHandler.setDefault(DEFAULT_COOKIE_MANAGER);
|
||||
}
|
||||
@ -147,7 +149,7 @@ public class PlayerActivity extends Activity implements OnClickListener, ExoPlay
|
||||
@Override
|
||||
public void onNewIntent(Intent intent) {
|
||||
releasePlayer();
|
||||
shouldRestorePosition = false;
|
||||
isTimelineStatic = false;
|
||||
setIntent(intent);
|
||||
}
|
||||
|
||||
@ -262,7 +264,7 @@ public class PlayerActivity extends Activity implements OnClickListener, ExoPlay
|
||||
player.setVideoDebugListener(eventLogger);
|
||||
player.setId3Output(eventLogger);
|
||||
simpleExoPlayerView.setPlayer(player);
|
||||
if (shouldRestorePosition) {
|
||||
if (isTimelineStatic) {
|
||||
if (playerPosition == C.TIME_UNSET) {
|
||||
player.seekToDefaultPosition(playerWindow);
|
||||
} else {
|
||||
@ -305,7 +307,7 @@ public class PlayerActivity extends Activity implements OnClickListener, ExoPlay
|
||||
}
|
||||
MediaSource mediaSource = mediaSources.length == 1 ? mediaSources[0]
|
||||
: new ConcatenatingMediaSource(mediaSources);
|
||||
player.prepare(mediaSource, !shouldRestorePosition);
|
||||
player.prepare(mediaSource, !isTimelineStatic, !isTimelineStatic);
|
||||
playerNeedsSource = false;
|
||||
updateButtonVisibilities();
|
||||
}
|
||||
@ -348,15 +350,11 @@ public class PlayerActivity extends Activity implements OnClickListener, ExoPlay
|
||||
debugViewHelper.stop();
|
||||
debugViewHelper = null;
|
||||
shouldAutoPlay = player.getPlayWhenReady();
|
||||
shouldRestorePosition = false;
|
||||
Timeline timeline = player.getCurrentTimeline();
|
||||
if (timeline != null) {
|
||||
playerWindow = player.getCurrentWindowIndex();
|
||||
Timeline.Window window = timeline.getWindow(playerWindow, new Timeline.Window());
|
||||
if (!window.isDynamic) {
|
||||
shouldRestorePosition = true;
|
||||
playerPosition = window.isSeekable ? player.getCurrentPosition() : C.TIME_UNSET;
|
||||
}
|
||||
playerPosition = C.TIME_UNSET;
|
||||
Timeline timeline = player.getCurrentTimeline();
|
||||
if (timeline != null && timeline.getWindow(playerWindow, window).isSeekable) {
|
||||
playerPosition = player.getCurrentPosition();
|
||||
}
|
||||
player.release();
|
||||
player = null;
|
||||
@ -412,7 +410,8 @@ public class PlayerActivity extends Activity implements OnClickListener, ExoPlay
|
||||
|
||||
@Override
|
||||
public void onTimelineChanged(Timeline timeline, Object manifest) {
|
||||
// Do nothing.
|
||||
isTimelineStatic = timeline != null && timeline.getWindowCount() > 0
|
||||
&& !timeline.getWindow(timeline.getWindowCount() - 1, window).isDynamic;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -501,7 +500,7 @@ public class PlayerActivity extends Activity implements OnClickListener, ExoPlay
|
||||
button.setText(label);
|
||||
button.setTag(i);
|
||||
button.setOnClickListener(this);
|
||||
debugRootView.addView(button);
|
||||
debugRootView.addView(button, debugRootView.getChildCount() - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -130,8 +130,8 @@ public interface ExoPlayer {
|
||||
/**
|
||||
* Called when timeline and/or manifest has been refreshed.
|
||||
*
|
||||
* @param timeline The latest timeline.
|
||||
* @param manifest The latest manifest.
|
||||
* @param timeline The latest timeline, or null if the timeline is being cleared.
|
||||
* @param manifest The latest manifest, or null if the manifest is being cleared.
|
||||
*/
|
||||
void onTimelineChanged(Timeline timeline, Object manifest);
|
||||
|
||||
@ -247,7 +247,7 @@ public interface ExoPlayer {
|
||||
|
||||
/**
|
||||
* Prepares the player to play the provided {@link MediaSource}. Equivalent to
|
||||
* {@code prepare(mediaSource, true)}.
|
||||
* {@code prepare(mediaSource, true, true)}.
|
||||
*/
|
||||
void prepare(MediaSource mediaSource);
|
||||
|
||||
@ -259,8 +259,11 @@ public interface ExoPlayer {
|
||||
* @param resetPosition Whether the playback position should be reset to the default position in
|
||||
* the first {@link Timeline.Window}. If false, playback will start from the position defined
|
||||
* by {@link #getCurrentWindowIndex()} and {@link #getCurrentPosition()}.
|
||||
* @param resetTimeline Whether the timeline and manifest should be reset. Should be true unless
|
||||
* the player is being prepared to play the same media as it was playing previously (e.g. if
|
||||
* playback failed and is being retried).
|
||||
*/
|
||||
void prepare(MediaSource mediaSource, boolean resetPosition);
|
||||
void prepare(MediaSource mediaSource, boolean resetPosition, boolean resetTimeline);
|
||||
|
||||
/**
|
||||
* Sets whether playback should proceed when {@link #getPlaybackState()} == {@link #STATE_READY}.
|
||||
|
@ -101,12 +101,18 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
||||
|
||||
@Override
|
||||
public void prepare(MediaSource mediaSource) {
|
||||
prepare(mediaSource, true);
|
||||
prepare(mediaSource, true, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepare(MediaSource mediaSource, boolean resetPosition) {
|
||||
public void prepare(MediaSource mediaSource, boolean resetPosition, boolean resetTimeline) {
|
||||
if (resetTimeline && (timeline != null || manifest != null)) {
|
||||
timeline = null;
|
||||
manifest = null;
|
||||
for (EventListener listener : listeners) {
|
||||
listener.onTimelineChanged(null, null);
|
||||
}
|
||||
}
|
||||
internalPlayer.prepare(mediaSource, resetPosition);
|
||||
}
|
||||
|
||||
|
@ -420,8 +420,8 @@ public final class SimpleExoPlayer implements ExoPlayer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepare(MediaSource mediaSource, boolean resetPosition) {
|
||||
player.prepare(mediaSource, resetPosition);
|
||||
public void prepare(MediaSource mediaSource, boolean resetPosition, boolean resetTimeline) {
|
||||
player.prepare(mediaSource, resetPosition, resetTimeline);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
x
Reference in New Issue
Block a user