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
7fad836b
authored
Mar 04, 2021
by
jaewan
Committed by
Ian Baker
Mar 12, 2021
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Implement Bundleable for PlaybackParameters
PiperOrigin-RevId: 360810865
parent
01cb6ee3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
72 additions
and
1 deletions
library/common/src/main/java/com/google/android/exoplayer2/PlaybackParameters.java
library/common/src/test/java/com/google/android/exoplayer2/PlaybackParametersTest.java
library/common/src/main/java/com/google/android/exoplayer2/PlaybackParameters.java
View file @
7fad836b
...
@@ -15,13 +15,18 @@
...
@@ -15,13 +15,18 @@
*/
*/
package
com
.
google
.
android
.
exoplayer2
;
package
com
.
google
.
android
.
exoplayer2
;
import
android.os.Bundle
;
import
androidx.annotation.CheckResult
;
import
androidx.annotation.CheckResult
;
import
androidx.annotation.IntDef
;
import
androidx.annotation.Nullable
;
import
androidx.annotation.Nullable
;
import
com.google.android.exoplayer2.util.Assertions
;
import
com.google.android.exoplayer2.util.Assertions
;
import
com.google.android.exoplayer2.util.Util
;
import
com.google.android.exoplayer2.util.Util
;
import
java.lang.annotation.Documented
;
import
java.lang.annotation.Retention
;
import
java.lang.annotation.RetentionPolicy
;
/** Parameters that apply to playback, including speed setting. */
/** Parameters that apply to playback, including speed setting. */
public
final
class
PlaybackParameters
{
public
final
class
PlaybackParameters
implements
Bundleable
{
/** The default playback parameters: real-time playback with no silence skipping. */
/** The default playback parameters: real-time playback with no silence skipping. */
public
static
final
PlaybackParameters
DEFAULT
=
new
PlaybackParameters
(
/* speed= */
1
f
);
public
static
final
PlaybackParameters
DEFAULT
=
new
PlaybackParameters
(
/* speed= */
1
f
);
...
@@ -106,4 +111,34 @@ public final class PlaybackParameters {
...
@@ -106,4 +111,34 @@ public final class PlaybackParameters {
public
String
toString
()
{
public
String
toString
()
{
return
Util
.
formatInvariant
(
"PlaybackParameters(speed=%.2f, pitch=%.2f)"
,
speed
,
pitch
);
return
Util
.
formatInvariant
(
"PlaybackParameters(speed=%.2f, pitch=%.2f)"
,
speed
,
pitch
);
}
}
// Bundleable implementation.
@Documented
@Retention
(
RetentionPolicy
.
SOURCE
)
@IntDef
({
FIELD_SPEED
,
FIELD_PITCH
})
private
@interface
FieldNumber
{}
private
static
final
int
FIELD_SPEED
=
0
;
private
static
final
int
FIELD_PITCH
=
1
;
@Override
public
Bundle
toBundle
()
{
Bundle
bundle
=
new
Bundle
();
bundle
.
putFloat
(
keyForField
(
FIELD_SPEED
),
speed
);
bundle
.
putFloat
(
keyForField
(
FIELD_PITCH
),
pitch
);
return
bundle
;
}
/** Object that can restore {@link PlaybackParameters} from a {@link Bundle}. */
public
static
final
Creator
<
PlaybackParameters
>
CREATOR
=
bundle
->
{
float
speed
=
bundle
.
getFloat
(
keyForField
(
FIELD_SPEED
),
/* defaultValue= */
1
f
);
float
pitch
=
bundle
.
getFloat
(
keyForField
(
FIELD_PITCH
),
/* defaultValue= */
1
f
);
return
new
PlaybackParameters
(
speed
,
pitch
);
};
private
static
String
keyForField
(
@FieldNumber
int
field
)
{
return
Integer
.
toString
(
field
,
Character
.
MAX_RADIX
);
}
}
}
library/common/src/test/java/com/google/android/exoplayer2/PlaybackParametersTest.java
0 → 100644
View file @
7fad836b
/*
* 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
;
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 PlaybackParameters}. */
@RunWith
(
AndroidJUnit4
.
class
)
public
class
PlaybackParametersTest
{
@Test
public
void
roundtripViaBundle_ofPlaybackParameters_yieldsEqualInstance
()
{
PlaybackParameters
playbackParameters
=
new
PlaybackParameters
(
/* speed= */
2.9f
,
/* pitch= */
1.2f
);
assertThat
(
PlaybackParameters
.
CREATOR
.
fromBundle
(
playbackParameters
.
toBundle
()))
.
isEqualTo
(
playbackParameters
);
}
}
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