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
aea9f8e5
authored
Apr 17, 2020
by
bachinger
Committed by
Oliver Woodman
May 27, 2020
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Merge pull request #7245 from Clement-Jean:silence-media-source-factory
PiperOrigin-RevId: 307010600
parent
4dc1d317
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
1 deletions
RELEASENOTES.md
library/core/src/main/java/com/google/android/exoplayer2/source/SilenceMediaSource.java
RELEASENOTES.md
View file @
aea9f8e5
...
@@ -2,6 +2,8 @@
...
@@ -2,6 +2,8 @@
### Next release ###
### Next release ###
*
Add
`SilenceMediaSource.Factory`
to support tags
(
[
PR #7245
](
https://github.com/google/ExoPlayer/pull/7245
)
).
*
Avoid throwing an exception while parsing fragmented MP4 default sample
*
Avoid throwing an exception while parsing fragmented MP4 default sample
values where the most-significant bit is set
values where the most-significant bit is set
(
[
#7207
](
https://github.com/google/ExoPlayer/issues/7207
)
).
(
[
#7207
](
https://github.com/google/ExoPlayer/issues/7207
)
).
...
...
library/core/src/main/java/com/google/android/exoplayer2/source/SilenceMediaSource.java
View file @
aea9f8e5
...
@@ -33,6 +33,42 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
...
@@ -33,6 +33,42 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
/** Media source with a single period consisting of silent raw audio of a given duration. */
/** Media source with a single period consisting of silent raw audio of a given duration. */
public
final
class
SilenceMediaSource
extends
BaseMediaSource
{
public
final
class
SilenceMediaSource
extends
BaseMediaSource
{
/** Factory for {@link SilenceMediaSource SilenceMediaSources}. */
public
static
final
class
Factory
{
private
long
durationUs
;
@Nullable
private
Object
tag
;
/**
* Sets the duration of the silent audio.
*
* @param durationUs The duration of silent audio to output, in microseconds.
* @return This factory, for convenience.
*/
public
Factory
setDurationUs
(
long
durationUs
)
{
this
.
durationUs
=
durationUs
;
return
this
;
}
/**
* Sets a tag for the media source which will be published in the {@link
* com.google.android.exoplayer2.Timeline} of the source as {@link
* com.google.android.exoplayer2.Timeline.Window#tag}.
*
* @param tag A tag for the media source.
* @return This factory, for convenience.
*/
public
Factory
setTag
(
@Nullable
Object
tag
)
{
this
.
tag
=
tag
;
return
this
;
}
/** Creates a new {@link SilenceMediaSource}. */
public
SilenceMediaSource
createMediaSource
()
{
return
new
SilenceMediaSource
(
durationUs
,
tag
);
}
}
private
static
final
int
SAMPLE_RATE_HZ
=
44100
;
private
static
final
int
SAMPLE_RATE_HZ
=
44100
;
@C
.
PcmEncoding
private
static
final
int
ENCODING
=
C
.
ENCODING_PCM_16BIT
;
@C
.
PcmEncoding
private
static
final
int
ENCODING
=
C
.
ENCODING_PCM_16BIT
;
private
static
final
int
CHANNEL_COUNT
=
2
;
private
static
final
int
CHANNEL_COUNT
=
2
;
...
@@ -54,6 +90,7 @@ public final class SilenceMediaSource extends BaseMediaSource {
...
@@ -54,6 +90,7 @@ public final class SilenceMediaSource extends BaseMediaSource {
new
byte
[
Util
.
getPcmFrameSize
(
ENCODING
,
CHANNEL_COUNT
)
*
1024
];
new
byte
[
Util
.
getPcmFrameSize
(
ENCODING
,
CHANNEL_COUNT
)
*
1024
];
private
final
long
durationUs
;
private
final
long
durationUs
;
@Nullable
private
final
Object
tag
;
/**
/**
* Creates a new media source providing silent audio of the given duration.
* Creates a new media source providing silent audio of the given duration.
...
@@ -61,15 +98,25 @@ public final class SilenceMediaSource extends BaseMediaSource {
...
@@ -61,15 +98,25 @@ public final class SilenceMediaSource extends BaseMediaSource {
* @param durationUs The duration of silent audio to output, in microseconds.
* @param durationUs The duration of silent audio to output, in microseconds.
*/
*/
public
SilenceMediaSource
(
long
durationUs
)
{
public
SilenceMediaSource
(
long
durationUs
)
{
this
(
durationUs
,
/* tag= */
null
);
}
private
SilenceMediaSource
(
long
durationUs
,
@Nullable
Object
tag
)
{
Assertions
.
checkArgument
(
durationUs
>=
0
);
Assertions
.
checkArgument
(
durationUs
>=
0
);
this
.
durationUs
=
durationUs
;
this
.
durationUs
=
durationUs
;
this
.
tag
=
tag
;
}
}
@Override
@Override
protected
void
prepareSourceInternal
(
@Nullable
TransferListener
mediaTransferListener
)
{
protected
void
prepareSourceInternal
(
@Nullable
TransferListener
mediaTransferListener
)
{
refreshSourceInfo
(
refreshSourceInfo
(
new
SinglePeriodTimeline
(
new
SinglePeriodTimeline
(
durationUs
,
/* isSeekable= */
true
,
/* isDynamic= */
false
,
/* isLive= */
false
));
durationUs
,
/* isSeekable= */
true
,
/* isDynamic= */
false
,
/* isLive= */
false
,
/* manifest= */
null
,
tag
));
}
}
@Override
@Override
...
...
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