-
Notifications
You must be signed in to change notification settings - Fork 299
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using test utilities to produce a fake media source which emulates buffering behaviour #1372
Comments
I think this can be controlled by the If you need to let them load more data at a later point in the test, you'd need to go one level down and inject your own custom |
Hmm, it seems that creating a custom In this setup the val mediaItem = MediaItem.Builder().setMediaId("TEST_ID").build()
val fakeMediaSource = object : FakeMediaSource(timelineForMediaItem(mediaItem, 10.seconds)) {
override fun createMediaPeriod(
id: MediaSource.MediaPeriodId,
trackGroupArray: TrackGroupArray,
allocator: Allocator,
mediaSourceEventDispatcher: MediaSourceEventListener.EventDispatcher,
drmSessionManager: DrmSessionManager,
drmEventDispatcher: DrmSessionEventListener.EventDispatcher,
transferListener: TransferListener?
): MediaPeriod = object : FakeMediaPeriod(
trackGroupArray,
allocator,
{ _, _ -> ImmutableList.of() },
mediaSourceEventDispatcher,
drmSessionManager,
drmEventDispatcher,
false
) {
override fun createSampleStream(
allocator: Allocator,
mediaSourceEventDispatcher: MediaSourceEventListener.EventDispatcher?,
drmSessionManager: DrmSessionManager,
drmEventDispatcher: DrmSessionEventListener.EventDispatcher,
initialFormat: Format,
fakeSampleStreamItems: MutableList<FakeSampleStream.FakeSampleStreamItem>
): FakeSampleStream = FakeSampleStream(
allocator,
mediaSourceEventDispatcher,
drmSessionManager,
drmEventDispatcher,
initialFormat,
listOf(
FakeSampleStreamItem.oneByteSample(5.seconds.inWholeMicroseconds),
FakeSampleStreamItem.oneByteSample(5.seconds.inWholeMicroseconds)
)
)
}
}
player.setMediaSource(fakeMediaSource)
player.prepare()
player.play()
TestPlayerRunHelper.playUntilPosition(player, 0, 1.seconds.inWholeMilliseconds)
TestPlayerRunHelper.runUntilPlaybackState(player, Player.STATE_BUFFERING) |
It's not running because
If I make both these changes, the test runs through as expected. |
Thanks, I'll give that a try |
That sounds like working as intended I think. If you add the As per my original comment, you can change the sample stream later with the
|
I'm trying to write some unit tests and using the existing tests as a guide (like this one: https://github.com/androidx/media/blob/d833d59124d795afc146322fe488b2c0d4b9af6a/libraries/exoplayer/src/test/java/androidx/media3/exoplayer/analytics/PlaybackStatsListenerTest.java)
I'm trying to test the behaviour of a custom
Player.Listener
that should react only once for each media item that starts playing. UsingFakeMediaSource
I can emulate most of the behaviours I'm interested in covering. However one behaviour I'd like to cover is content which buffers part way through.If I set a real media item on the player from a remote mp3 url and observe the events, I get a tonne of
onPlaybackStateChanged
andonIsPlayingChanged
events as it swaps between buffering and ready.I'd like to have a test that covers this behaviour but if possible I'd like to do it using local resources rather than my current method of hitting a real mp3 on a remote server.
Is there a way to emulate this using
FakeMediaSource
or one of its subclasses? Or would I need to put a local mp3 file in my test resources and load that?The text was updated successfully, but these errors were encountered: