mirror of
https://github.com/androidx/media.git
synced 2025-05-07 23:50:44 +08:00
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:
parent
79cdd03682
commit
b3594051a1
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user