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
|
@Override
|
||||||
public void onTimelineChanged(Timeline timeline, Object manifest) {
|
public void onTimelineChanged(Timeline timeline, Object manifest) {
|
||||||
|
if (timeline == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
int periodCount = timeline.getPeriodCount();
|
int periodCount = timeline.getPeriodCount();
|
||||||
int windowCount = timeline.getWindowCount();
|
int windowCount = timeline.getWindowCount();
|
||||||
Log.d(TAG, "sourceInfo [periodCount=" + periodCount + ", windowCount=" + windowCount);
|
Log.d(TAG, "sourceInfo [periodCount=" + periodCount + ", windowCount=" + windowCount);
|
||||||
|
@ -101,6 +101,7 @@ public class PlayerActivity extends Activity implements OnClickListener, ExoPlay
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Handler mainHandler;
|
private Handler mainHandler;
|
||||||
|
private Timeline.Window window;
|
||||||
private EventLogger eventLogger;
|
private EventLogger eventLogger;
|
||||||
private SimpleExoPlayerView simpleExoPlayerView;
|
private SimpleExoPlayerView simpleExoPlayerView;
|
||||||
private LinearLayout debugRootView;
|
private LinearLayout debugRootView;
|
||||||
@ -115,7 +116,7 @@ public class PlayerActivity extends Activity implements OnClickListener, ExoPlay
|
|||||||
private boolean playerNeedsSource;
|
private boolean playerNeedsSource;
|
||||||
|
|
||||||
private boolean shouldAutoPlay;
|
private boolean shouldAutoPlay;
|
||||||
private boolean shouldRestorePosition;
|
private boolean isTimelineStatic;
|
||||||
private int playerWindow;
|
private int playerWindow;
|
||||||
private long playerPosition;
|
private long playerPosition;
|
||||||
|
|
||||||
@ -127,6 +128,7 @@ public class PlayerActivity extends Activity implements OnClickListener, ExoPlay
|
|||||||
shouldAutoPlay = true;
|
shouldAutoPlay = true;
|
||||||
mediaDataSourceFactory = buildDataSourceFactory(true);
|
mediaDataSourceFactory = buildDataSourceFactory(true);
|
||||||
mainHandler = new Handler();
|
mainHandler = new Handler();
|
||||||
|
window = new Timeline.Window();
|
||||||
if (CookieHandler.getDefault() != DEFAULT_COOKIE_MANAGER) {
|
if (CookieHandler.getDefault() != DEFAULT_COOKIE_MANAGER) {
|
||||||
CookieHandler.setDefault(DEFAULT_COOKIE_MANAGER);
|
CookieHandler.setDefault(DEFAULT_COOKIE_MANAGER);
|
||||||
}
|
}
|
||||||
@ -147,7 +149,7 @@ public class PlayerActivity extends Activity implements OnClickListener, ExoPlay
|
|||||||
@Override
|
@Override
|
||||||
public void onNewIntent(Intent intent) {
|
public void onNewIntent(Intent intent) {
|
||||||
releasePlayer();
|
releasePlayer();
|
||||||
shouldRestorePosition = false;
|
isTimelineStatic = false;
|
||||||
setIntent(intent);
|
setIntent(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -262,7 +264,7 @@ public class PlayerActivity extends Activity implements OnClickListener, ExoPlay
|
|||||||
player.setVideoDebugListener(eventLogger);
|
player.setVideoDebugListener(eventLogger);
|
||||||
player.setId3Output(eventLogger);
|
player.setId3Output(eventLogger);
|
||||||
simpleExoPlayerView.setPlayer(player);
|
simpleExoPlayerView.setPlayer(player);
|
||||||
if (shouldRestorePosition) {
|
if (isTimelineStatic) {
|
||||||
if (playerPosition == C.TIME_UNSET) {
|
if (playerPosition == C.TIME_UNSET) {
|
||||||
player.seekToDefaultPosition(playerWindow);
|
player.seekToDefaultPosition(playerWindow);
|
||||||
} else {
|
} else {
|
||||||
@ -305,7 +307,7 @@ public class PlayerActivity extends Activity implements OnClickListener, ExoPlay
|
|||||||
}
|
}
|
||||||
MediaSource mediaSource = mediaSources.length == 1 ? mediaSources[0]
|
MediaSource mediaSource = mediaSources.length == 1 ? mediaSources[0]
|
||||||
: new ConcatenatingMediaSource(mediaSources);
|
: new ConcatenatingMediaSource(mediaSources);
|
||||||
player.prepare(mediaSource, !shouldRestorePosition);
|
player.prepare(mediaSource, !isTimelineStatic, !isTimelineStatic);
|
||||||
playerNeedsSource = false;
|
playerNeedsSource = false;
|
||||||
updateButtonVisibilities();
|
updateButtonVisibilities();
|
||||||
}
|
}
|
||||||
@ -348,15 +350,11 @@ public class PlayerActivity extends Activity implements OnClickListener, ExoPlay
|
|||||||
debugViewHelper.stop();
|
debugViewHelper.stop();
|
||||||
debugViewHelper = null;
|
debugViewHelper = null;
|
||||||
shouldAutoPlay = player.getPlayWhenReady();
|
shouldAutoPlay = player.getPlayWhenReady();
|
||||||
shouldRestorePosition = false;
|
|
||||||
Timeline timeline = player.getCurrentTimeline();
|
|
||||||
if (timeline != null) {
|
|
||||||
playerWindow = player.getCurrentWindowIndex();
|
playerWindow = player.getCurrentWindowIndex();
|
||||||
Timeline.Window window = timeline.getWindow(playerWindow, new Timeline.Window());
|
playerPosition = C.TIME_UNSET;
|
||||||
if (!window.isDynamic) {
|
Timeline timeline = player.getCurrentTimeline();
|
||||||
shouldRestorePosition = true;
|
if (timeline != null && timeline.getWindow(playerWindow, window).isSeekable) {
|
||||||
playerPosition = window.isSeekable ? player.getCurrentPosition() : C.TIME_UNSET;
|
playerPosition = player.getCurrentPosition();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
player.release();
|
player.release();
|
||||||
player = null;
|
player = null;
|
||||||
@ -412,7 +410,8 @@ public class PlayerActivity extends Activity implements OnClickListener, ExoPlay
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTimelineChanged(Timeline timeline, Object manifest) {
|
public void onTimelineChanged(Timeline timeline, Object manifest) {
|
||||||
// Do nothing.
|
isTimelineStatic = timeline != null && timeline.getWindowCount() > 0
|
||||||
|
&& !timeline.getWindow(timeline.getWindowCount() - 1, window).isDynamic;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -501,7 +500,7 @@ public class PlayerActivity extends Activity implements OnClickListener, ExoPlay
|
|||||||
button.setText(label);
|
button.setText(label);
|
||||||
button.setTag(i);
|
button.setTag(i);
|
||||||
button.setOnClickListener(this);
|
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.
|
* Called when timeline and/or manifest has been refreshed.
|
||||||
*
|
*
|
||||||
* @param timeline The latest timeline.
|
* @param timeline The latest timeline, or null if the timeline is being cleared.
|
||||||
* @param manifest The latest manifest.
|
* @param manifest The latest manifest, or null if the manifest is being cleared.
|
||||||
*/
|
*/
|
||||||
void onTimelineChanged(Timeline timeline, Object manifest);
|
void onTimelineChanged(Timeline timeline, Object manifest);
|
||||||
|
|
||||||
@ -247,7 +247,7 @@ public interface ExoPlayer {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Prepares the player to play the provided {@link MediaSource}. Equivalent to
|
* Prepares the player to play the provided {@link MediaSource}. Equivalent to
|
||||||
* {@code prepare(mediaSource, true)}.
|
* {@code prepare(mediaSource, true, true)}.
|
||||||
*/
|
*/
|
||||||
void prepare(MediaSource mediaSource);
|
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
|
* @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
|
* the first {@link Timeline.Window}. If false, playback will start from the position defined
|
||||||
* by {@link #getCurrentWindowIndex()} and {@link #getCurrentPosition()}.
|
* 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}.
|
* Sets whether playback should proceed when {@link #getPlaybackState()} == {@link #STATE_READY}.
|
||||||
|
@ -101,12 +101,18 @@ import java.util.concurrent.CopyOnWriteArraySet;
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void prepare(MediaSource mediaSource) {
|
public void prepare(MediaSource mediaSource) {
|
||||||
prepare(mediaSource, true);
|
prepare(mediaSource, true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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;
|
timeline = null;
|
||||||
|
manifest = null;
|
||||||
|
for (EventListener listener : listeners) {
|
||||||
|
listener.onTimelineChanged(null, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
internalPlayer.prepare(mediaSource, resetPosition);
|
internalPlayer.prepare(mediaSource, resetPosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -420,8 +420,8 @@ public final class SimpleExoPlayer implements ExoPlayer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void prepare(MediaSource mediaSource, boolean resetPosition) {
|
public void prepare(MediaSource mediaSource, boolean resetPosition, boolean resetTimeline) {
|
||||||
player.prepare(mediaSource, resetPosition);
|
player.prepare(mediaSource, resetPosition, resetTimeline);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
x
Reference in New Issue
Block a user