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
30ed83ec
authored
Nov 18, 2019
by
Oliver Woodman
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Revert "Playlist API: Add setMediaItem() and prepare()"
This reverts commit
cd2c1f2f
.
parent
c9cc147f
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
46 additions
and
365 deletions
demos/main/src/main/java/com/google/android/exoplayer2/demo/PlayerActivity.java
library/core/src/main/java/com/google/android/exoplayer2/ExoPlayer.java
library/core/src/main/java/com/google/android/exoplayer2/ExoPlayerImpl.java
library/core/src/main/java/com/google/android/exoplayer2/SimpleExoPlayer.java
library/core/src/test/java/com/google/android/exoplayer2/ExoPlayerTest.java
testutils/src/main/java/com/google/android/exoplayer2/testutil/ExoPlayerTestRunner.java
testutils/src/main/java/com/google/android/exoplayer2/testutil/StubExoPlayer.java
demos/main/src/main/java/com/google/android/exoplayer2/demo/PlayerActivity.java
View file @
30ed83ec
...
@@ -394,8 +394,7 @@ public class PlayerActivity extends AppCompatActivity
...
@@ -394,8 +394,7 @@ public class PlayerActivity extends AppCompatActivity
if
(
haveStartPosition
)
{
if
(
haveStartPosition
)
{
player
.
seekTo
(
startWindow
,
startPosition
);
player
.
seekTo
(
startWindow
,
startPosition
);
}
}
player
.
setMediaItem
(
mediaSource
);
player
.
prepare
(
mediaSource
,
!
haveStartPosition
,
false
);
player
.
prepare
();
updateButtonVisibility
();
updateButtonVisibility
();
}
}
...
...
library/core/src/main/java/com/google/android/exoplayer2/ExoPlayer.java
View file @
30ed83ec
...
@@ -331,50 +331,25 @@ public interface ExoPlayer extends Player {
...
@@ -331,50 +331,25 @@ public interface ExoPlayer extends Player {
*/
*/
void
retry
();
void
retry
();
/** Prepares the player. */
void
prepare
();
/**
/**
* @deprecated Use {@code setMediaItem(mediaSource, C.TIME_UNSET)} and {@link #prepare()} instead.
* Prepares the player to play the provided {@link MediaSource}. Equivalent to {@code
* prepare(mediaSource, true, true)}.
*/
*/
@Deprecated
void
prepare
(
MediaSource
mediaSource
);
void
prepare
(
MediaSource
mediaSource
);
/** @deprecated Use {@link #setMediaItem(MediaSource, long)} and {@link #prepare()} instead. */
@Deprecated
void
prepare
(
MediaSource
mediaSource
,
boolean
resetPosition
,
boolean
resetState
);
/**
* Sets the specified {@link MediaSource}.
*
* <p>Note: This is an intermediate implementation towards a larger change. Until then {@link
* #prepare()} has to be called immediately after calling this method.
*
* @param mediaItem The new {@link MediaSource}.
*/
void
setMediaItem
(
MediaSource
mediaItem
);
/**
/**
* Sets the specified {@link MediaSource}.
* Prepares the player to play the provided {@link MediaSource}, optionally resetting the playback
*
* position the default position in the first {@link Timeline.Window}.
* <p>Note: This is an intermediate implementation towards a larger change. Until then {@link
* #prepare()} has to be called immediately after calling this method.
*
*
* <p>This intermediate implementation calls {@code stop(true)} before seeking to avoid seeking in
* @param mediaSource The {@link MediaSource} to play.
* a media item that has been set previously. It is equivalent with calling
* @param resetPosition Whether the playback position should be reset to the default position in
*
* the first {@link Timeline.Window}. If false, playback will start from the position defined
* <pre><code>
* by {@link #getCurrentWindowIndex()} and {@link #getCurrentPosition()}.
* if (!getCurrentTimeline().isEmpty()) {
* @param resetState Whether the timeline, manifest, tracks and track selections should be reset.
* player.stop(true);
* Should be true unless the player is being prepared to play the same media as it was playing
* }
* previously (e.g. if playback failed and is being retried).
* player.seekTo(0, startPositionMs);
* player.setMediaItem(mediaItem);
* </code></pre>
*
* @param mediaItem The new {@link MediaSource}.
* @param startPositionMs The position in milliseconds to start playback from.
*/
*/
void
setMediaItem
(
MediaSource
mediaItem
,
long
startPositionMs
);
void
prepare
(
MediaSource
mediaSource
,
boolean
resetPosition
,
boolean
resetState
);
/**
/**
* Creates a message that can be sent to a {@link PlayerMessage.Target}. By default, the message
* Creates a message that can be sent to a {@link PlayerMessage.Target}. By default, the message
...
...
library/core/src/main/java/com/google/android/exoplayer2/ExoPlayerImpl.java
View file @
30ed83ec
...
@@ -62,7 +62,7 @@ import java.util.concurrent.CopyOnWriteArrayList;
...
@@ -62,7 +62,7 @@ import java.util.concurrent.CopyOnWriteArrayList;
private
final
Timeline
.
Period
period
;
private
final
Timeline
.
Period
period
;
private
final
ArrayDeque
<
Runnable
>
pendingListenerNotifications
;
private
final
ArrayDeque
<
Runnable
>
pendingListenerNotifications
;
@Nullable
private
MediaSource
mediaSource
;
private
MediaSource
mediaSource
;
private
boolean
playWhenReady
;
private
boolean
playWhenReady
;
@PlaybackSuppressionReason
private
int
playbackSuppressionReason
;
@PlaybackSuppressionReason
private
int
playbackSuppressionReason
;
@RepeatMode
private
int
repeatMode
;
@RepeatMode
private
int
repeatMode
;
...
@@ -219,38 +219,34 @@ import java.util.concurrent.CopyOnWriteArrayList;
...
@@ -219,38 +219,34 @@ import java.util.concurrent.CopyOnWriteArrayList;
}
}
@Override
@Override
@Deprecated
public
void
prepare
(
MediaSource
mediaSource
)
{
public
void
prepare
(
MediaSource
mediaSource
)
{
setMediaItem
(
mediaSource
);
prepare
(
mediaSource
,
/* resetPosition= */
true
,
/* resetState= */
true
);
prepareInternal
(
/* resetPosition= */
true
,
/* resetState= */
true
);
}
}
@Override
@Override
@Deprecated
public
void
prepare
(
MediaSource
mediaSource
,
boolean
resetPosition
,
boolean
resetState
)
{
public
void
prepare
(
MediaSource
mediaSource
,
boolean
resetPosition
,
boolean
resetState
)
{
setMediaItem
(
mediaSource
);
this
.
mediaSource
=
mediaSource
;
prepareInternal
(
resetPosition
,
resetState
);
PlaybackInfo
playbackInfo
=
}
getResetPlaybackInfo
(
resetPosition
,
@Override
resetState
,
public
void
prepare
()
{
/* resetError= */
true
,
Assertions
.
checkNotNull
(
mediaSource
);
/* playbackState= */
Player
.
STATE_BUFFERING
);
prepareInternal
(
/* resetPosition= */
false
,
/* resetState= */
true
);
// Trigger internal prepare first before updating the playback info and notifying external
}
// listeners to ensure that new operations issued in the listener notifications reach the
// player after this prepare. The internal player can't change the playback info immediately
@Override
// because it uses a callback.
public
void
setMediaItem
(
MediaSource
mediaItem
,
long
startPositionMs
)
{
hasPendingPrepare
=
true
;
if
(!
getCurrentTimeline
().
isEmpty
())
{
pendingOperationAcks
++;
stop
(
/* reset= */
true
);
internalPlayer
.
prepare
(
mediaSource
,
resetPosition
,
resetState
);
}
updatePlaybackInfo
(
seekTo
(
/* windowIndex= */
0
,
startPositionMs
);
playbackInfo
,
setMediaItem
(
mediaItem
);
/* positionDiscontinuity= */
false
,
/* ignored */
DISCONTINUITY_REASON_INTERNAL
,
TIMELINE_CHANGE_REASON_RESET
,
/* seekProcessed= */
false
);
}
}
@Override
public
void
setMediaItem
(
MediaSource
mediaItem
)
{
mediaSource
=
mediaItem
;
}
@Override
@Override
public
void
setPlayWhenReady
(
boolean
playWhenReady
)
{
public
void
setPlayWhenReady
(
boolean
playWhenReady
)
{
...
@@ -610,29 +606,6 @@ import java.util.concurrent.CopyOnWriteArrayList;
...
@@ -610,29 +606,6 @@ import java.util.concurrent.CopyOnWriteArrayList;
}
}
}
}
/* package */
void
prepareInternal
(
boolean
resetPosition
,
boolean
resetState
)
{
Assertions
.
checkNotNull
(
mediaSource
);
PlaybackInfo
playbackInfo
=
getResetPlaybackInfo
(
resetPosition
,
resetState
,
/* resetError= */
true
,
/* playbackState= */
Player
.
STATE_BUFFERING
);
// Trigger internal prepare first before updating the playback info and notifying external
// listeners to ensure that new operations issued in the listener notifications reach the
// player after this prepare. The internal player can't change the playback info immediately
// because it uses a callback.
hasPendingPrepare
=
true
;
pendingOperationAcks
++;
internalPlayer
.
prepare
(
mediaSource
,
resetPosition
,
resetState
);
updatePlaybackInfo
(
playbackInfo
,
/* positionDiscontinuity= */
false
,
/* ignored */
DISCONTINUITY_REASON_INTERNAL
,
TIMELINE_CHANGE_REASON_RESET
,
/* seekProcessed= */
false
);
}
private
void
handlePlaybackParameters
(
private
void
handlePlaybackParameters
(
PlaybackParameters
playbackParameters
,
boolean
operationAck
)
{
PlaybackParameters
playbackParameters
,
boolean
operationAck
)
{
if
(
operationAck
)
{
if
(
operationAck
)
{
...
...
library/core/src/main/java/com/google/android/exoplayer2/SimpleExoPlayer.java
View file @
30ed83ec
...
@@ -1162,7 +1162,6 @@ public class SimpleExoPlayer extends BasePlayer
...
@@ -1162,7 +1162,6 @@ public class SimpleExoPlayer extends BasePlayer
}
}
@Override
@Override
@SuppressWarnings
(
"deprecation"
)
public
void
retry
()
{
public
void
retry
()
{
verifyApplicationThread
();
verifyApplicationThread
();
if
(
mediaSource
!=
null
if
(
mediaSource
!=
null
...
@@ -1172,38 +1171,23 @@ public class SimpleExoPlayer extends BasePlayer
...
@@ -1172,38 +1171,23 @@ public class SimpleExoPlayer extends BasePlayer
}
}
@Override
@Override
@Deprecated
@SuppressWarnings
(
"deprecation"
)
public
void
prepare
(
MediaSource
mediaSource
)
{
public
void
prepare
(
MediaSource
mediaSource
)
{
prepare
(
mediaSource
,
/* resetPosition= */
true
,
/* resetState= */
true
);
prepare
(
mediaSource
,
/* resetPosition= */
true
,
/* resetState= */
true
);
}
}
@Override
@Override
@Deprecated
public
void
prepare
(
MediaSource
mediaSource
,
boolean
resetPosition
,
boolean
resetState
)
{
public
void
prepare
(
MediaSource
mediaSource
,
boolean
resetPosition
,
boolean
resetState
)
{
verifyApplicationThread
();
verifyApplicationThread
();
setMediaItem
(
mediaSource
);
if
(
this
.
mediaSource
!=
null
)
{
prepareInternal
(
resetPosition
,
resetState
);
this
.
mediaSource
.
removeEventListener
(
analyticsCollector
);
}
analyticsCollector
.
resetForNewMediaSource
();
}
@Override
this
.
mediaSource
=
mediaSource
;
public
void
prepare
()
{
mediaSource
.
addEventListener
(
eventHandler
,
analyticsCollector
);
verifyApplicationThread
();
@AudioFocusManager
.
PlayerCommand
prepareInternal
(
/* resetPosition= */
false
,
/* resetState= */
true
);
int
playerCommand
=
audioFocusManager
.
handlePrepare
(
getPlayWhenReady
());
}
updatePlayWhenReady
(
getPlayWhenReady
(),
playerCommand
);
player
.
prepare
(
mediaSource
,
resetPosition
,
resetState
);
@Override
public
void
setMediaItem
(
MediaSource
mediaItem
,
long
startPositionMs
)
{
verifyApplicationThread
();
setMediaItemInternal
(
mediaItem
);
player
.
setMediaItem
(
mediaItem
,
startPositionMs
);
}
@Override
public
void
setMediaItem
(
MediaSource
mediaItem
)
{
verifyApplicationThread
();
setMediaItemInternal
(
mediaItem
);
player
.
setMediaItem
(
mediaItem
);
}
}
@Override
@Override
...
@@ -1448,23 +1432,6 @@ public class SimpleExoPlayer extends BasePlayer
...
@@ -1448,23 +1432,6 @@ public class SimpleExoPlayer extends BasePlayer
// Internal methods.
// Internal methods.
private
void
prepareInternal
(
boolean
resetPosition
,
boolean
resetState
)
{
Assertions
.
checkNotNull
(
mediaSource
);
@AudioFocusManager
.
PlayerCommand
int
playerCommand
=
audioFocusManager
.
handlePrepare
(
getPlayWhenReady
());
updatePlayWhenReady
(
getPlayWhenReady
(),
playerCommand
);
player
.
prepareInternal
(
resetPosition
,
resetState
);
}
private
void
setMediaItemInternal
(
MediaSource
mediaItem
)
{
if
(
mediaSource
!=
null
)
{
mediaSource
.
removeEventListener
(
analyticsCollector
);
analyticsCollector
.
resetForNewMediaSource
();
}
mediaSource
=
mediaItem
;
mediaSource
.
addEventListener
(
eventHandler
,
analyticsCollector
);
}
private
void
removeSurfaceCallbacks
()
{
private
void
removeSurfaceCallbacks
()
{
if
(
textureView
!=
null
)
{
if
(
textureView
!=
null
)
{
if
(
textureView
.
getSurfaceTextureListener
()
!=
componentListener
)
{
if
(
textureView
.
getSurfaceTextureListener
()
!=
componentListener
)
{
...
...
library/core/src/test/java/com/google/android/exoplayer2/ExoPlayerTest.java
View file @
30ed83ec
...
@@ -16,7 +16,6 @@
...
@@ -16,7 +16,6 @@
package
com
.
google
.
android
.
exoplayer2
;
package
com
.
google
.
android
.
exoplayer2
;
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
.
fail
;
import
static
org
.
junit
.
Assert
.
fail
;
import
static
org
.
robolectric
.
Shadows
.
shadowOf
;
import
static
org
.
robolectric
.
Shadows
.
shadowOf
;
...
@@ -36,10 +35,7 @@ import com.google.android.exoplayer2.Timeline.Window;
...
@@ -36,10 +35,7 @@ import com.google.android.exoplayer2.Timeline.Window;
import
com.google.android.exoplayer2.analytics.AnalyticsListener
;
import
com.google.android.exoplayer2.analytics.AnalyticsListener
;
import
com.google.android.exoplayer2.audio.AudioAttributes
;
import
com.google.android.exoplayer2.audio.AudioAttributes
;
import
com.google.android.exoplayer2.source.ClippingMediaSource
;
import
com.google.android.exoplayer2.source.ClippingMediaSource
;
import
com.google.android.exoplayer2.source.CompositeMediaSource
;
import
com.google.android.exoplayer2.source.ConcatenatingMediaSource
;
import
com.google.android.exoplayer2.source.ConcatenatingMediaSource
;
import
com.google.android.exoplayer2.source.LoopingMediaSource
;
import
com.google.android.exoplayer2.source.MediaPeriod
;
import
com.google.android.exoplayer2.source.MediaSource
;
import
com.google.android.exoplayer2.source.MediaSource
;
import
com.google.android.exoplayer2.source.MediaSource.MediaPeriodId
;
import
com.google.android.exoplayer2.source.MediaSource.MediaPeriodId
;
import
com.google.android.exoplayer2.source.MediaSourceEventListener.EventDispatcher
;
import
com.google.android.exoplayer2.source.MediaSourceEventListener.EventDispatcher
;
...
@@ -1588,7 +1584,6 @@ public final class ExoPlayerTest {
...
@@ -1588,7 +1584,6 @@ public final class ExoPlayerTest {
AtomicInteger
counter
=
new
AtomicInteger
();
AtomicInteger
counter
=
new
AtomicInteger
();
ActionSchedule
actionSchedule
=
ActionSchedule
actionSchedule
=
new
ActionSchedule
.
Builder
(
"testSendMessagesFromStartPositionOnlyOnce"
)
new
ActionSchedule
.
Builder
(
"testSendMessagesFromStartPositionOnlyOnce"
)
.
waitForTimelineChanged
()
.
pause
()
.
pause
()
.
sendMessage
(
.
sendMessage
(
(
messageType
,
payload
)
->
{
(
messageType
,
payload
)
->
{
...
@@ -2931,218 +2926,6 @@ public final class ExoPlayerTest {
...
@@ -2931,218 +2926,6 @@ public final class ExoPlayerTest {
assertThat
(
seenPlaybackSuppression
.
get
()).
isFalse
();
assertThat
(
seenPlaybackSuppression
.
get
()).
isFalse
();
}
}
@Test
public
void
testDelegatingMediaSourceApproach
()
throws
Exception
{
Timeline
fakeTimeline
=
new
FakeTimeline
(
new
TimelineWindowDefinition
(
/* isSeekable= */
true
,
/* isDynamic= */
false
,
/* durationUs= */
10_000
));
final
ConcatenatingMediaSource
underlyingSource
=
new
ConcatenatingMediaSource
();
CompositeMediaSource
<
Void
>
delegatingMediaSource
=
new
CompositeMediaSource
<
Void
>()
{
@Override
public
void
prepareSourceInternal
(
@Nullable
TransferListener
mediaTransferListener
)
{
super
.
prepareSourceInternal
(
mediaTransferListener
);
underlyingSource
.
addMediaSource
(
new
FakeMediaSource
(
fakeTimeline
,
Builder
.
VIDEO_FORMAT
));
underlyingSource
.
addMediaSource
(
new
FakeMediaSource
(
fakeTimeline
,
Builder
.
VIDEO_FORMAT
));
prepareChildSource
(
null
,
underlyingSource
);
}
@Override
public
MediaPeriod
createPeriod
(
MediaPeriodId
id
,
Allocator
allocator
,
long
startPositionUs
)
{
return
underlyingSource
.
createPeriod
(
id
,
allocator
,
startPositionUs
);
}
@Override
public
void
releasePeriod
(
MediaPeriod
mediaPeriod
)
{
underlyingSource
.
releasePeriod
(
mediaPeriod
);
}
@Override
protected
void
onChildSourceInfoRefreshed
(
Void
id
,
MediaSource
mediaSource
,
Timeline
timeline
)
{
refreshSourceInfo
(
timeline
);
}
};
int
[]
currentWindowIndices
=
new
int
[
1
];
long
[]
currentPlaybackPositions
=
new
long
[
1
];
long
[]
windowCounts
=
new
long
[
1
];
int
seekToWindowIndex
=
1
;
ActionSchedule
actionSchedule
=
new
ActionSchedule
.
Builder
(
"testDelegatingMediaSourceApproach"
)
.
seek
(
/* windowIndex= */
1
,
/* positionMs= */
5000
)
.
waitForSeekProcessed
()
.
executeRunnable
(
new
PlayerRunnable
()
{
@Override
public
void
run
(
SimpleExoPlayer
player
)
{
currentWindowIndices
[
0
]
=
player
.
getCurrentWindowIndex
();
currentPlaybackPositions
[
0
]
=
player
.
getCurrentPosition
();
windowCounts
[
0
]
=
player
.
getCurrentTimeline
().
getWindowCount
();
}
})
.
build
();
ExoPlayerTestRunner
exoPlayerTestRunner
=
new
Builder
()
.
setMediaSource
(
delegatingMediaSource
)
.
setActionSchedule
(
actionSchedule
)
.
build
(
context
)
.
start
()
.
blockUntilActionScheduleFinished
(
TIMEOUT_MS
)
.
blockUntilEnded
(
TIMEOUT_MS
);
exoPlayerTestRunner
.
assertTimelineChangeReasonsEqual
(
Player
.
TIMELINE_CHANGE_REASON_PREPARED
);
assertArrayEquals
(
new
long
[]
{
2
},
windowCounts
);
assertArrayEquals
(
new
int
[]
{
seekToWindowIndex
},
currentWindowIndices
);
assertArrayEquals
(
new
long
[]
{
5_000
},
currentPlaybackPositions
);
}
@Test
public
void
testSeekTo_windowIndexIsReset_deprecated
()
throws
Exception
{
FakeTimeline
fakeTimeline
=
new
FakeTimeline
(
/* windowCount= */
1
);
FakeMediaSource
mediaSource
=
new
FakeMediaSource
(
fakeTimeline
);
LoopingMediaSource
loopingMediaSource
=
new
LoopingMediaSource
(
mediaSource
,
2
);
final
int
[]
windowIndex
=
{
C
.
INDEX_UNSET
};
final
long
[]
positionMs
=
{
C
.
TIME_UNSET
};
ActionSchedule
actionSchedule
=
new
ActionSchedule
.
Builder
(
"testSeekTo_windowIndexIsReset_deprecated"
)
.
seek
(
/* windowIndex= */
1
,
/* positionMs= */
C
.
TIME_UNSET
)
.
waitForSeekProcessed
()
.
playUntilPosition
(
/* windowIndex= */
1
,
/* positionMs= */
5000
)
.
executeRunnable
(
new
PlayerRunnable
()
{
@Override
public
void
run
(
SimpleExoPlayer
player
)
{
//noinspection deprecation
player
.
prepare
(
mediaSource
);
player
.
seekTo
(
/* positionMs= */
5000
);
}
})
.
executeRunnable
(
new
PlayerRunnable
()
{
@Override
public
void
run
(
SimpleExoPlayer
player
)
{
windowIndex
[
0
]
=
player
.
getCurrentWindowIndex
();
positionMs
[
0
]
=
player
.
getCurrentPosition
();
}
})
.
build
();
new
ExoPlayerTestRunner
.
Builder
()
.
setMediaSource
(
loopingMediaSource
)
.
setActionSchedule
(
actionSchedule
)
.
build
(
context
)
.
start
()
.
blockUntilActionScheduleFinished
(
TIMEOUT_MS
);
assertThat
(
windowIndex
[
0
]).
isEqualTo
(
0
);
assertThat
(
positionMs
[
0
]).
isAtLeast
(
5000L
);
}
@Test
public
void
testSeekTo_windowIndexIsReset
()
throws
Exception
{
FakeTimeline
fakeTimeline
=
new
FakeTimeline
(
/* windowCount= */
1
);
FakeMediaSource
mediaSource
=
new
FakeMediaSource
(
fakeTimeline
);
LoopingMediaSource
loopingMediaSource
=
new
LoopingMediaSource
(
mediaSource
,
2
);
final
int
[]
windowIndex
=
{
C
.
INDEX_UNSET
};
final
long
[]
positionMs
=
{
C
.
TIME_UNSET
};
ActionSchedule
actionSchedule
=
new
ActionSchedule
.
Builder
(
"testSeekTo_windowIndexIsReset"
)
.
seek
(
/* windowIndex= */
1
,
/* positionMs= */
C
.
TIME_UNSET
)
.
waitForSeekProcessed
()
.
playUntilPosition
(
/* windowIndex= */
1
,
/* positionMs= */
5000
)
.
executeRunnable
(
new
PlayerRunnable
()
{
@Override
public
void
run
(
SimpleExoPlayer
player
)
{
player
.
setMediaItem
(
mediaSource
,
/* startPositionMs= */
5000
);
player
.
prepare
();
}
})
.
executeRunnable
(
new
PlayerRunnable
()
{
@Override
public
void
run
(
SimpleExoPlayer
player
)
{
windowIndex
[
0
]
=
player
.
getCurrentWindowIndex
();
positionMs
[
0
]
=
player
.
getCurrentPosition
();
}
})
.
build
();
new
ExoPlayerTestRunner
.
Builder
()
.
setMediaSource
(
loopingMediaSource
)
.
setActionSchedule
(
actionSchedule
)
.
build
(
context
)
.
start
()
.
blockUntilActionScheduleFinished
(
TIMEOUT_MS
);
assertThat
(
windowIndex
[
0
]).
isEqualTo
(
0
);
assertThat
(
positionMs
[
0
]).
isAtLeast
(
5000L
);
}
@Test
public
void
becomingNoisyIgnoredIfBecomingNoisyHandlingIsDisabled
()
throws
Exception
{
CountDownLatch
becomingNoisyHandlingDisabled
=
new
CountDownLatch
(
1
);
CountDownLatch
becomingNoisyDelivered
=
new
CountDownLatch
(
1
);
PlayerStateGrabber
playerStateGrabber
=
new
PlayerStateGrabber
();
ActionSchedule
actionSchedule
=
new
ActionSchedule
.
Builder
(
"becomingNoisyIgnoredIfBecomingNoisyHandlingIsDisabled"
)
.
executeRunnable
(
new
PlayerRunnable
()
{
@Override
public
void
run
(
SimpleExoPlayer
player
)
{
player
.
setHandleAudioBecomingNoisy
(
false
);
becomingNoisyHandlingDisabled
.
countDown
();
// Wait for the broadcast to be delivered from the main thread.
try
{
becomingNoisyDelivered
.
await
();
}
catch
(
InterruptedException
e
)
{
throw
new
IllegalStateException
(
e
);
}
}
})
.
delay
(
1
)
// Handle pending messages on the playback thread.
.
executeRunnable
(
playerStateGrabber
)
.
build
();
ExoPlayerTestRunner
testRunner
=
new
ExoPlayerTestRunner
.
Builder
().
setActionSchedule
(
actionSchedule
).
build
(
context
).
start
();
becomingNoisyHandlingDisabled
.
await
();
deliverBroadcast
(
new
Intent
(
AudioManager
.
ACTION_AUDIO_BECOMING_NOISY
));
becomingNoisyDelivered
.
countDown
();
testRunner
.
blockUntilActionScheduleFinished
(
TIMEOUT_MS
).
blockUntilEnded
(
TIMEOUT_MS
);
assertThat
(
playerStateGrabber
.
playWhenReady
).
isTrue
();
}
@Test
public
void
pausesWhenBecomingNoisyIfBecomingNoisyHandlingIsEnabled
()
throws
Exception
{
CountDownLatch
becomingNoisyHandlingEnabled
=
new
CountDownLatch
(
1
);
ActionSchedule
actionSchedule
=
new
ActionSchedule
.
Builder
(
"pausesWhenBecomingNoisyIfBecomingNoisyHandlingIsEnabled"
)
.
executeRunnable
(
new
PlayerRunnable
()
{
@Override
public
void
run
(
SimpleExoPlayer
player
)
{
player
.
setHandleAudioBecomingNoisy
(
true
);
becomingNoisyHandlingEnabled
.
countDown
();
}
})
.
waitForPlayWhenReady
(
false
)
// Becoming noisy should set playWhenReady = false
.
play
()
.
build
();
ExoPlayerTestRunner
testRunner
=
new
ExoPlayerTestRunner
.
Builder
().
setActionSchedule
(
actionSchedule
).
build
(
context
).
start
();
becomingNoisyHandlingEnabled
.
await
();
deliverBroadcast
(
new
Intent
(
AudioManager
.
ACTION_AUDIO_BECOMING_NOISY
));
// If the player fails to handle becoming noisy, blockUntilActionScheduleFinished will time out
// and throw, causing the test to fail.
testRunner
.
blockUntilActionScheduleFinished
(
TIMEOUT_MS
).
blockUntilEnded
(
TIMEOUT_MS
);
}
// Internal methods.
// Internal methods.
private
static
ActionSchedule
.
Builder
addSurfaceSwitch
(
ActionSchedule
.
Builder
builder
)
{
private
static
ActionSchedule
.
Builder
addSurfaceSwitch
(
ActionSchedule
.
Builder
builder
)
{
...
...
testutils/src/main/java/com/google/android/exoplayer2/testutil/ExoPlayerTestRunner.java
View file @
30ed83ec
...
@@ -431,8 +431,7 @@ public final class ExoPlayerTestRunner implements Player.EventListener, ActionSc
...
@@ -431,8 +431,7 @@ public final class ExoPlayerTestRunner implements Player.EventListener, ActionSc
if
(
actionSchedule
!=
null
)
{
if
(
actionSchedule
!=
null
)
{
actionSchedule
.
start
(
player
,
trackSelector
,
null
,
handler
,
ExoPlayerTestRunner
.
this
);
actionSchedule
.
start
(
player
,
trackSelector
,
null
,
handler
,
ExoPlayerTestRunner
.
this
);
}
}
player
.
setMediaItem
(
mediaSource
);
player
.
prepare
(
mediaSource
,
/* resetPosition= */
false
,
/* resetState= */
false
);
player
.
prepare
();
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
handleException
(
e
);
handleException
(
e
);
}
}
...
...
testutils/src/main/java/com/google/android/exoplayer2/testutil/StubExoPlayer.java
View file @
30ed83ec
...
@@ -97,11 +97,6 @@ public abstract class StubExoPlayer extends BasePlayer implements ExoPlayer {
...
@@ -97,11 +97,6 @@ public abstract class StubExoPlayer extends BasePlayer implements ExoPlayer {
}
}
@Override
@Override
public
void
prepare
()
{
throw
new
UnsupportedOperationException
();
}
@Override
public
void
prepare
(
MediaSource
mediaSource
)
{
public
void
prepare
(
MediaSource
mediaSource
)
{
throw
new
UnsupportedOperationException
();
throw
new
UnsupportedOperationException
();
}
}
...
@@ -112,16 +107,6 @@ public abstract class StubExoPlayer extends BasePlayer implements ExoPlayer {
...
@@ -112,16 +107,6 @@ public abstract class StubExoPlayer extends BasePlayer implements ExoPlayer {
}
}
@Override
@Override
public
void
setMediaItem
(
MediaSource
mediaItem
)
{
throw
new
UnsupportedOperationException
();
}
@Override
public
void
setMediaItem
(
MediaSource
mediaItem
,
long
startPositionMs
)
{
throw
new
UnsupportedOperationException
();
}
@Override
public
void
setPlayWhenReady
(
boolean
playWhenReady
)
{
public
void
setPlayWhenReady
(
boolean
playWhenReady
)
{
throw
new
UnsupportedOperationException
();
throw
new
UnsupportedOperationException
();
}
}
...
...
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