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
6a8b9557
authored
May 24, 2021
by
aquilescanta
Committed by
Oliver Woodman
May 26, 2021
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Use ERROR_CODE_BEHIND_LIVE_WINDOW instead of instanceof checks
PiperOrigin-RevId: 375514509
parent
afe4217c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
33 deletions
demos/main/src/main/java/com/google/android/exoplayer2/demo/PlayerActivity.java
docs/live-streaming.md
demos/main/src/main/java/com/google/android/exoplayer2/demo/PlayerActivity.java
View file @
6a8b9557
...
...
@@ -34,6 +34,7 @@ import androidx.appcompat.app.AppCompatActivity;
import
com.google.android.exoplayer2.C
;
import
com.google.android.exoplayer2.ExoPlaybackException
;
import
com.google.android.exoplayer2.MediaItem
;
import
com.google.android.exoplayer2.PlaybackException
;
import
com.google.android.exoplayer2.Player
;
import
com.google.android.exoplayer2.RenderersFactory
;
import
com.google.android.exoplayer2.SimpleExoPlayer
;
...
...
@@ -43,7 +44,6 @@ import com.google.android.exoplayer2.ext.ima.ImaAdsLoader;
import
com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.DecoderInitializationException
;
import
com.google.android.exoplayer2.mediacodec.MediaCodecUtil.DecoderQueryException
;
import
com.google.android.exoplayer2.offline.DownloadRequest
;
import
com.google.android.exoplayer2.source.BehindLiveWindowException
;
import
com.google.android.exoplayer2.source.DefaultMediaSourceFactory
;
import
com.google.android.exoplayer2.source.MediaSourceFactory
;
import
com.google.android.exoplayer2.source.TrackGroupArray
;
...
...
@@ -413,20 +413,6 @@ public class PlayerActivity extends AppCompatActivity
Toast
.
makeText
(
getApplicationContext
(),
message
,
Toast
.
LENGTH_LONG
).
show
();
}
private
static
boolean
isBehindLiveWindow
(
ExoPlaybackException
e
)
{
if
(
e
.
type
!=
ExoPlaybackException
.
TYPE_SOURCE
)
{
return
false
;
}
Throwable
cause
=
e
.
getSourceException
();
while
(
cause
!=
null
)
{
if
(
cause
instanceof
BehindLiveWindowException
)
{
return
true
;
}
cause
=
cause
.
getCause
();
}
return
false
;
}
private
class
PlayerEventListener
implements
Player
.
EventListener
{
@Override
...
...
@@ -439,7 +425,7 @@ public class PlayerActivity extends AppCompatActivity
@Override
public
void
onPlayerError
(
@NonNull
ExoPlaybackException
e
)
{
if
(
isBehindLiveWindow
(
e
)
)
{
if
(
e
.
errorCode
==
PlaybackException
.
ERROR_CODE_BEHIND_LIVE_WINDOW
)
{
player
.
seekToDefaultPosition
();
player
.
prepare
();
}
else
{
...
...
docs/live-streaming.md
View file @
6a8b9557
...
...
@@ -130,11 +130,12 @@ Available configuration values are:
If automatic playback speed adjustment is not desired, it can be disabled by
setting
`minPlaybackSpeed`
and
`maxPlaybackSpeed`
to
`1.0f`
.
## BehindLiveWindowException ##
## BehindLiveWindowException
and ERROR_CODE_BEHIND_LIVE_WINDOW
##
The playback position may fall behind the live window, for example if the player
is paused or buffering for a long enough period of time. If this happens then
playback will fail and a
`BehindLiveWindowException`
will be reported via
playback will fail and an exception with error code
`ERROR_CODE_BEHIND_LIVE_WINDOW`
will be reported via
`Player.Listener.onPlayerError`
. Application code may wish to handle such
errors by resuming playback at the default position. The
[
PlayerActivity
][]
of
the demo app exemplifies this approach.
...
...
@@ -142,7 +143,7 @@ the demo app exemplifies this approach.
~~~
@Override
public void onPlayerError(ExoPlaybackException e) {
if (
isBehindLiveWindow(e)
) {
if (
e.errorCode == PlaybackException.ERROR_CODE_BEHIND_LIVE_WINDOW
) {
// Re-initialize player at the current live window default position.
player.seekToDefaultPosition();
player.prepare();
...
...
@@ -150,20 +151,6 @@ public void onPlayerError(ExoPlaybackException e) {
// Handle other errors.
}
}
private static boolean isBehindLiveWindow(ExoPlaybackException e) {
if (e.type != ExoPlaybackException.TYPE_SOURCE) {
return false;
}
Throwable cause = e.getSourceException();
while (cause != null) {
if (cause instanceof BehindLiveWindowException) {
return true;
}
cause = cause.getCause();
}
return false;
}
~~~
{: .language-java}
...
...
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