From 32bd69d4b273869056f384fa81e0c685d38a80ce Mon Sep 17 00:00:00 2001 From: Oliver Woodman Date: Thu, 16 Aug 2018 17:02:08 +0100 Subject: [PATCH] Cleanup recent merged pull requests --- RELEASENOTES.md | 10 ++- .../source/ConcatenatingMediaSource.java | 26 +++--- .../source/hls/WebvttExtractor.java | 4 +- .../android/exoplayer2/ui/PlayerView.java | 89 +++++++++---------- 4 files changed, 66 insertions(+), 63 deletions(-) diff --git a/RELEASENOTES.md b/RELEASENOTES.md index c5f29d8bc3e..770d1ae3773 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -44,9 +44,10 @@ on ExoPlayer via its source code rather than an AAR may need to add `compileOptions { targetCompatibility JavaVersion.VERSION_1_8 }` to their gradle settings to ensure bytecode compatibility. -* Add support for lazy preparation of playlist media sources in - `ConcatenatingMediaSource` - ([#3972](https://github.com/google/ExoPlayer/issues/3972)). +* ConcatenatingMediaSource: + * Add support for lazy preparation of playlist media sources + ([#3972](https://github.com/google/ExoPlayer/issues/3972)). + * Add support for range removal with `removeMediaSourceRange` methods. * `BandwidthMeter` management: * Pass `BandwidthMeter` directly to `ExoPlayerFactory` instead of `TrackSelection.Factory` and `DataSource.Factory`. May also be omitted to @@ -108,6 +109,9 @@ * IMA: Improve handling of consecutive empty ad groups ([#4030](https://github.com/google/ExoPlayer/issues/4030)), ([#4280](https://github.com/google/ExoPlayer/issues/4280)). +* Add option to show buffering view when playWhenReady is false + ([#4304](https://github.com/google/ExoPlayer/issues/4304)). +* Allow any `Drawable` to be used as `PlayerView` default artwork. ### 2.8.3 ### diff --git a/library/core/src/main/java/com/google/android/exoplayer2/source/ConcatenatingMediaSource.java b/library/core/src/main/java/com/google/android/exoplayer2/source/ConcatenatingMediaSource.java index cbc04bb66d5..8987e9cb561 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/source/ConcatenatingMediaSource.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/source/ConcatenatingMediaSource.java @@ -265,8 +265,8 @@ public final synchronized void addMediaSources( *

Note: If you want to move the instance, it's preferable to use {@link #moveMediaSource(int, * int)} instead. * - *

Note: If you want to remove a set of contiguous sources, it's preferable to use - * {@link #removeMediaSourceRange(int, int)} instead. + *

Note: If you want to remove a set of contiguous sources, it's preferable to use {@link + * #removeMediaSourceRange(int, int)} instead. * * @param index The index at which the media source will be removed. This index must be in the * range of 0 <= index < {@link #getSize()}. @@ -281,8 +281,8 @@ public final synchronized void removeMediaSource(int index) { *

Note: If you want to move the instance, it's preferable to use {@link #moveMediaSource(int, * int, Runnable)} instead. * - *

Note: If you want to remove a set of contiguous sources, it's preferable to use - * {@link #removeMediaSourceRange(int, int, Runnable)} instead. + *

Note: If you want to remove a set of contiguous sources, it's preferable to use {@link + * #removeMediaSourceRange(int, int, Runnable)} instead. * * @param index The index at which the media source will be removed. This index must be in the * range of 0 <= index < {@link #getSize()}. @@ -307,15 +307,15 @@ public final synchronized void removeMediaSource( * Removes a range of {@link MediaSource}s from the playlist, by specifying an initial index * (included) and a final index (excluded). * - *

Note: when specified range is empty, no actual media source is removed and no exception - * is thrown. + *

Note: when specified range is empty, no actual media source is removed and no exception is + * thrown. * * @param fromIndex The initial range index, pointing to the first media source that will be * removed. This index must be in the range of 0 <= index <= {@link #getSize()}. * @param toIndex The final range index, pointing to the first media source that will be left * untouched. This index must be in the range of 0 <= index <= {@link #getSize()}. - * @throws IndexOutOfBoundsException When the range is malformed, i.e. {@code fromIndex} < - * 0, {@code toIndex} > {@link #getSize()}, {@code fromIndex} > {@code toIndex} + * @throws IndexOutOfBoundsException When the range is malformed, i.e. {@code fromIndex} < 0, + * {@code toIndex} > {@link #getSize()}, {@code fromIndex} > {@code toIndex} */ public final synchronized void removeMediaSourceRange(int fromIndex, int toIndex) { removeMediaSourceRange(fromIndex, toIndex, null); @@ -325,8 +325,8 @@ public final synchronized void removeMediaSourceRange(int fromIndex, int toIndex * Removes a range of {@link MediaSource}s from the playlist, by specifying an initial index * (included) and a final index (excluded), and executes a custom action on completion. * - *

Note: when specified range is empty, no actual media source is removed and no exception - * is thrown. + *

Note: when specified range is empty, no actual media source is removed and no exception is + * thrown. * * @param fromIndex The initial range index, pointing to the first media source that will be * removed. This index must be in the range of 0 <= index <= {@link #getSize()}. @@ -334,11 +334,11 @@ public final synchronized void removeMediaSourceRange(int fromIndex, int toIndex * untouched. This index must be in the range of 0 <= index <= {@link #getSize()}. * @param actionOnCompletion A {@link Runnable} which is executed immediately after the media * source range has been removed from the playlist. - * @throws IndexOutOfBoundsException When the range is malformed, i.e. {@code fromIndex} < - * 0, {@code toIndex} > {@link #getSize()}, {@code fromIndex} > {@code toIndex} + * @throws IndexOutOfBoundsException When the range is malformed, i.e. {@code fromIndex} < 0, + * {@code toIndex} > {@link #getSize()}, {@code fromIndex} > {@code toIndex} */ public final synchronized void removeMediaSourceRange( - int fromIndex, int toIndex, @Nullable Runnable actionOnCompletion) { + int fromIndex, int toIndex, @Nullable Runnable actionOnCompletion) { Util.removeRange(mediaSourcesPublic, fromIndex, toIndex); if (fromIndex == toIndex) { if (actionOnCompletion != null) { diff --git a/library/hls/src/main/java/com/google/android/exoplayer2/source/hls/WebvttExtractor.java b/library/hls/src/main/java/com/google/android/exoplayer2/source/hls/WebvttExtractor.java index 4587192cc71..da6e0f94adf 100644 --- a/library/hls/src/main/java/com/google/android/exoplayer2/source/hls/WebvttExtractor.java +++ b/library/hls/src/main/java/com/google/android/exoplayer2/source/hls/WebvttExtractor.java @@ -37,8 +37,8 @@ /** * A special purpose extractor for WebVTT content in HLS. - *

- * This extractor passes through non-empty WebVTT files untouched, however derives the correct + * + *

This extractor passes through non-empty WebVTT files untouched, however derives the correct * sample timestamp for each by sniffing the X-TIMESTAMP-MAP header along with the start timestamp * of the first cue header. Empty WebVTT files are not passed through, since it's not possible to * derive a sample timestamp in this case. diff --git a/library/ui/src/main/java/com/google/android/exoplayer2/ui/PlayerView.java b/library/ui/src/main/java/com/google/android/exoplayer2/ui/PlayerView.java index bfebf7eb7ce..99f38b4c408 100644 --- a/library/ui/src/main/java/com/google/android/exoplayer2/ui/PlayerView.java +++ b/library/ui/src/main/java/com/google/android/exoplayer2/ui/PlayerView.java @@ -25,9 +25,9 @@ import android.graphics.BitmapFactory; import android.graphics.Matrix; import android.graphics.RectF; -import android.support.annotation.IntDef; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; +import android.support.annotation.IntDef; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.content.ContextCompat; @@ -89,7 +89,7 @@ *

  • {@code default_artwork} - Default artwork to use if no artwork available in audio * streams. * *
  • {@code use_controller} - Whether the playback controls can be shown. @@ -116,10 +116,10 @@ *
  • Default: {@code true} * *
  • {@code show_buffering} - Whether the buffering spinner is displayed when the player - * is buffering. + * is buffering. Valid values are {@code never}, {@code when_playing} and {@code always}. * *
  • {@code resize_mode} - Controls how video and album art is resized within the view. * Valid values are {@code fit}, {@code fixed_width}, {@code fixed_height} and {@code fill}. @@ -243,13 +243,22 @@ public class PlayerView extends FrameLayout { private static final int SURFACE_TYPE_TEXTURE_VIEW = 2; private static final int SURFACE_TYPE_MONO360_VIEW = 3; - public static final int SHOW_BUFFERING_NEVER = 0; - public static final int SHOW_BUFFERING_ALWAYS = 1; - public static final int SHOW_BUFFERING_WHEN_PLAYING = 2; - + /** Determines when the buffering view is shown. */ @IntDef({SHOW_BUFFERING_NEVER, SHOW_BUFFERING_WHEN_PLAYING, SHOW_BUFFERING_ALWAYS}) @Retention(RetentionPolicy.SOURCE) public @interface ShowBuffering {} + /** The buffering view is never shown. */ + public static final int SHOW_BUFFERING_NEVER = 0; + /** + * The buffering view is shown when the player is in the {@link Player#STATE_BUFFERING buffering} + * state and {@link Player#getPlayWhenReady() playWhenReady} is {@code true}. + */ + public static final int SHOW_BUFFERING_WHEN_PLAYING = 1; + /** + * The buffering view is always shown when the player is in the {@link Player#STATE_BUFFERING + * buffering} state. + */ + public static final int SHOW_BUFFERING_ALWAYS = 2; private final AspectRatioFrameLayout contentFrame; private final View shutterView; @@ -265,7 +274,7 @@ public class PlayerView extends FrameLayout { private Player player; private boolean useController; private boolean useArtwork; - private Drawable defaultArtwork; + private @Nullable Drawable defaultArtwork; private @ShowBuffering int showBuffering; private boolean keepContentOnPlayerReset; private @Nullable ErrorMessageProvider errorMessageProvider; @@ -598,8 +607,9 @@ public Drawable getDefaultArtwork() { * @deprecated use (@link {@link #setDefaultArtwork(Drawable)} instead. */ @Deprecated - public void setDefaultArtwork(Bitmap defaultArtwork) { - setDefaultArtwork(new BitmapDrawable(getResources(), defaultArtwork)); + public void setDefaultArtwork(@Nullable Bitmap defaultArtwork) { + setDefaultArtwork( + defaultArtwork == null ? null : new BitmapDrawable(getResources(), defaultArtwork)); } /** @@ -608,7 +618,7 @@ public void setDefaultArtwork(Bitmap defaultArtwork) { * * @param defaultArtwork the default artwork to display */ - public void setDefaultArtwork(Drawable defaultArtwork) { + public void setDefaultArtwork(@Nullable Drawable defaultArtwork) { if (this.defaultArtwork != defaultArtwork) { this.defaultArtwork = defaultArtwork; updateForCurrentTrackSelections(/* isNewPlayer= */ false); @@ -682,7 +692,6 @@ public void setKeepContentOnPlayerReset(boolean keepContentOnPlayerReset) { * buffering spinner is not displayed by default. * * @deprecated Use {@link #setShowBuffering(int)} - * * @param showBuffering Whether the buffering icon is displayed */ @Deprecated @@ -692,15 +701,11 @@ public void setShowBuffering(boolean showBuffering) { /** * Sets whether a buffering spinner is displayed when the player is in the buffering state. The - * buffering spinner is not displayed by default (initial value {@link #SHOW_BUFFERING_NEVER}) - * - *

    + * buffering spinner is not displayed by default. * - * @param showBuffering Buffering strategy that defines when the buffering icon is displayed + * @param showBuffering The mode that defines when the buffering spinner is displayed. One of + * {@link #SHOW_BUFFERING_NEVER}, {@link #SHOW_BUFFERING_WHEN_PLAYING} and + * {@link #SHOW_BUFFERING_ALWAYS}. */ public void setShowBuffering(@ShowBuffering int showBuffering) { if (this.showBuffering != showBuffering) { @@ -1153,14 +1158,20 @@ private boolean setArtworkFromMetadata(Metadata metadata) { return false; } - private boolean setDrawableArtwork(Drawable drawable) { - if(drawable != null) { - artworkView.setImageDrawable(drawable); - if(contentFrame != null) { - contentFrame.setAspectRatio(0); + private boolean setDrawableArtwork(@Nullable Drawable drawable) { + if (drawable != null) { + int drawableWidth = drawable.getIntrinsicWidth(); + int drawableHeight = drawable.getIntrinsicHeight(); + if (drawableWidth > 0 && drawableHeight > 0) { + if (contentFrame != null) { + contentFrame.setAspectRatio((float) drawableWidth / drawableHeight); + } + artworkView.setImageDrawable(drawable); + artworkView.setVisibility(VISIBLE); + return true; } } - return true; + return false; } private void hideArtwork() { @@ -1178,23 +1189,11 @@ private void closeShutter() { private void updateBuffering() { if (bufferingView != null) { - - boolean showBufferingSpinner = false; - - if (player != null && player.getPlaybackState() == Player.STATE_BUFFERING) { - switch (showBuffering) { - case SHOW_BUFFERING_ALWAYS: - showBufferingSpinner = true; - break; - case SHOW_BUFFERING_NEVER: - showBufferingSpinner = false; - break; - case SHOW_BUFFERING_WHEN_PLAYING: - showBufferingSpinner = player.getPlayWhenReady(); - break; - } - } - + boolean showBufferingSpinner = + player != null + && player.getPlaybackState() == Player.STATE_BUFFERING + && (showBuffering == SHOW_BUFFERING_ALWAYS + || (showBuffering == SHOW_BUFFERING_WHEN_PLAYING && player.getPlayWhenReady())); bufferingView.setVisibility(showBufferingSpinner ? View.VISIBLE : View.GONE); } }