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
6dd065a1
authored
May 30, 2022
by
ibaker
Committed by
Marc Baechinger
May 30, 2022
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Wrap framework AudioAttributes in new AudioAttributesV21 class
PiperOrigin-RevId: 451831531
parent
38720a6b
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
23 deletions
library/common/src/main/java/com/google/android/exoplayer2/audio/AudioAttributes.java
library/core/src/main/java/com/google/android/exoplayer2/AudioFocusManager.java
library/core/src/main/java/com/google/android/exoplayer2/audio/DefaultAudioSink.java
library/common/src/main/java/com/google/android/exoplayer2/audio/AudioAttributes.java
View file @
6dd065a1
...
@@ -43,6 +43,27 @@ import java.lang.annotation.Target;
...
@@ -43,6 +43,27 @@ import java.lang.annotation.Target;
*/
*/
public
final
class
AudioAttributes
implements
Bundleable
{
public
final
class
AudioAttributes
implements
Bundleable
{
/** A direct wrapper around {@link android.media.AudioAttributes}. */
@RequiresApi
(
21
)
public
static
final
class
AudioAttributesV21
{
public
final
android
.
media
.
AudioAttributes
audioAttributes
;
private
AudioAttributesV21
(
AudioAttributes
audioAttributes
)
{
android
.
media
.
AudioAttributes
.
Builder
builder
=
new
android
.
media
.
AudioAttributes
.
Builder
()
.
setContentType
(
audioAttributes
.
contentType
)
.
setFlags
(
audioAttributes
.
flags
)
.
setUsage
(
audioAttributes
.
usage
);
if
(
Util
.
SDK_INT
>=
29
)
{
Api29
.
setAllowedCapturePolicy
(
builder
,
audioAttributes
.
allowedCapturePolicy
);
}
if
(
Util
.
SDK_INT
>=
32
)
{
Api32
.
setSpatializationBehavior
(
builder
,
audioAttributes
.
spatializationBehavior
);
}
this
.
audioAttributes
=
builder
.
build
();
}
}
/**
/**
* The default audio attributes, where the content type is {@link C#AUDIO_CONTENT_TYPE_UNKNOWN},
* The default audio attributes, where the content type is {@link C#AUDIO_CONTENT_TYPE_UNKNOWN},
* usage is {@link C#USAGE_MEDIA}, capture policy is {@link C#ALLOW_CAPTURE_BY_ALL} and no flags
* usage is {@link C#USAGE_MEDIA}, capture policy is {@link C#ALLOW_CAPTURE_BY_ALL} and no flags
...
@@ -121,7 +142,7 @@ public final class AudioAttributes implements Bundleable {
...
@@ -121,7 +142,7 @@ public final class AudioAttributes implements Bundleable {
/** The {@link C.SpatializationBehavior}. */
/** The {@link C.SpatializationBehavior}. */
public
final
@C
.
SpatializationBehavior
int
spatializationBehavior
;
public
final
@C
.
SpatializationBehavior
int
spatializationBehavior
;
@Nullable
private
android
.
media
.
AudioAttributes
audioAttributesV21
;
@Nullable
private
AudioAttributesV21
audioAttributesV21
;
private
AudioAttributes
(
private
AudioAttributes
(
@C
.
AudioContentType
int
contentType
,
@C
.
AudioContentType
int
contentType
,
...
@@ -137,25 +158,15 @@ public final class AudioAttributes implements Bundleable {
...
@@ -137,25 +158,15 @@ public final class AudioAttributes implements Bundleable {
}
}
/**
/**
* Returns a {@link
android.media.AudioAttributes
} from this instance.
* Returns a {@link
AudioAttributesV21
} from this instance.
*
*
* <p>Field {@link AudioAttributes#allowedCapturePolicy} is ignored for API levels prior to 29.
* <p>Some fields are ignored if the corresponding {@link android.media.AudioAttributes.Builder}
* setter is not available on the current API level.
*/
*/
@RequiresApi
(
21
)
@RequiresApi
(
21
)
public
android
.
media
.
AudioAttributes
getAudioAttributesV21
()
{
public
AudioAttributesV21
getAudioAttributesV21
()
{
if
(
audioAttributesV21
==
null
)
{
if
(
audioAttributesV21
==
null
)
{
android
.
media
.
AudioAttributes
.
Builder
builder
=
audioAttributesV21
=
new
AudioAttributesV21
(
this
);
new
android
.
media
.
AudioAttributes
.
Builder
()
.
setContentType
(
contentType
)
.
setFlags
(
flags
)
.
setUsage
(
usage
);
if
(
Util
.
SDK_INT
>=
29
)
{
Api29
.
setAllowedCapturePolicy
(
builder
,
allowedCapturePolicy
);
}
if
(
Util
.
SDK_INT
>=
32
)
{
Api32
.
setSpatializationBehavior
(
builder
,
spatializationBehavior
);
}
audioAttributesV21
=
builder
.
build
();
}
}
return
audioAttributesV21
;
return
audioAttributesV21
;
}
}
...
@@ -247,8 +258,6 @@ public final class AudioAttributes implements Bundleable {
...
@@ -247,8 +258,6 @@ public final class AudioAttributes implements Bundleable {
@RequiresApi
(
29
)
@RequiresApi
(
29
)
private
static
final
class
Api29
{
private
static
final
class
Api29
{
private
Api29
()
{}
@DoNotInline
@DoNotInline
public
static
void
setAllowedCapturePolicy
(
public
static
void
setAllowedCapturePolicy
(
android
.
media
.
AudioAttributes
.
Builder
builder
,
android
.
media
.
AudioAttributes
.
Builder
builder
,
...
@@ -259,8 +268,6 @@ public final class AudioAttributes implements Bundleable {
...
@@ -259,8 +268,6 @@ public final class AudioAttributes implements Bundleable {
@RequiresApi
(
32
)
@RequiresApi
(
32
)
private
static
final
class
Api32
{
private
static
final
class
Api32
{
private
Api32
()
{}
@DoNotInline
@DoNotInline
public
static
void
setSpatializationBehavior
(
public
static
void
setSpatializationBehavior
(
android
.
media
.
AudioAttributes
.
Builder
builder
,
android
.
media
.
AudioAttributes
.
Builder
builder
,
...
...
library/core/src/main/java/com/google/android/exoplayer2/AudioFocusManager.java
View file @
6dd065a1
...
@@ -274,7 +274,8 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
...
@@ -274,7 +274,8 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
boolean
willPauseWhenDucked
=
willPauseWhenDucked
();
boolean
willPauseWhenDucked
=
willPauseWhenDucked
();
audioFocusRequest
=
audioFocusRequest
=
builder
builder
.
setAudioAttributes
(
checkNotNull
(
audioAttributes
).
getAudioAttributesV21
())
.
setAudioAttributes
(
checkNotNull
(
audioAttributes
).
getAudioAttributesV21
().
audioAttributes
)
.
setWillPauseWhenDucked
(
willPauseWhenDucked
)
.
setWillPauseWhenDucked
(
willPauseWhenDucked
)
.
setOnAudioFocusChangeListener
(
focusListener
)
.
setOnAudioFocusChangeListener
(
focusListener
)
.
build
();
.
build
();
...
...
library/core/src/main/java/com/google/android/exoplayer2/audio/DefaultAudioSink.java
View file @
6dd065a1
...
@@ -1827,7 +1827,8 @@ public final class DefaultAudioSink implements AudioSink {
...
@@ -1827,7 +1827,8 @@ public final class DefaultAudioSink implements AudioSink {
}
}
AudioFormat
audioFormat
=
getAudioFormat
(
format
.
sampleRate
,
channelConfig
,
encoding
);
AudioFormat
audioFormat
=
getAudioFormat
(
format
.
sampleRate
,
channelConfig
,
encoding
);
switch
(
getOffloadedPlaybackSupport
(
audioFormat
,
audioAttributes
.
getAudioAttributesV21
()))
{
switch
(
getOffloadedPlaybackSupport
(
audioFormat
,
audioAttributes
.
getAudioAttributesV21
().
audioAttributes
))
{
case
AudioManager
.
PLAYBACK_OFFLOAD_NOT_SUPPORTED
:
case
AudioManager
.
PLAYBACK_OFFLOAD_NOT_SUPPORTED
:
return
false
;
return
false
;
case
AudioManager
.
PLAYBACK_OFFLOAD_SUPPORTED
:
case
AudioManager
.
PLAYBACK_OFFLOAD_SUPPORTED
:
...
@@ -2301,7 +2302,7 @@ public final class DefaultAudioSink implements AudioSink {
...
@@ -2301,7 +2302,7 @@ public final class DefaultAudioSink implements AudioSink {
if
(
tunneling
)
{
if
(
tunneling
)
{
return
getAudioTrackTunnelingAttributesV21
();
return
getAudioTrackTunnelingAttributesV21
();
}
else
{
}
else
{
return
audioAttributes
.
getAudioAttributesV21
();
return
audioAttributes
.
getAudioAttributesV21
()
.
audioAttributes
;
}
}
}
}
...
...
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