Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
SDK
/
exoplayer
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
1f12f22b
authored
Jul 27, 2018
by
Arnold Szabo
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
#4304 - Add option to show buffering view when setPlayWhenReady is false
parent
8952ccac
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
55 additions
and
9 deletions
library/ui/src/main/java/com/google/android/exoplayer2/ui/PlayerView.java
library/ui/src/main/res/values/attrs.xml
library/ui/src/main/java/com/google/android/exoplayer2/ui/PlayerView.java
View file @
1f12f22b
...
...
@@ -25,6 +25,7 @@ import android.graphics.Bitmap;
import
android.graphics.BitmapFactory
;
import
android.graphics.Matrix
;
import
android.graphics.RectF
;
import
android.support.annotation.IntDef
;
import
android.support.annotation.NonNull
;
import
android.support.annotation.Nullable
;
import
android.util.AttributeSet
;
...
...
@@ -61,6 +62,8 @@ import com.google.android.exoplayer2.util.ErrorMessageProvider;
import
com.google.android.exoplayer2.util.RepeatModeUtil
;
import
com.google.android.exoplayer2.util.Util
;
import
com.google.android.exoplayer2.video.VideoListener
;
import
java.lang.annotation.Retention
;
import
java.lang.annotation.RetentionPolicy
;
import
java.util.List
;
/**
...
...
@@ -237,6 +240,14 @@ 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
;
@IntDef
({
SHOW_BUFFERING_NEVER
,
SHOW_BUFFERING_WHEN_PLAYING
,
SHOW_BUFFERING_ALWAYS
})
@Retention
(
RetentionPolicy
.
SOURCE
)
public
@interface
ShowBuffering
{}
private
final
AspectRatioFrameLayout
contentFrame
;
private
final
View
shutterView
;
private
final
View
surfaceView
;
...
...
@@ -252,7 +263,7 @@ public class PlayerView extends FrameLayout {
private
boolean
useController
;
private
boolean
useArtwork
;
private
Bitmap
defaultArtwork
;
private
boolean
showBuffering
;
private
@ShowBuffering
int
showBuffering
;
private
boolean
keepContentOnPlayerReset
;
private
@Nullable
ErrorMessageProvider
<?
super
ExoPlaybackException
>
errorMessageProvider
;
private
@Nullable
CharSequence
customErrorMessage
;
...
...
@@ -306,7 +317,7 @@ public class PlayerView extends FrameLayout {
boolean
controllerHideOnTouch
=
true
;
boolean
controllerAutoShow
=
true
;
boolean
controllerHideDuringAds
=
true
;
boolean
showBuffering
=
false
;
int
showBuffering
=
SHOW_BUFFERING_NEVER
;
if
(
attrs
!=
null
)
{
TypedArray
a
=
context
.
getTheme
().
obtainStyledAttributes
(
attrs
,
R
.
styleable
.
PlayerView
,
0
,
0
);
try
{
...
...
@@ -324,7 +335,7 @@ public class PlayerView extends FrameLayout {
controllerHideOnTouch
=
a
.
getBoolean
(
R
.
styleable
.
PlayerView_hide_on_touch
,
controllerHideOnTouch
);
controllerAutoShow
=
a
.
getBoolean
(
R
.
styleable
.
PlayerView_auto_show
,
controllerAutoShow
);
showBuffering
=
a
.
get
Boolean
(
R
.
styleable
.
PlayerView_show_buffering
,
showBuffering
);
showBuffering
=
a
.
get
Integer
(
R
.
styleable
.
PlayerView_show_buffering
,
showBuffering
);
keepContentOnPlayerReset
=
a
.
getBoolean
(
R
.
styleable
.
PlayerView_keep_content_on_player_reset
,
keepContentOnPlayerReset
);
...
...
@@ -655,9 +666,28 @@ public class PlayerView extends FrameLayout {
* Sets whether a buffering spinner is displayed when the player is in the buffering state. The
* buffering spinner is not displayed by default.
*
* Deprecated, use {@link #setShowBuffering(int)}
*
* @param showBuffering Whether the buffering icon is displayed
*/
@Deprecated
public
void
setShowBuffering
(
boolean
showBuffering
)
{
setShowBuffering
(
showBuffering
?
SHOW_BUFFERING_ALWAYS
:
SHOW_BUFFERING_NEVER
);
}
/**
* 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})
*
* <p><ul>
* <li>{@link #SHOW_BUFFERING_ALWAYS} displayed always when buffering
* <li>{@link #SHOW_BUFFERING_NEVER} not displayed at all
* <li>{@link #SHOW_BUFFERING_WHEN_PLAYING} displayed only when playing and buffering
* </p></ul>
*
* @param showBuffering Buffering strategy that defines when the buffering icon is displayed
*/
public
void
setShowBuffering
(
@ShowBuffering
int
showBuffering
)
{
if
(
this
.
showBuffering
!=
showBuffering
)
{
this
.
showBuffering
=
showBuffering
;
updateBuffering
();
...
...
@@ -1139,11 +1169,23 @@ public class PlayerView extends FrameLayout {
private
void
updateBuffering
()
{
if
(
bufferingView
!=
null
)
{
boolean
showBufferingSpinner
=
showBuffering
&&
player
!=
null
&&
player
.
getPlaybackState
()
==
Player
.
STATE_BUFFERING
&&
player
.
getPlayWhenReady
();
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
;
}
}
bufferingView
.
setVisibility
(
showBufferingSpinner
?
View
.
VISIBLE
:
View
.
GONE
);
}
}
...
...
library/ui/src/main/res/values/attrs.xml
View file @
1f12f22b
...
...
@@ -51,7 +51,11 @@
<attr
name=
"hide_on_touch"
format=
"boolean"
/>
<attr
name=
"hide_during_ads"
format=
"boolean"
/>
<attr
name=
"auto_show"
format=
"boolean"
/>
<attr
name=
"show_buffering"
format=
"boolean"
/>
<attr
name=
"show_buffering"
format=
"enum"
>
<enum
name=
"show_buffering_never"
value=
"0"
/>
<enum
name=
"show_buffering_always"
value=
"1"
/>
<enum
name=
"show_buffering_when_playing"
value=
"2"
/>
</attr>
<attr
name=
"keep_content_on_player_reset"
format=
"boolean"
/>
<attr
name=
"resize_mode"
/>
<attr
name=
"surface_type"
/>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment