From 4a3980c71ee422a4ead9e5d89ac158874f0d10cd Mon Sep 17 00:00:00 2001 From: olly Date: Wed, 8 Jun 2016 06:01:58 -0700 Subject: [PATCH] Add format change events to SimpleExoPlayer. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=124344637 --- .../android/exoplayer/demo/EventLogger.java | 20 +++++++++++++---- .../android/exoplayer/SimpleExoPlayer.java | 22 +++++++++++++++++-- 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/demo/src/main/java/com/google/android/exoplayer/demo/EventLogger.java b/demo/src/main/java/com/google/android/exoplayer/demo/EventLogger.java index 233ac6460b..c72f09851c 100644 --- a/demo/src/main/java/com/google/android/exoplayer/demo/EventLogger.java +++ b/demo/src/main/java/com/google/android/exoplayer/demo/EventLogger.java @@ -15,7 +15,6 @@ */ package com.google.android.exoplayer.demo; -import com.google.android.exoplayer.C; import com.google.android.exoplayer.DefaultTrackSelector; import com.google.android.exoplayer.DefaultTrackSelector.TrackInfo; import com.google.android.exoplayer.ExoPlaybackException; @@ -139,12 +138,24 @@ public class EventLogger implements ExoPlayer.EventListener, SimpleExoPlayer.Deb Log.d(TAG, "audioDecoderInitialized [" + getSessionTimeString() + ", " + decoderName + "]"); } + @Override + public void onAudioFormatChanged(Format format) { + Log.d(TAG, "audioFormatChanged [" + getSessionTimeString() + ", " + getFormatString(format) + + "]"); + } + @Override public void onVideoDecoderInitialized(String decoderName, long elapsedRealtimeMs, long initializationDurationMs) { Log.d(TAG, "videoDecoderInitialized [" + getSessionTimeString() + ", " + decoderName + "]"); } + @Override + public void onVideoFormatChanged(Format format) { + Log.d(TAG, "videoFormatChanged [" + getSessionTimeString() + ", " + getFormatString(format) + + "]"); + } + @Override public void onDroppedFrames(int count, long elapsed) { Log.d(TAG, "droppedFrames [" + getSessionTimeString() + ", " + count + "]"); @@ -200,9 +211,7 @@ public class EventLogger implements ExoPlayer.EventListener, SimpleExoPlayer.Deb @Override public void onDownstreamFormatChanged(int sourceId, Format format, int trigger, long mediaTimeMs) { - if (sourceId == C.TRACK_TYPE_VIDEO) { - Log.d(TAG, "videoFormatChanged [" + getSessionTimeString() + ", " + format.id + "]"); - } + // Do nothing. } // Internal methods @@ -266,6 +275,9 @@ public class EventLogger implements ExoPlayer.EventListener, SimpleExoPlayer.Deb } private static String getFormatString(Format format) { + if (format == null) { + return "null"; + } StringBuilder builder = new StringBuilder(); builder.append("id=").append(format.id).append(", mimeType=").append(format.sampleMimeType); if (format.bitrate != Format.NO_VALUE) { diff --git a/library/src/main/java/com/google/android/exoplayer/SimpleExoPlayer.java b/library/src/main/java/com/google/android/exoplayer/SimpleExoPlayer.java index 2bc336df7e..82e21090a1 100644 --- a/library/src/main/java/com/google/android/exoplayer/SimpleExoPlayer.java +++ b/library/src/main/java/com/google/android/exoplayer/SimpleExoPlayer.java @@ -63,8 +63,10 @@ public final class SimpleExoPlayer implements ExoPlayer { public interface DebugListener { void onAudioDecoderInitialized(String decoderName, long elapsedRealtimeMs, long initializationDurationMs); + void onAudioFormatChanged(Format format); void onVideoDecoderInitialized(String decoderName, long elapsedRealtimeMs, long initializationDurationMs); + void onVideoFormatChanged(Format format); void onDroppedFrames(int count, long elapsed); void onAudioTrackUnderrun(int bufferSize, long bufferSizeMs, long elapsedSinceLastFeedMs); } @@ -481,6 +483,9 @@ public final class SimpleExoPlayer implements ExoPlayer { @Override public void onVideoInputFormatChanged(Format format) { videoFormat = format; + if (debugListener != null) { + debugListener.onVideoFormatChanged(format); + } } @Override @@ -508,8 +513,13 @@ public final class SimpleExoPlayer implements ExoPlayer { @Override public void onVideoDisabled() { - videoFormat = null; videoCodecCounters = null; + if (videoFormat != null) { + videoFormat = null; + if (debugListener != null) { + debugListener.onVideoFormatChanged(null); + } + } } // AudioTrackRendererEventListener implementation @@ -531,6 +541,9 @@ public final class SimpleExoPlayer implements ExoPlayer { @Override public void onAudioInputFormatChanged(Format format) { audioFormat = format; + if (debugListener != null) { + debugListener.onAudioFormatChanged(format); + } } @Override @@ -543,8 +556,13 @@ public final class SimpleExoPlayer implements ExoPlayer { @Override public void onAudioDisabled() { - audioFormat = null; audioCodecCounters = null; + if (audioFormat != null) { + audioFormat = null; + if (debugListener != null) { + debugListener.onAudioFormatChanged(null); + } + } } // TextRenderer implementation