Fix DemoPlayer's spurious transition through STATE_IDLE.

The spurious transitions were caused by calling pushTrackSelection
in onRenderers after changing the renderer building state to BUILT
and before calling player.prepare. pushTrackSelection can cause the
ExoPlayer to generate state changes, since it can call setPlayWhenReady.
This change transitions the renderer building state later, so that
when this happens getPlaybackState correctly masks the state and
returns STATE_PREPARING.
This commit is contained in:
Oliver Woodman 2015-05-01 20:35:54 +01:00
parent 79cdd03682
commit b3594051a1

View File

@ -295,9 +295,11 @@ public class DemoPlayer implements ExoPlayer.Listener, ChunkSampleSource.EventLi
if (builderCallback != null) {
builderCallback.cancel();
}
videoFormat = null;
videoRenderer = null;
multiTrackSources = null;
rendererBuildingState = RENDERER_BUILDING_STATE_BUILDING;
maybeReportPlayerState();
videoFormat = null;
builderCallback = new InternalRendererBuilderCallback();
rendererBuilder.buildRenderers(this, builderCallback);
}
@ -324,15 +326,15 @@ public class DemoPlayer implements ExoPlayer.Listener, ChunkSampleSource.EventLi
}
}
// Complete preparation.
this.videoRenderer = renderers[TYPE_VIDEO];
this.trackNames = trackNames;
this.videoRenderer = renderers[TYPE_VIDEO];
this.multiTrackSources = multiTrackSources;
rendererBuildingState = RENDERER_BUILDING_STATE_BUILT;
pushSurface(false);
pushTrackSelection(TYPE_VIDEO, true);
pushTrackSelection(TYPE_AUDIO, true);
pushTrackSelection(TYPE_TEXT, true);
player.prepare(renderers);
rendererBuildingState = RENDERER_BUILDING_STATE_BUILT;
}
/* package */ void onRenderersError(Exception e) {
@ -571,7 +573,7 @@ public class DemoPlayer implements ExoPlayer.Listener, ChunkSampleSource.EventLi
}
private void pushSurface(boolean blockForSurfacePush) {
if (rendererBuildingState != RENDERER_BUILDING_STATE_BUILT) {
if (videoRenderer == null) {
return;
}
@ -585,7 +587,7 @@ public class DemoPlayer implements ExoPlayer.Listener, ChunkSampleSource.EventLi
}
private void pushTrackSelection(int type, boolean allowRendererEnable) {
if (rendererBuildingState != RENDERER_BUILDING_STATE_BUILT) {
if (multiTrackSources == null) {
return;
}