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
7dffb2dc
authored
Aug 11, 2021
by
olly
Committed by
Oliver Woodman
Aug 11, 2021
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Migrate to Player.Listener
PiperOrigin-RevId: 390124675
parent
4aa58980
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
41 additions
and
43 deletions
library/common/src/main/java/com/google/android/exoplayer2/Player.java
library/core/src/androidTest/java/com/google/android/exoplayer2/ClippedPlaybackTest.java
library/ui/src/main/java/com/google/android/exoplayer2/ui/PlayerView.java
library/ui/src/main/java/com/google/android/exoplayer2/ui/StyledPlayerView.java
robolectricutils/src/main/java/com/google/android/exoplayer2/robolectric/PlaybackOutput.java
robolectricutils/src/main/java/com/google/android/exoplayer2/robolectric/TestPlayerRunHelper.java
library/common/src/main/java/com/google/android/exoplayer2/Player.java
View file @
7dffb2dc
...
...
@@ -140,7 +140,7 @@ public interface Player {
*
* <p>The provided {@link MediaMetadata} is a combination of the {@link MediaItem#mediaMetadata}
* and the static and dynamic metadata from the {@link TrackSelection#getFormat(int) track
* selections' formats} and {@link
MetadataOutput
#onMetadata(Metadata)}.
* selections' formats} and {@link
Listener
#onMetadata(Metadata)}.
*
* <p>{@link #onEvents(Player, Events)} will also be called to report this event along with
* other events that happen in the same {@link Looper} message queue iteration.
...
...
@@ -1924,7 +1924,7 @@ public interface Player {
*
* <p>This {@link MediaMetadata} is a combination of the {@link MediaItem#mediaMetadata} and the
* static and dynamic metadata from the {@link TrackSelection#getFormat(int) track selections'
* formats} and {@link
MetadataOutput
#onMetadata(Metadata)}.
* formats} and {@link
Listener
#onMetadata(Metadata)}.
*/
MediaMetadata
getMediaMetadata
();
...
...
library/core/src/androidTest/java/com/google/android/exoplayer2/ClippedPlaybackTest.java
View file @
7dffb2dc
...
...
@@ -22,7 +22,6 @@ import android.net.Uri;
import
androidx.test.ext.junit.runners.AndroidJUnit4
;
import
com.google.android.exoplayer2.source.ClippingMediaSource
;
import
com.google.android.exoplayer2.text.Cue
;
import
com.google.android.exoplayer2.text.TextOutput
;
import
com.google.android.exoplayer2.util.ConditionVariable
;
import
com.google.android.exoplayer2.util.MimeTypes
;
import
com.google.common.collect.ImmutableList
;
...
...
@@ -56,34 +55,22 @@ public final class ClippedPlaybackTest {
.
setClipEndPositionMs
(
1000
)
.
build
();
AtomicReference
<
SimpleExoPlayer
>
player
=
new
AtomicReference
<>();
CapturingTextOutput
textOutput
=
new
CapturingTextOutput
();
ConditionVariable
playbackEnded
=
new
ConditionVariable
();
TextCapturingPlaybackListener
textCapturer
=
new
TextCapturingPlaybackListener
();
getInstrumentation
()
.
runOnMainSync
(
()
->
{
player
.
set
(
new
SimpleExoPlayer
.
Builder
(
getInstrumentation
().
getContext
()).
build
());
player
.
get
().
addTextOutput
(
textOutput
);
player
.
get
()
.
addListener
(
new
Player
.
Listener
()
{
@Override
public
void
onPlaybackStateChanged
(
@Player
.
State
int
playbackState
)
{
if
(
playbackState
==
Player
.
STATE_ENDED
)
{
playbackEnded
.
open
();
}
}
});
player
.
get
().
addListener
(
textCapturer
);
player
.
get
().
setMediaItem
(
mediaItem
);
player
.
get
().
prepare
();
player
.
get
().
play
();
});
playbackEnded
.
block
();
textCapturer
.
block
();
getInstrumentation
().
runOnMainSync
(()
->
player
.
get
().
release
());
getInstrumentation
().
waitForIdleSync
();
assertThat
(
Iterables
.
getOnlyElement
(
Iterables
.
concat
(
text
Output
.
cues
)).
text
.
toString
())
assertThat
(
Iterables
.
getOnlyElement
(
Iterables
.
concat
(
text
Capturer
.
cues
)).
text
.
toString
())
.
isEqualTo
(
"This is the first subtitle."
);
}
...
...
@@ -110,42 +97,32 @@ public final class ClippedPlaybackTest {
.
setClipEndPositionMs
(
4_000
)
.
build
());
AtomicReference
<
SimpleExoPlayer
>
player
=
new
AtomicReference
<>();
CapturingTextOutput
textOutput
=
new
CapturingTextOutput
();
ConditionVariable
playbackEnded
=
new
ConditionVariable
();
TextCapturingPlaybackListener
textCapturer
=
new
TextCapturingPlaybackListener
();
getInstrumentation
()
.
runOnMainSync
(
()
->
{
player
.
set
(
new
SimpleExoPlayer
.
Builder
(
getInstrumentation
().
getContext
()).
build
());
player
.
get
().
addTextOutput
(
textOutput
);
player
.
get
()
.
addListener
(
new
Player
.
Listener
()
{
@Override
public
void
onPlaybackStateChanged
(
@Player
.
State
int
playbackState
)
{
if
(
playbackState
==
Player
.
STATE_ENDED
)
{
playbackEnded
.
open
();
}
}
});
player
.
get
().
addListener
(
textCapturer
);
player
.
get
().
setMediaItems
(
mediaItems
);
player
.
get
().
prepare
();
player
.
get
().
play
();
});
playbackEnded
.
block
();
textCapturer
.
block
();
getInstrumentation
().
runOnMainSync
(()
->
player
.
get
().
release
());
getInstrumentation
().
waitForIdleSync
();
assertThat
(
Iterables
.
getOnlyElement
(
Iterables
.
concat
(
text
Output
.
cues
)).
text
.
toString
())
assertThat
(
Iterables
.
getOnlyElement
(
Iterables
.
concat
(
text
Capturer
.
cues
)).
text
.
toString
())
.
isEqualTo
(
"This is the first subtitle."
);
}
private
static
class
CapturingTextOutput
implements
TextOutput
{
private
static
class
TextCapturingPlaybackListener
implements
Player
.
Listener
{
private
final
ConditionVariable
playbackEnded
;
private
final
List
<
List
<
Cue
>>
cues
;
private
CapturingTextOutput
()
{
private
TextCapturingPlaybackListener
()
{
playbackEnded
=
new
ConditionVariable
();
cues
=
new
ArrayList
<>();
}
...
...
@@ -153,5 +130,16 @@ public final class ClippedPlaybackTest {
public
void
onCues
(
List
<
Cue
>
cues
)
{
this
.
cues
.
add
(
cues
);
}
@Override
public
void
onPlaybackStateChanged
(
@Player
.
State
int
playbackState
)
{
if
(
playbackState
==
Player
.
STATE_ENDED
)
{
playbackEnded
.
open
();
}
}
public
void
block
()
throws
InterruptedException
{
playbackEnded
.
block
();
}
}
}
library/ui/src/main/java/com/google/android/exoplayer2/ui/PlayerView.java
View file @
7dffb2dc
...
...
@@ -1490,7 +1490,7 @@ public class PlayerView extends FrameLayout implements AdViewProvider {
@Override
public
void
onCues
(
List
<
Cue
>
cues
)
{
if
(
subtitleView
!=
null
)
{
subtitleView
.
on
Cues
(
cues
);
subtitleView
.
set
Cues
(
cues
);
}
}
...
...
library/ui/src/main/java/com/google/android/exoplayer2/ui/StyledPlayerView.java
View file @
7dffb2dc
...
...
@@ -1531,7 +1531,7 @@ public class StyledPlayerView extends FrameLayout implements AdViewProvider {
@Override
public
void
onCues
(
List
<
Cue
>
cues
)
{
if
(
subtitleView
!=
null
)
{
subtitleView
.
on
Cues
(
cues
);
subtitleView
.
set
Cues
(
cues
);
}
}
...
...
robolectricutils/src/main/java/com/google/android/exoplayer2/robolectric/PlaybackOutput.java
View file @
7dffb2dc
...
...
@@ -17,6 +17,7 @@ package com.google.android.exoplayer2.robolectric;
import
android.graphics.Bitmap
;
import
androidx.annotation.Nullable
;
import
com.google.android.exoplayer2.Player
;
import
com.google.android.exoplayer2.SimpleExoPlayer
;
import
com.google.android.exoplayer2.metadata.Metadata
;
import
com.google.android.exoplayer2.metadata.dvbsi.AppInfoTable
;
...
...
@@ -63,8 +64,18 @@ public final class PlaybackOutput implements Dumper.Dumpable {
// TODO: Consider passing playback position into MetadataOutput and TextOutput. Calling
// player.getCurrentPosition() inside onMetadata/Cues will likely be non-deterministic
// because renderer-thread != playback-thread.
player
.
addMetadataOutput
(
metadatas:
:
add
);
// TODO(internal b/174661563): Output subtitle data when it's not flaky.
player
.
addListener
(
new
Player
.
Listener
()
{
@Override
public
void
onMetadata
(
Metadata
metadata
)
{
metadatas
.
add
(
metadata
);
}
@Override
public
void
onCues
(
List
<
Cue
>
cues
)
{
// TODO(internal b/174661563): Output subtitle data when it's not flaky.
}
});
}
/**
...
...
robolectricutils/src/main/java/com/google/android/exoplayer2/robolectric/TestPlayerRunHelper.java
View file @
7dffb2dc
...
...
@@ -27,7 +27,6 @@ import com.google.android.exoplayer2.SimpleExoPlayer;
import
com.google.android.exoplayer2.Timeline
;
import
com.google.android.exoplayer2.util.ConditionVariable
;
import
com.google.android.exoplayer2.util.Util
;
import
com.google.android.exoplayer2.video.VideoListener
;
import
java.util.concurrent.TimeoutException
;
import
java.util.concurrent.atomic.AtomicBoolean
;
import
java.util.concurrent.atomic.AtomicReference
;
...
...
@@ -252,7 +251,7 @@ public class TestPlayerRunHelper {
}
/**
* Runs tasks of the main {@link Looper} until the {@link
Video
Listener#onRenderedFirstFrame}
* Runs tasks of the main {@link Looper} until the {@link
Player.
Listener#onRenderedFirstFrame}
* callback is called or a playback error occurs.
*
* <p>If a playback error occurs it will be thrown wrapped in an {@link IllegalStateException}..
...
...
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