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
3e8e3737
authored
Jan 26, 2021
by
gyumin
Committed by
kim-vde
Jan 26, 2021
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Add toBundle/fromBundle to AudioAttributes and DeviceInfo
PiperOrigin-RevId: 353864181
parent
f69e4be4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
131 additions
and
0 deletions
library/common/src/main/java/com/google/android/exoplayer2/audio/AudioAttributes.java
library/common/src/main/java/com/google/android/exoplayer2/device/DeviceInfo.java
library/common/src/test/java/com/google/android/exoplayer2/audio/AudioAttributesTest.java
library/common/src/test/java/com/google/android/exoplayer2/device/DeviceInfoTest.java
library/common/src/main/java/com/google/android/exoplayer2/audio/AudioAttributes.java
View file @
3e8e3737
...
...
@@ -15,6 +15,7 @@
*/
package
com
.
google
.
android
.
exoplayer2
.
audio
;
import
android.os.Bundle
;
import
androidx.annotation.Nullable
;
import
androidx.annotation.RequiresApi
;
import
com.google.android.exoplayer2.C
;
...
...
@@ -33,6 +34,11 @@ import com.google.android.exoplayer2.util.Util;
*/
public
final
class
AudioAttributes
{
private
static
final
String
FIELD_CONTENT_TYPE
=
"contentType"
;
private
static
final
String
FIELD_FLAGS
=
"flags"
;
private
static
final
String
FIELD_USAGE
=
"usage"
;
private
static
final
String
FIELD_ALLOWED_CAPTURE_POLICY
=
"allowedCapturePolicy"
;
public
static
final
AudioAttributes
DEFAULT
=
new
Builder
().
build
();
/**
...
...
@@ -159,4 +165,31 @@ public final class AudioAttributes {
return
result
;
}
/** Converts this instance into a {@link Bundle}. */
public
Bundle
toBundle
()
{
Bundle
bundle
=
new
Bundle
();
bundle
.
putInt
(
FIELD_CONTENT_TYPE
,
contentType
);
bundle
.
putInt
(
FIELD_FLAGS
,
flags
);
bundle
.
putInt
(
FIELD_USAGE
,
usage
);
bundle
.
putInt
(
FIELD_ALLOWED_CAPTURE_POLICY
,
allowedCapturePolicy
);
return
bundle
;
}
/** Creates an {@link AudioAttributes} instance from a {@link Bundle}. */
public
static
AudioAttributes
fromBundle
(
Bundle
bundle
)
{
Builder
builder
=
new
Builder
();
if
(
bundle
.
containsKey
(
FIELD_CONTENT_TYPE
))
{
builder
.
setContentType
(
bundle
.
getInt
(
FIELD_CONTENT_TYPE
));
}
if
(
bundle
.
containsKey
(
FIELD_FLAGS
))
{
builder
.
setFlags
(
bundle
.
getInt
(
FIELD_FLAGS
));
}
if
(
bundle
.
containsKey
(
FIELD_USAGE
))
{
builder
.
setUsage
(
bundle
.
getInt
(
FIELD_USAGE
));
}
if
(
bundle
.
containsKey
(
FIELD_ALLOWED_CAPTURE_POLICY
))
{
builder
.
setAllowedCapturePolicy
(
bundle
.
getInt
(
FIELD_ALLOWED_CAPTURE_POLICY
));
}
return
builder
.
build
();
}
}
library/common/src/main/java/com/google/android/exoplayer2/device/DeviceInfo.java
View file @
3e8e3737
...
...
@@ -15,6 +15,7 @@
*/
package
com
.
google
.
android
.
exoplayer2
.
device
;
import
android.os.Bundle
;
import
androidx.annotation.IntDef
;
import
androidx.annotation.Nullable
;
import
java.lang.annotation.Documented
;
...
...
@@ -26,6 +27,10 @@ import java.lang.annotation.Target;
/** Information about the playback device. */
public
final
class
DeviceInfo
{
private
static
final
String
FIELD_PLAYBACK_TYPE
=
"playbackType"
;
private
static
final
String
FIELD_MIN_VOLUME
=
"minVolume"
;
private
static
final
String
FIELD_MAX_VOLUME
=
"maxVolume"
;
/** Types of playback. One of {@link #PLAYBACK_TYPE_LOCAL} or {@link #PLAYBACK_TYPE_REMOTE}. */
@Documented
@Retention
(
RetentionPolicy
.
SOURCE
)
...
...
@@ -80,4 +85,21 @@ public final class DeviceInfo {
result
=
31
*
result
+
maxVolume
;
return
result
;
}
/** Converts this instance into a {@link Bundle}. */
public
Bundle
toBundle
()
{
Bundle
bundle
=
new
Bundle
();
bundle
.
putInt
(
FIELD_PLAYBACK_TYPE
,
playbackType
);
bundle
.
putInt
(
FIELD_MIN_VOLUME
,
minVolume
);
bundle
.
putInt
(
FIELD_MAX_VOLUME
,
maxVolume
);
return
bundle
;
}
/** Creates an {@link DeviceInfo} instance from a {@link Bundle}. */
public
static
DeviceInfo
fromBundle
(
Bundle
bundle
)
{
int
playbackType
=
bundle
.
getInt
(
FIELD_PLAYBACK_TYPE
,
/* defaultValue= */
PLAYBACK_TYPE_LOCAL
);
int
minVolume
=
bundle
.
getInt
(
FIELD_MIN_VOLUME
,
/* defaultValue= */
0
);
int
maxVolume
=
bundle
.
getInt
(
FIELD_MAX_VOLUME
,
/* defaultValue= */
0
);
return
new
DeviceInfo
(
playbackType
,
minVolume
,
maxVolume
);
}
}
library/common/src/test/java/com/google/android/exoplayer2/audio/AudioAttributesTest.java
0 → 100644
View file @
3e8e3737
/*
* Copyright 2021 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
com
.
google
.
android
.
exoplayer2
.
audio
;
import
static
com
.
google
.
common
.
truth
.
Truth
.
assertThat
;
import
androidx.test.ext.junit.runners.AndroidJUnit4
;
import
com.google.android.exoplayer2.C
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
/** Unit tests for {@link AudioAttributes}. */
@RunWith
(
AndroidJUnit4
.
class
)
public
class
AudioAttributesTest
{
@Test
public
void
roundtripViaBundle_yieldsEqualInstance
()
{
AudioAttributes
audioAttributes
=
new
AudioAttributes
.
Builder
()
.
setContentType
(
C
.
CONTENT_TYPE_SONIFICATION
)
.
setFlags
(
C
.
FLAG_AUDIBILITY_ENFORCED
)
.
setUsage
(
C
.
USAGE_ALARM
)
.
setAllowedCapturePolicy
(
C
.
ALLOW_CAPTURE_BY_SYSTEM
)
.
build
();
assertThat
(
AudioAttributes
.
fromBundle
(
audioAttributes
.
toBundle
())).
isEqualTo
(
audioAttributes
);
}
}
library/common/src/test/java/com/google/android/exoplayer2/device/DeviceInfoTest.java
0 → 100644
View file @
3e8e3737
/*
* Copyright 2021 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
com
.
google
.
android
.
exoplayer2
.
device
;
import
static
com
.
google
.
common
.
truth
.
Truth
.
assertThat
;
import
androidx.test.ext.junit.runners.AndroidJUnit4
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
/** Unit tests for {@link DeviceInfo}. */
@RunWith
(
AndroidJUnit4
.
class
)
public
class
DeviceInfoTest
{
@Test
public
void
roundtripViaBundle_yieldsEqualInstance
()
{
DeviceInfo
deviceInfo
=
new
DeviceInfo
(
DeviceInfo
.
PLAYBACK_TYPE_REMOTE
,
/* minVolume= */
1
,
/* maxVolume= */
9
);
assertThat
(
DeviceInfo
.
fromBundle
(
deviceInfo
.
toBundle
())).
isEqualTo
(
deviceInfo
);
}
}
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