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
12bd36d4
authored
Jul 30, 2020
by
christosts
Committed by
Oliver Woodman
Aug 01, 2020
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Migrate test resettingMediaSourcesGivesFreshSourceInfo() to TestExoPlayer
PiperOrigin-RevId: 323985679
parent
6d0696a3
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
61 deletions
library/core/src/test/java/com/google/android/exoplayer2/ExoPlayerTest.java
library/core/src/test/java/com/google/android/exoplayer2/ExoPlayerTest.java
View file @
12bd36d4
...
@@ -18,6 +18,8 @@ package com.google.android.exoplayer2;
...
@@ -18,6 +18,8 @@ package com.google.android.exoplayer2;
import
static
com
.
google
.
android
.
exoplayer2
.
testutil
.
FakeSampleStream
.
FakeSampleStreamItem
.
END_OF_STREAM_ITEM
;
import
static
com
.
google
.
android
.
exoplayer2
.
testutil
.
FakeSampleStream
.
FakeSampleStreamItem
.
END_OF_STREAM_ITEM
;
import
static
com
.
google
.
android
.
exoplayer2
.
testutil
.
FakeSampleStream
.
FakeSampleStreamItem
.
oneByteSample
;
import
static
com
.
google
.
android
.
exoplayer2
.
testutil
.
FakeSampleStream
.
FakeSampleStreamItem
.
oneByteSample
;
import
static
com
.
google
.
android
.
exoplayer2
.
testutil
.
TestExoPlayer
.
runUntilPlaybackState
;
import
static
com
.
google
.
android
.
exoplayer2
.
testutil
.
TestExoPlayer
.
runUntilPlaybackState
;
import
static
com
.
google
.
android
.
exoplayer2
.
testutil
.
TestExoPlayer
.
runUntilTimelineChanged
;
import
static
com
.
google
.
android
.
exoplayer2
.
testutil
.
TestUtil
.
runMainLooperUntil
;
import
static
com
.
google
.
common
.
truth
.
Truth
.
assertThat
;
import
static
com
.
google
.
common
.
truth
.
Truth
.
assertThat
;
import
static
org
.
junit
.
Assert
.
assertArrayEquals
;
import
static
org
.
junit
.
Assert
.
assertArrayEquals
;
import
static
org
.
junit
.
Assert
.
assertThrows
;
import
static
org
.
junit
.
Assert
.
assertThrows
;
...
@@ -375,81 +377,62 @@ public final class ExoPlayerTest {
...
@@ -375,81 +377,62 @@ public final class ExoPlayerTest {
Timeline
firstTimeline
=
Timeline
firstTimeline
=
new
FakeTimeline
(
new
FakeTimeline
(
new
TimelineWindowDefinition
(
new
TimelineWindowDefinition
(
/* isSeekable= */
true
,
/* isDynamic= */
false
,
1
000_000_000
));
/* isSeekable= */
true
,
/* isDynamic= */
false
,
/* durationUs= */
1_
000_000_000
));
MediaSource
firstSource
=
new
FakeMediaSource
(
firstTimeline
,
ExoPlayerTestRunner
.
VIDEO_FORMAT
);
MediaSource
firstSource
=
new
FakeMediaSource
(
firstTimeline
,
ExoPlayerTestRunner
.
VIDEO_FORMAT
);
final
CountDownLatch
queuedSourceInfoCountDownLatch
=
new
CountDownLatch
(
1
);
AtomicBoolean
secondSourcePrepared
=
new
AtomicBoolean
();
final
CountDownLatch
completePreparationCountDownLatch
=
new
CountDownLatch
(
1
);
Timeline
secondTimeline
=
new
FakeTimeline
(
/* windowCount= */
1
);
MediaSource
secondSource
=
MediaSource
secondSource
=
new
FakeMediaSource
(
secondTimeline
,
ExoPlayerTestRunner
.
VIDEO_FORMAT
)
{
new
FakeMediaSource
(
new
FakeTimeline
(
/* windowCount= */
1
),
ExoPlayerTestRunner
.
VIDEO_FORMAT
)
{
@Override
@Override
public
synchronized
void
prepareSourceInternal
(
public
synchronized
void
prepareSourceInternal
(
@Nullable
TransferListener
mediaTransferListener
)
{
@Nullable
TransferListener
mediaTransferListener
)
{
super
.
prepareSourceInternal
(
mediaTransferListener
);
super
.
prepareSourceInternal
(
mediaTransferListener
);
// We've queued a source info refresh on the playback thread's event queue. Allow the
secondSourcePrepared
.
set
(
true
);
// test thread to set the third source to the playlist, and block this thread (the
// playback thread) until the test thread's call to setMediaSources() has returned.
queuedSourceInfoCountDownLatch
.
countDown
();
try
{
completePreparationCountDownLatch
.
await
();
}
catch
(
InterruptedException
e
)
{
throw
new
IllegalStateException
(
e
);
}
}
}
};
};
Object
thirdSourceManifest
=
new
Object
();
Timeline
thirdTimeline
=
new
FakeTimeline
(
/* windowCount= */
1
);
Timeline
thirdTimeline
=
new
FakeTimeline
(
/* windowCount= */
1
,
thirdSourceManifest
);
MediaSource
thirdSource
=
new
FakeMediaSource
(
thirdTimeline
,
ExoPlayerTestRunner
.
VIDEO_FORMAT
);
MediaSource
thirdSource
=
new
FakeMediaSource
(
thirdTimeline
,
ExoPlayerTestRunner
.
VIDEO_FORMAT
);
SimpleExoPlayer
player
=
new
TestExoPlayer
.
Builder
(
context
).
setRenderers
(
renderer
).
build
();
EventListener
mockEventListener
=
mock
(
EventListener
.
class
);
player
.
addListener
(
mockEventListener
);
player
.
setMediaSource
(
firstSource
);
player
.
prepare
();
player
.
play
();
runUntilTimelineChanged
(
player
);
player
.
setMediaSource
(
secondSource
);
runMainLooperUntil
(
secondSourcePrepared:
:
get
);
player
.
setMediaSource
(
thirdSource
);
runUntilPlaybackState
(
player
,
Player
.
STATE_ENDED
);
// Prepare the player with a source with the first manifest and a non-empty timeline. Prepare
// the player again with a source and a new manifest, which will never be exposed. Allow the
// test thread to set a third source, and block the playback thread until the test thread's call
// to setMediaSources() has returned.
ActionSchedule
actionSchedule
=
new
ActionSchedule
.
Builder
(
TAG
)
.
waitForTimelineChanged
(
firstTimeline
,
/* expectedReason */
Player
.
TIMELINE_CHANGE_REASON_SOURCE_UPDATE
)
.
setMediaSources
(
secondSource
)
.
executeRunnable
(
()
->
{
try
{
queuedSourceInfoCountDownLatch
.
await
();
}
catch
(
InterruptedException
e
)
{
// Ignore.
}
})
.
setMediaSources
(
thirdSource
)
.
executeRunnable
(
completePreparationCountDownLatch:
:
countDown
)
.
build
();
ExoPlayerTestRunner
testRunner
=
new
ExoPlayerTestRunner
.
Builder
(
context
)
.
setMediaSources
(
firstSource
)
.
setRenderers
(
renderer
)
.
setActionSchedule
(
actionSchedule
)
.
build
()
.
start
()
.
blockUntilActionScheduleFinished
(
TIMEOUT_MS
)
.
blockUntilEnded
(
TIMEOUT_MS
);
testRunner
.
assertNoPositionDiscontinuities
();
// The first source's preparation completed with a real timeline. When the second source was
// The first source's preparation completed with a real timeline. When the second source was
// prepared, it immediately exposed a placeholder timeline, but the source info refresh from the
// prepared, it immediately exposed a placeholder timeline, but the source info refresh from the
// second source was suppressed as we replace it with the third source before the update
// second source was suppressed as we replace it with the third source before the update
// arrives.
// arrives.
testRunner
.
assertTimelinesSame
(
InOrder
inOrder
=
inOrder
(
mockEventListener
);
placeholderTimeline
,
inOrder
.
verify
(
mockEventListener
,
never
()).
onPositionDiscontinuity
(
anyInt
());
firstTimeline
,
inOrder
placeholderTimeline
,
.
verify
(
mockEventListener
)
placeholderTimeline
,
.
onTimelineChanged
(
thirdTimeline
);
argThat
(
noUid
(
placeholderTimeline
)),
testRunner
.
assertTimelineChangeReasonsEqual
(
eq
(
Player
.
TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED
));
Player
.
TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED
,
inOrder
Player
.
TIMELINE_CHANGE_REASON_SOURCE_UPDATE
,
.
verify
(
mockEventListener
)
Player
.
TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED
,
.
onTimelineChanged
(
Player
.
TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED
,
argThat
(
noUid
(
firstTimeline
)),
eq
(
Player
.
TIMELINE_CHANGE_REASON_SOURCE_UPDATE
));
Player
.
TIMELINE_CHANGE_REASON_SOURCE_UPDATE
);
inOrder
testRunner
.
assertTrackGroupsEqual
(
.
verify
(
mockEventListener
,
times
(
2
))
new
TrackGroupArray
(
new
TrackGroup
(
ExoPlayerTestRunner
.
VIDEO_FORMAT
)));
.
onTimelineChanged
(
argThat
(
noUid
(
placeholderTimeline
)),
eq
(
Player
.
TIMELINE_CHANGE_REASON_PLAYLIST_CHANGED
));
inOrder
.
verify
(
mockEventListener
)
.
onTimelineChanged
(
argThat
(
noUid
(
thirdTimeline
)),
eq
(
Player
.
TIMELINE_CHANGE_REASON_SOURCE_UPDATE
));
inOrder
.
verify
(
mockEventListener
)
.
onTracksChanged
(
eq
(
new
TrackGroupArray
(
new
TrackGroup
(
ExoPlayerTestRunner
.
VIDEO_FORMAT
))),
any
());
assertThat
(
renderer
.
isEnded
).
isTrue
();
assertThat
(
renderer
.
isEnded
).
isTrue
();
}
}
...
...
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