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
90113ce0
authored
Jul 22, 2021
by
kimvde
Committed by
kim-vde
Jul 22, 2021
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Deprecate ControlDispatcher in media2
PiperOrigin-RevId: 386185285
parent
b69c06a5
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
84 additions
and
17 deletions
RELEASENOTES.md
extensions/media2/src/androidTest/java/com/google/android/exoplayer2/ext/media2/SessionPlayerConnectorTest.java
extensions/media2/src/main/java/com/google/android/exoplayer2/ext/media2/PlayerWrapper.java
extensions/media2/src/main/java/com/google/android/exoplayer2/ext/media2/SessionPlayerConnector.java
RELEASENOTES.md
View file @
90113ce0
...
@@ -111,8 +111,10 @@
...
@@ -111,8 +111,10 @@
*
Cronet extension:
*
Cronet extension:
*
Add
`CronetDataSource.Factory.setRequestPriority`
to allow setting the
*
Add
`CronetDataSource.Factory.setRequestPriority`
to allow setting the
priority of requests made by
`CronetDataSource`
instances.
priority of requests made by
`CronetDataSource`
instances.
*
Leanback:
*
Leanback
extension
:
*
Deprecate
`setControlDispatcher`
in
`LeanbackPlayerAdapter`
.
*
Deprecate
`setControlDispatcher`
in
`LeanbackPlayerAdapter`
.
*
Media2 extension:
*
Deprecate
`setControlDispatcher`
in
`SessionPlayerConnector`
.
### 2.14.2 (2021-07-20)
### 2.14.2 (2021-07-20)
...
...
extensions/media2/src/androidTest/java/com/google/android/exoplayer2/ext/media2/SessionPlayerConnectorTest.java
View file @
90113ce0
...
@@ -44,6 +44,7 @@ import androidx.test.filters.SmallTest;
...
@@ -44,6 +44,7 @@ import androidx.test.filters.SmallTest;
import
androidx.test.platform.app.InstrumentationRegistry
;
import
androidx.test.platform.app.InstrumentationRegistry
;
import
com.google.android.exoplayer2.ControlDispatcher
;
import
com.google.android.exoplayer2.ControlDispatcher
;
import
com.google.android.exoplayer2.DefaultControlDispatcher
;
import
com.google.android.exoplayer2.DefaultControlDispatcher
;
import
com.google.android.exoplayer2.ForwardingPlayer
;
import
com.google.android.exoplayer2.Player
;
import
com.google.android.exoplayer2.Player
;
import
com.google.android.exoplayer2.SimpleExoPlayer
;
import
com.google.android.exoplayer2.SimpleExoPlayer
;
import
com.google.android.exoplayer2.ext.media2.test.R
;
import
com.google.android.exoplayer2.ext.media2.test.R
;
...
@@ -185,6 +186,45 @@ public class SessionPlayerConnectorTest {
...
@@ -185,6 +186,45 @@ public class SessionPlayerConnectorTest {
@Test
@Test
@LargeTest
@LargeTest
public
void
play_withForwardingPlayer_isSkipped
()
throws
Exception
{
if
(
Looper
.
myLooper
()
==
null
)
{
Looper
.
prepare
();
}
Player
forwardingPlayer
=
null
;
SessionPlayerConnector
playerConnector
=
null
;
try
{
Player
simpleExoPlayer
=
new
SimpleExoPlayer
.
Builder
(
context
).
setLooper
(
Looper
.
myLooper
()).
build
();
forwardingPlayer
=
new
ForwardingPlayer
(
simpleExoPlayer
)
{
@Override
public
boolean
isCommandAvailable
(
int
command
)
{
if
(
command
==
COMMAND_PLAY_PAUSE
)
{
return
false
;
}
return
super
.
isCommandAvailable
(
command
);
}
@Override
public
Commands
getAvailableCommands
()
{
return
super
.
getAvailableCommands
().
buildUpon
().
remove
(
COMMAND_PLAY_PAUSE
).
build
();
}
};
playerConnector
=
new
SessionPlayerConnector
(
forwardingPlayer
);
assertPlayerResult
(
playerConnector
.
play
(),
RESULT_INFO_SKIPPED
);
}
finally
{
if
(
playerConnector
!=
null
)
{
playerConnector
.
close
();
}
if
(
forwardingPlayer
!=
null
)
{
forwardingPlayer
.
release
();
}
}
}
@Test
@LargeTest
public
void
setMediaItem_withAudioResource_notifiesOnPlaybackCompleted
()
throws
Exception
{
public
void
setMediaItem_withAudioResource_notifiesOnPlaybackCompleted
()
throws
Exception
{
TestUtils
.
loadResource
(
R
.
raw
.
audio
,
sessionPlayerConnector
);
TestUtils
.
loadResource
(
R
.
raw
.
audio
,
sessionPlayerConnector
);
...
...
extensions/media2/src/main/java/com/google/android/exoplayer2/ext/media2/PlayerWrapper.java
View file @
90113ce0
...
@@ -15,6 +15,14 @@
...
@@ -15,6 +15,14 @@
*/
*/
package
com
.
google
.
android
.
exoplayer2
.
ext
.
media2
;
package
com
.
google
.
android
.
exoplayer2
.
ext
.
media2
;
import
static
com
.
google
.
android
.
exoplayer2
.
Player
.
COMMAND_GET_AUDIO_ATTRIBUTES
;
import
static
com
.
google
.
android
.
exoplayer2
.
Player
.
COMMAND_PLAY_PAUSE
;
import
static
com
.
google
.
android
.
exoplayer2
.
Player
.
COMMAND_SEEK_IN_CURRENT_WINDOW
;
import
static
com
.
google
.
android
.
exoplayer2
.
Player
.
COMMAND_SEEK_TO_NEXT
;
import
static
com
.
google
.
android
.
exoplayer2
.
Player
.
COMMAND_SEEK_TO_PREVIOUS
;
import
static
com
.
google
.
android
.
exoplayer2
.
Player
.
COMMAND_SEEK_TO_WINDOW
;
import
static
com
.
google
.
android
.
exoplayer2
.
Player
.
COMMAND_SET_REPEAT_MODE
;
import
static
com
.
google
.
android
.
exoplayer2
.
Player
.
COMMAND_SET_SHUFFLE_MODE
;
import
static
com
.
google
.
android
.
exoplayer2
.
util
.
Util
.
postOrRun
;
import
static
com
.
google
.
android
.
exoplayer2
.
util
.
Util
.
postOrRun
;
import
android.os.Handler
;
import
android.os.Handler
;
...
@@ -27,6 +35,7 @@ import androidx.media2.common.SessionPlayer;
...
@@ -27,6 +35,7 @@ import androidx.media2.common.SessionPlayer;
import
com.google.android.exoplayer2.C
;
import
com.google.android.exoplayer2.C
;
import
com.google.android.exoplayer2.ControlDispatcher
;
import
com.google.android.exoplayer2.ControlDispatcher
;
import
com.google.android.exoplayer2.DefaultControlDispatcher
;
import
com.google.android.exoplayer2.DefaultControlDispatcher
;
import
com.google.android.exoplayer2.ForwardingPlayer
;
import
com.google.android.exoplayer2.MediaItem
;
import
com.google.android.exoplayer2.MediaItem
;
import
com.google.android.exoplayer2.PlaybackException
;
import
com.google.android.exoplayer2.PlaybackException
;
import
com.google.android.exoplayer2.PlaybackParameters
;
import
com.google.android.exoplayer2.PlaybackParameters
;
...
@@ -154,6 +163,12 @@ import java.util.List;
...
@@ -154,6 +163,12 @@ import java.util.List;
}
}
}
}
/**
* @deprecated Use a {@link ForwardingPlayer} and pass it to the constructor instead. You can also
* customize some operations when configuring the player (for example by using {@code
* SimpleExoPlayer.Builder#setSeekBackIncrementMs(long)}).
*/
@Deprecated
public
void
setControlDispatcher
(
ControlDispatcher
controlDispatcher
)
{
public
void
setControlDispatcher
(
ControlDispatcher
controlDispatcher
)
{
this
.
controlDispatcher
=
controlDispatcher
;
this
.
controlDispatcher
=
controlDispatcher
;
}
}
...
@@ -231,11 +246,13 @@ import java.util.List;
...
@@ -231,11 +246,13 @@ import java.util.List;
}
}
public
boolean
skipToPreviousPlaylistItem
()
{
public
boolean
skipToPreviousPlaylistItem
()
{
return
controlDispatcher
.
dispatchPrevious
(
player
);
return
player
.
isCommandAvailable
(
COMMAND_SEEK_TO_PREVIOUS
)
&&
controlDispatcher
.
dispatchPrevious
(
player
);
}
}
public
boolean
skipToNextPlaylistItem
()
{
public
boolean
skipToNextPlaylistItem
()
{
return
controlDispatcher
.
dispatchNext
(
player
);
return
player
.
isCommandAvailable
(
COMMAND_SEEK_TO_NEXT
)
&&
controlDispatcher
.
dispatchNext
(
player
);
}
}
public
boolean
skipToPlaylistItem
(
@IntRange
(
from
=
0
)
int
index
)
{
public
boolean
skipToPlaylistItem
(
@IntRange
(
from
=
0
)
int
index
)
{
...
@@ -247,7 +264,8 @@ import java.util.List;
...
@@ -247,7 +264,8 @@ import java.util.List;
Assertions
.
checkState
(
0
<=
index
&&
index
<
timeline
.
getWindowCount
());
Assertions
.
checkState
(
0
<=
index
&&
index
<
timeline
.
getWindowCount
());
int
windowIndex
=
player
.
getCurrentWindowIndex
();
int
windowIndex
=
player
.
getCurrentWindowIndex
();
if
(
windowIndex
!=
index
)
{
if
(
windowIndex
!=
index
)
{
return
controlDispatcher
.
dispatchSeekTo
(
player
,
index
,
C
.
TIME_UNSET
);
return
player
.
isCommandAvailable
(
COMMAND_SEEK_TO_WINDOW
)
&&
controlDispatcher
.
dispatchSeekTo
(
player
,
index
,
C
.
TIME_UNSET
);
}
}
return
false
;
return
false
;
}
}
...
@@ -258,12 +276,14 @@ import java.util.List;
...
@@ -258,12 +276,14 @@ import java.util.List;
}
}
public
boolean
setRepeatMode
(
int
repeatMode
)
{
public
boolean
setRepeatMode
(
int
repeatMode
)
{
return
controlDispatcher
.
dispatchSetRepeatMode
(
return
player
.
isCommandAvailable
(
COMMAND_SET_REPEAT_MODE
)
&&
controlDispatcher
.
dispatchSetRepeatMode
(
player
,
Utils
.
getExoPlayerRepeatMode
(
repeatMode
));
player
,
Utils
.
getExoPlayerRepeatMode
(
repeatMode
));
}
}
public
boolean
setShuffleMode
(
int
shuffleMode
)
{
public
boolean
setShuffleMode
(
int
shuffleMode
)
{
return
controlDispatcher
.
dispatchSetShuffleModeEnabled
(
return
player
.
isCommandAvailable
(
COMMAND_SET_SHUFFLE_MODE
)
&&
controlDispatcher
.
dispatchSetShuffleModeEnabled
(
player
,
Utils
.
getExoPlayerShuffleMode
(
shuffleMode
));
player
,
Utils
.
getExoPlayerShuffleMode
(
shuffleMode
));
}
}
...
@@ -314,7 +334,8 @@ import java.util.List;
...
@@ -314,7 +334,8 @@ import java.util.List;
public
boolean
play
()
{
public
boolean
play
()
{
if
(
player
.
getPlaybackState
()
==
Player
.
STATE_ENDED
)
{
if
(
player
.
getPlaybackState
()
==
Player
.
STATE_ENDED
)
{
boolean
seekHandled
=
boolean
seekHandled
=
controlDispatcher
.
dispatchSeekTo
(
player
.
isCommandAvailable
(
COMMAND_SEEK_IN_CURRENT_WINDOW
)
&&
controlDispatcher
.
dispatchSeekTo
(
player
,
player
.
getCurrentWindowIndex
(),
/* positionMs= */
0
);
player
,
player
.
getCurrentWindowIndex
(),
/* positionMs= */
0
);
if
(!
seekHandled
)
{
if
(!
seekHandled
)
{
return
false
;
return
false
;
...
@@ -325,7 +346,8 @@ import java.util.List;
...
@@ -325,7 +346,8 @@ import java.util.List;
if
(
playWhenReady
&&
suppressReason
==
Player
.
PLAYBACK_SUPPRESSION_REASON_NONE
)
{
if
(
playWhenReady
&&
suppressReason
==
Player
.
PLAYBACK_SUPPRESSION_REASON_NONE
)
{
return
false
;
return
false
;
}
}
return
controlDispatcher
.
dispatchSetPlayWhenReady
(
player
,
/* playWhenReady= */
true
);
return
player
.
isCommandAvailable
(
COMMAND_PLAY_PAUSE
)
&&
controlDispatcher
.
dispatchSetPlayWhenReady
(
player
,
/* playWhenReady= */
true
);
}
}
public
boolean
pause
()
{
public
boolean
pause
()
{
...
@@ -334,11 +356,13 @@ import java.util.List;
...
@@ -334,11 +356,13 @@ import java.util.List;
if
(!
playWhenReady
&&
suppressReason
==
Player
.
PLAYBACK_SUPPRESSION_REASON_NONE
)
{
if
(!
playWhenReady
&&
suppressReason
==
Player
.
PLAYBACK_SUPPRESSION_REASON_NONE
)
{
return
false
;
return
false
;
}
}
return
controlDispatcher
.
dispatchSetPlayWhenReady
(
player
,
/* playWhenReady= */
false
);
return
player
.
isCommandAvailable
(
COMMAND_PLAY_PAUSE
)
&&
controlDispatcher
.
dispatchSetPlayWhenReady
(
player
,
/* playWhenReady= */
false
);
}
}
public
boolean
seekTo
(
long
position
)
{
public
boolean
seekTo
(
long
position
)
{
return
controlDispatcher
.
dispatchSeekTo
(
player
,
player
.
getCurrentWindowIndex
(),
position
);
return
player
.
isCommandAvailable
(
COMMAND_SEEK_IN_CURRENT_WINDOW
)
&&
controlDispatcher
.
dispatchSeekTo
(
player
,
player
.
getCurrentWindowIndex
(),
position
);
}
}
public
long
getCurrentPosition
()
{
public
long
getCurrentPosition
()
{
...
@@ -443,7 +467,7 @@ import java.util.List;
...
@@ -443,7 +467,7 @@ import java.util.List;
public
AudioAttributesCompat
getAudioAttributes
()
{
public
AudioAttributesCompat
getAudioAttributes
()
{
AudioAttributes
audioAttributes
=
AudioAttributes
.
DEFAULT
;
AudioAttributes
audioAttributes
=
AudioAttributes
.
DEFAULT
;
if
(
player
.
isCommandAvailable
(
Player
.
COMMAND_GET_AUDIO_ATTRIBUTES
))
{
if
(
player
.
isCommandAvailable
(
COMMAND_GET_AUDIO_ATTRIBUTES
))
{
audioAttributes
=
player
.
getAudioAttributes
();
audioAttributes
=
player
.
getAudioAttributes
();
}
}
return
Utils
.
getAudioAttributesCompat
(
audioAttributes
);
return
Utils
.
getAudioAttributesCompat
(
audioAttributes
);
...
...
extensions/media2/src/main/java/com/google/android/exoplayer2/ext/media2/SessionPlayerConnector.java
View file @
90113ce0
...
@@ -30,8 +30,8 @@ import androidx.media2.common.MediaItem;
...
@@ -30,8 +30,8 @@ import androidx.media2.common.MediaItem;
import
androidx.media2.common.MediaMetadata
;
import
androidx.media2.common.MediaMetadata
;
import
androidx.media2.common.SessionPlayer
;
import
androidx.media2.common.SessionPlayer
;
import
com.google.android.exoplayer2.ControlDispatcher
;
import
com.google.android.exoplayer2.ControlDispatcher
;
import
com.google.android.exoplayer2.DefaultControlDispatcher
;
import
com.google.android.exoplayer2.ExoPlayerLibraryInfo
;
import
com.google.android.exoplayer2.ExoPlayerLibraryInfo
;
import
com.google.android.exoplayer2.ForwardingPlayer
;
import
com.google.android.exoplayer2.Player
;
import
com.google.android.exoplayer2.Player
;
import
com.google.android.exoplayer2.util.Assertions
;
import
com.google.android.exoplayer2.util.Assertions
;
import
com.google.android.exoplayer2.util.Log
;
import
com.google.android.exoplayer2.util.Log
;
...
@@ -87,7 +87,7 @@ public final class SessionPlayerConnector extends SessionPlayer {
...
@@ -87,7 +87,7 @@ public final class SessionPlayerConnector extends SessionPlayer {
/**
/**
* Creates an instance using {@link DefaultMediaItemConverter} to convert between ExoPlayer and
* Creates an instance using {@link DefaultMediaItemConverter} to convert between ExoPlayer and
* media2 MediaItems
and {@link DefaultControlDispatcher} to dispatch player commands
.
* media2 MediaItems.
*
*
* @param player The player to wrap.
* @param player The player to wrap.
*/
*/
...
@@ -96,7 +96,7 @@ public final class SessionPlayerConnector extends SessionPlayer {
...
@@ -96,7 +96,7 @@ public final class SessionPlayerConnector extends SessionPlayer {
}
}
/**
/**
* Creates an instance
using the provided {@link ControlDispatcher} to dispatch player commands
.
* Creates an instance.
*
*
* @param player The player to wrap.
* @param player The player to wrap.
* @param mediaItemConverter The {@link MediaItemConverter}.
* @param mediaItemConverter The {@link MediaItemConverter}.
...
@@ -114,10 +114,11 @@ public final class SessionPlayerConnector extends SessionPlayer {
...
@@ -114,10 +114,11 @@ public final class SessionPlayerConnector extends SessionPlayer {
}
}
/**
/**
*
Sets the {@link ControlDispatcher}.
*
@deprecated Use a {@link ForwardingPlayer} and pass it to the constructor instead. You can also
*
*
customize some operations when configuring the player (for example by using {@code
*
@param controlDispatcher The {@link ControlDispatcher}
.
*
SimpleExoPlayer.Builder#setSeekBackIncrementMs(long)})
.
*/
*/
@Deprecated
public
void
setControlDispatcher
(
ControlDispatcher
controlDispatcher
)
{
public
void
setControlDispatcher
(
ControlDispatcher
controlDispatcher
)
{
player
.
setControlDispatcher
(
controlDispatcher
);
player
.
setControlDispatcher
(
controlDispatcher
);
}
}
...
...
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