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
c982f4c4
authored
Mar 06, 2020
by
kimvde
Committed by
Oliver Woodman
Mar 10, 2020
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Add possibility to set the audio session id
Issue: #6975 PiperOrigin-RevId: 299328798
parent
ab21f710
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
42 additions
and
0 deletions
RELEASENOTES.md
library/core/src/main/java/com/google/android/exoplayer2/Player.java
library/core/src/main/java/com/google/android/exoplayer2/Renderer.java
library/core/src/main/java/com/google/android/exoplayer2/SimpleExoPlayer.java
library/core/src/main/java/com/google/android/exoplayer2/audio/MediaCodecAudioRenderer.java
library/core/src/main/java/com/google/android/exoplayer2/audio/SimpleDecoderAudioRenderer.java
RELEASENOTES.md
View file @
c982f4c4
...
@@ -19,6 +19,8 @@
...
@@ -19,6 +19,8 @@
*
Add
`Player.onPlayWhenReadyChanged`
with reasons.
*
Add
`Player.onPlayWhenReadyChanged`
with reasons.
*
Add
`Player.onPlaybackStateChanged`
and deprecate
*
Add
`Player.onPlaybackStateChanged`
and deprecate
`Player.onPlayerStateChanged`
.
`Player.onPlayerStateChanged`
.
*
Add
`Player.setAudioSessionId`
to set the session ID attached to the
`AudioTrack`
.
*
Deprecate and rename
`getPlaybackError`
to
`getPlayerError`
for
*
Deprecate and rename
`getPlaybackError`
to
`getPlayerError`
for
consistency.
consistency.
*
Deprecate and rename
`onLoadingChanged`
to
`onIsLoadingChanged`
for
*
Deprecate and rename
`onLoadingChanged`
to
`onIsLoadingChanged`
for
...
...
library/core/src/main/java/com/google/android/exoplayer2/Player.java
View file @
c982f4c4
...
@@ -15,6 +15,7 @@
...
@@ -15,6 +15,7 @@
*/
*/
package
com
.
google
.
android
.
exoplayer2
;
package
com
.
google
.
android
.
exoplayer2
;
import
android.content.Context
;
import
android.os.Looper
;
import
android.os.Looper
;
import
android.view.Surface
;
import
android.view.Surface
;
import
android.view.SurfaceHolder
;
import
android.view.SurfaceHolder
;
...
@@ -123,6 +124,18 @@ public interface Player {
...
@@ -123,6 +124,18 @@ public interface Player {
/** Returns the attributes for audio playback. */
/** Returns the attributes for audio playback. */
AudioAttributes
getAudioAttributes
();
AudioAttributes
getAudioAttributes
();
/**
* Sets the ID of the audio session to attach to the underlying {@link
* android.media.AudioTrack}.
*
* <p>The audio session ID can be generated using {@link C#generateAudioSessionIdV21(Context)}
* for API 21+.
*
* @param audioSessionId The audio session ID, or {@link C#AUDIO_SESSION_ID_UNSET} if it should
* be generated by the framework.
*/
void
setAudioSessionId
(
int
audioSessionId
);
/** Returns the audio session identifier, or {@link C#AUDIO_SESSION_ID_UNSET} if not set. */
/** Returns the audio session identifier, or {@link C#AUDIO_SESSION_ID_UNSET} if not set. */
int
getAudioSessionId
();
int
getAudioSessionId
();
...
...
library/core/src/main/java/com/google/android/exoplayer2/Renderer.java
View file @
c982f4c4
...
@@ -132,6 +132,12 @@ public interface Renderer extends PlayerMessage.Target {
...
@@ -132,6 +132,12 @@ public interface Renderer extends PlayerMessage.Target {
*/
*/
int
MSG_SET_SKIP_SILENCE_ENABLED
=
101
;
int
MSG_SET_SKIP_SILENCE_ENABLED
=
101
;
/**
/**
* A type of a message that can be passed to an audio renderer via {@link
* ExoPlayer#createMessage(Target)}. The message payload should be an {@link Integer} instance
* representing the audio session ID that will be attached to the underlying audio track.
*/
int
MSG_SET_AUDIO_SESSION_ID
=
102
;
/**
* Applications or extensions may define custom {@code MSG_*} constants that can be passed to
* Applications or extensions may define custom {@code MSG_*} constants that can be passed to
* renderers. These custom constants must be greater than or equal to this value.
* renderers. These custom constants must be greater than or equal to this value.
*/
*/
...
...
library/core/src/main/java/com/google/android/exoplayer2/SimpleExoPlayer.java
View file @
c982f4c4
...
@@ -673,6 +673,21 @@ public class SimpleExoPlayer extends BasePlayer
...
@@ -673,6 +673,21 @@ public class SimpleExoPlayer extends BasePlayer
}
}
@Override
@Override
public
void
setAudioSessionId
(
int
audioSessionId
)
{
verifyApplicationThread
();
this
.
audioSessionId
=
audioSessionId
;
for
(
Renderer
renderer
:
renderers
)
{
if
(
renderer
.
getTrackType
()
==
C
.
TRACK_TYPE_AUDIO
)
{
player
.
createMessage
(
renderer
)
.
setType
(
Renderer
.
MSG_SET_AUDIO_SESSION_ID
)
.
setPayload
(
audioSessionId
)
.
send
();
}
}
}
@Override
public
int
getAudioSessionId
()
{
public
int
getAudioSessionId
()
{
return
audioSessionId
;
return
audioSessionId
;
}
}
...
...
library/core/src/main/java/com/google/android/exoplayer2/audio/MediaCodecAudioRenderer.java
View file @
c982f4c4
...
@@ -673,6 +673,9 @@ public class MediaCodecAudioRenderer extends MediaCodecRenderer implements Media
...
@@ -673,6 +673,9 @@ public class MediaCodecAudioRenderer extends MediaCodecRenderer implements Media
case
MSG_SET_SKIP_SILENCE_ENABLED:
case
MSG_SET_SKIP_SILENCE_ENABLED:
audioSink
.
setSkipSilenceEnabled
((
Boolean
)
message
);
audioSink
.
setSkipSilenceEnabled
((
Boolean
)
message
);
break
;
break
;
case
MSG_SET_AUDIO_SESSION_ID:
audioSink
.
setAudioSessionId
((
Integer
)
message
);
break
;
default
:
default
:
super
.
handleMessage
(
messageType
,
message
);
super
.
handleMessage
(
messageType
,
message
);
break
;
break
;
...
...
library/core/src/main/java/com/google/android/exoplayer2/audio/SimpleDecoderAudioRenderer.java
View file @
c982f4c4
...
@@ -564,6 +564,9 @@ public abstract class SimpleDecoderAudioRenderer extends BaseRenderer implements
...
@@ -564,6 +564,9 @@ public abstract class SimpleDecoderAudioRenderer extends BaseRenderer implements
case
MSG_SET_SKIP_SILENCE_ENABLED:
case
MSG_SET_SKIP_SILENCE_ENABLED:
audioSink
.
setSkipSilenceEnabled
((
Boolean
)
message
);
audioSink
.
setSkipSilenceEnabled
((
Boolean
)
message
);
break
;
break
;
case
MSG_SET_AUDIO_SESSION_ID:
audioSink
.
setAudioSessionId
((
Integer
)
message
);
break
;
default
:
default
:
super
.
handleMessage
(
messageType
,
message
);
super
.
handleMessage
(
messageType
,
message
);
break
;
break
;
...
...
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