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
6611ac48
authored
Oct 17, 2020
by
Oliver Woodman
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Add a way to override ad media MIME types
Issue: #7961 PiperOrigin-RevId: 337069152
parent
5cc6dac7
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
85 additions
and
25 deletions
RELEASENOTES.md
extensions/ima/src/main/java/com/google/android/exoplayer2/ext/ima/ImaAdsLoader.java
extensions/ima/src/main/java/com/google/android/exoplayer2/ext/ima/ImaUtil.java
extensions/ima/src/test/java/com/google/android/exoplayer2/ext/ima/ImaAdsLoaderTest.java
RELEASENOTES.md
View file @
6611ac48
...
...
@@ -16,16 +16,15 @@
*
Fix NPE in
`TextRenderer`
when playing content with a single subtitle
buffer (
[
#8017
](
https://github.com/google/ExoPlayer/issues/8017
)
).
*
UI:
*
Do not require subtitleButton in custom layouts of StyledPlayerView
*
Show overflow button in
`StyledPlayerControlView`
only when there is not
enough space.
*
Fix animation when
`StyledPlayerView`
first shows its playback controls.
*
Allow subtitleButton to be omitted in custom
`StyledPlayerView`
layouts
(
[
#7962
](
https://github.com/google/ExoPlayer/issues/7962
)
).
*
Add
the
option to sort tracks by
`Format`
in
`TrackSelectionView`
and
*
Add
an
option to sort tracks by
`Format`
in
`TrackSelectionView`
and
`TrackSelectionDialogBuilder`
(
[
#7709
](
https://github.com/google/ExoPlayer/issues/7709
)
).
*
Adjusted bottom buttons' heights and paddings in StyledPlayerView for
easy tapping.
*
Show overflow button in
`StyledPlayerControlView`
only when there is no
enough space.
*
Fix animation when
`StyledPlayerView`
first shows its playback controls.
*
Improve touch targets in
`StyledPlayerView`
to make tapping easier.
*
Audio:
*
Fix the default audio sink position not advancing correctly when using
`AudioTrack`
-based speed adjustment
...
...
@@ -58,6 +57,8 @@
ad tag via media item playback properties continues to be supported.
This is in preparation for supporting ads in playlists
(
[
#3750
](
https://github.com/google/ExoPlayer/issues/3750
)
).
*
Add a way to override ad media MIME types
(
[
#7961)(https://github.com/google/ExoPlayer/issues/7961)).
### 2.12.0 (2020-09-11) ###
...
...
extensions/ima/src/main/java/com/google/android/exoplayer2/ext/ima/ImaAdsLoader.java
View file @
6611ac48
...
...
@@ -59,7 +59,9 @@ import com.google.android.exoplayer2.ExoPlaybackException;
import
com.google.android.exoplayer2.ExoPlayerLibraryInfo
;
import
com.google.android.exoplayer2.Player
;
import
com.google.android.exoplayer2.Timeline
;
import
com.google.android.exoplayer2.source.MediaSourceFactory
;
import
com.google.android.exoplayer2.source.ads.AdPlaybackState
;
import
com.google.android.exoplayer2.source.ads.AdsMediaSource
;
import
com.google.android.exoplayer2.source.ads.AdsMediaSource.AdLoadException
;
import
com.google.android.exoplayer2.trackselection.TrackSelectionArray
;
import
com.google.android.exoplayer2.upstream.DataSpec
;
...
...
@@ -94,18 +96,17 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
* <p>See https://developers.google.com/interactive-media-ads/docs/sdks/android/compatibility for
* information on compatible ad tag formats. Pass the ad tag URI when setting media item playback
* properties (if using the media item API) or as a {@link DataSpec} when constructing the {@link
*
com.google.android.exoplayer2.source.ads.AdsMediaSource} (if using media sources directly). For
*
the latter case, please note that this implementation delegates loading of the data spec to the
*
IMA SDK, so range and headers specifications will be ignored in ad tag URIs. Literal ads
*
responses can be encoded as data scheme data specs, for example, by constructing the data spec
*
using a URI generated via {@link
Util#getDataUriForString(String, String)}.
*
AdsMediaSource} (if using media sources directly). For the latter case, please note that this
*
implementation delegates loading of the data spec to the IMA SDK, so range and headers
*
specifications will be ignored in ad tag URIs. Literal ads responses can be encoded as data
*
scheme data specs, for example, by constructing the data spec using a URI generated via {@link
* Util#getDataUriForString(String, String)}.
*
* <p>The IMA SDK can report obstructions to the ad view for accurate viewability measurement. This
* means that any overlay views that obstruct the ad overlay but are essential for playback need to
* be registered via the {@link AdViewProvider} passed to the {@link
* com.google.android.exoplayer2.source.ads.AdsMediaSource}. See the <a
* href="https://developers.google.com/interactive-media-ads/docs/sdks/android/client-side/omsdk">
* IMA SDK Open Measurement documentation</a> for more information.
* be registered via the {@link AdViewProvider} passed to the {@link AdsMediaSource}. See the <a
* href="https://developers.google.com/interactive-media-ads/docs/sdks/android/client-side/omsdk">IMA
* SDK Open Measurement documentation</a> for more information.
*/
public
final
class
ImaAdsLoader
implements
Player
.
EventListener
,
com
.
google
.
android
.
exoplayer2
.
source
.
ads
.
AdsLoader
{
...
...
@@ -134,6 +135,7 @@ public final class ImaAdsLoader
@Nullable
private
AdErrorListener
adErrorListener
;
@Nullable
private
AdEventListener
adEventListener
;
@Nullable
private
VideoAdPlayer
.
VideoAdPlayerCallback
videoAdPlayerCallback
;
@Nullable
private
List
<
String
>
adMediaMimeTypes
;
@Nullable
private
Set
<
UiElement
>
adUiElements
;
@Nullable
private
Collection
<
CompanionAdSlot
>
companionAdSlots
;
private
long
adPreloadTimeoutMs
;
...
...
@@ -240,6 +242,23 @@ public final class ImaAdsLoader
}
/**
* Sets the MIME types to prioritize for linear ad media. If not specified, MIME types supported
* by the {@link MediaSourceFactory adMediaSourceFactory} used to construct the {@link
* AdsMediaSource} will be used.
*
* @param adMediaMimeTypes The MIME types to prioritize for linear ad media. May contain {@link
* MimeTypes#APPLICATION_MPD}, {@link MimeTypes#APPLICATION_M3U8}, {@link
* MimeTypes#VIDEO_MP4}, {@link MimeTypes#VIDEO_WEBM}, {@link MimeTypes#VIDEO_H263}, {@link
* MimeTypes#AUDIO_MP4} and {@link MimeTypes#AUDIO_MPEG}.
* @return This builder, for convenience.
* @see AdsRenderingSettings#setMimeTypes(List)
*/
public
Builder
setAdMediaMimeTypes
(
List
<
String
>
adMediaMimeTypes
)
{
this
.
adMediaMimeTypes
=
ImmutableList
.
copyOf
(
checkNotNull
(
adMediaMimeTypes
));
return
this
;
}
/**
* Sets the duration in milliseconds for which the player must buffer while preloading an ad
* group before that ad group is skipped and marked as having failed to load. Pass {@link
* C#TIME_UNSET} if there should be no such timeout. The default value is {@value
...
...
@@ -340,9 +359,8 @@ public final class ImaAdsLoader
* information on compatible ad tags.
* @return The new {@link ImaAdsLoader}.
* @deprecated Pass the ad tag URI when setting media item playback properties (if using the
* media item API) or as a {@link DataSpec} when constructing the {@link
* com.google.android.exoplayer2.source.ads.AdsMediaSource} (if using media sources
* directly).
* media item API) or as a {@link DataSpec} when constructing the {@link AdsMediaSource} (if
* using media sources directly).
*/
@Deprecated
public
ImaAdsLoader
buildForAdTag
(
Uri
adTagUri
)
{
...
...
@@ -362,9 +380,9 @@ public final class ImaAdsLoader
* @return The new {@link ImaAdsLoader}.
* @deprecated Pass the ads response as a data URI when setting media item playback properties
* (if using the media item API) or as a {@link DataSpec} when constructing the {@link
*
com.google.android.exoplayer2.source.ads.AdsMediaSource} (if using media sources
*
directly). {@link Util#getDataUriForString(String, String)} can be used to construct a
*
data URI from
literal string ads response (with MIME type text/xml).
*
AdsMediaSource} (if using media sources directly). {@link
*
Util#getDataUriForString(String, String)} can be used to construct a data URI from
* literal string ads response (with MIME type text/xml).
*/
@Deprecated
public
ImaAdsLoader
buildForAdsResponse
(
String
adsResponse
)
{
...
...
@@ -387,6 +405,7 @@ public final class ImaAdsLoader
focusSkipButtonWhenAvailable
,
playAdBeforeStartPosition
,
mediaBitrate
,
adMediaMimeTypes
,
adUiElements
,
companionAdSlots
,
adErrorListener
,
...
...
@@ -548,8 +567,7 @@ public final class ImaAdsLoader
* more information.
* @deprecated Use {@link Builder} to create an instance. Pass the ad tag URI when setting media
* item playback properties (if using the media item API) or as a {@link DataSpec} when
* constructing the {@link com.google.android.exoplayer2.source.ads.AdsMediaSource} (if using
* media sources directly).
* constructing the {@link AdsMediaSource} (if using media sources directly).
*/
@Deprecated
public
ImaAdsLoader
(
Context
context
,
Uri
adTagUri
)
{
...
...
@@ -988,7 +1006,10 @@ public final class ImaAdsLoader
private
AdsRenderingSettings
setupAdsRendering
()
{
AdsRenderingSettings
adsRenderingSettings
=
imaFactory
.
createAdsRenderingSettings
();
adsRenderingSettings
.
setEnablePreloading
(
true
);
adsRenderingSettings
.
setMimeTypes
(
supportedMimeTypes
);
adsRenderingSettings
.
setMimeTypes
(
configuration
.
adMediaMimeTypes
!=
null
?
configuration
.
adMediaMimeTypes
:
supportedMimeTypes
);
if
(
configuration
.
mediaLoadTimeoutMs
!=
TIMEOUT_UNSET
)
{
adsRenderingSettings
.
setLoadVideoTimeout
(
configuration
.
mediaLoadTimeoutMs
);
}
...
...
extensions/ima/src/main/java/com/google/android/exoplayer2/ext/ima/ImaUtil.java
View file @
6611ac48
...
...
@@ -88,6 +88,7 @@ import java.util.Set;
public
final
boolean
focusSkipButtonWhenAvailable
;
public
final
boolean
playAdBeforeStartPosition
;
public
final
int
mediaBitrate
;
@Nullable
public
final
List
<
String
>
adMediaMimeTypes
;
@Nullable
public
final
Set
<
UiElement
>
adUiElements
;
@Nullable
public
final
Collection
<
CompanionAdSlot
>
companionAdSlots
;
@Nullable
public
final
AdErrorEvent
.
AdErrorListener
applicationAdErrorListener
;
...
...
@@ -102,6 +103,7 @@ import java.util.Set;
boolean
focusSkipButtonWhenAvailable
,
boolean
playAdBeforeStartPosition
,
int
mediaBitrate
,
@Nullable
List
<
String
>
adMediaMimeTypes
,
@Nullable
Set
<
UiElement
>
adUiElements
,
@Nullable
Collection
<
CompanionAdSlot
>
companionAdSlots
,
@Nullable
AdErrorEvent
.
AdErrorListener
applicationAdErrorListener
,
...
...
@@ -114,6 +116,7 @@ import java.util.Set;
this
.
focusSkipButtonWhenAvailable
=
focusSkipButtonWhenAvailable
;
this
.
playAdBeforeStartPosition
=
playAdBeforeStartPosition
;
this
.
mediaBitrate
=
mediaBitrate
;
this
.
adMediaMimeTypes
=
adMediaMimeTypes
;
this
.
adUiElements
=
adUiElements
;
this
.
companionAdSlots
=
companionAdSlots
;
this
.
applicationAdErrorListener
=
applicationAdErrorListener
;
...
...
extensions/ima/src/test/java/com/google/android/exoplayer2/ext/ima/ImaAdsLoaderTest.java
View file @
6611ac48
...
...
@@ -64,6 +64,7 @@ import com.google.android.exoplayer2.source.ads.SinglePeriodAdTimeline;
import
com.google.android.exoplayer2.testutil.FakeTimeline
;
import
com.google.android.exoplayer2.testutil.FakeTimeline.TimelineWindowDefinition
;
import
com.google.android.exoplayer2.upstream.DataSpec
;
import
com.google.android.exoplayer2.util.MimeTypes
;
import
com.google.android.exoplayer2.util.Util
;
import
com.google.common.collect.ImmutableList
;
import
com.google.common.collect.ImmutableMap
;
...
...
@@ -755,6 +756,40 @@ public final class ImaAdsLoaderTest {
}
@Test
public
void
setsDefaultMimeTypes
()
throws
Exception
{
setupPlayback
(
CONTENT_TIMELINE
,
ImmutableList
.
of
(
0
f
));
imaAdsLoader
.
setSupportedContentTypes
(
C
.
TYPE_DASH
,
C
.
TYPE_OTHER
);
imaAdsLoader
.
start
(
adsLoaderListener
,
adViewProvider
);
verify
(
mockAdsRenderingSettings
)
.
setMimeTypes
(
ImmutableList
.
of
(
MimeTypes
.
APPLICATION_MPD
,
MimeTypes
.
VIDEO_MP4
,
MimeTypes
.
VIDEO_WEBM
,
MimeTypes
.
VIDEO_H263
,
MimeTypes
.
AUDIO_MP4
,
MimeTypes
.
AUDIO_MPEG
));
}
@Test
public
void
buildWithAdMediaMimeTypes_setsMimeTypes
()
throws
Exception
{
setupPlayback
(
CONTENT_TIMELINE
,
ImmutableList
.
of
(
0
f
),
new
ImaAdsLoader
.
Builder
(
getApplicationContext
())
.
setImaFactory
(
mockImaFactory
)
.
setImaSdkSettings
(
mockImaSdkSettings
)
.
setAdMediaMimeTypes
(
ImmutableList
.
of
(
MimeTypes
.
AUDIO_MPEG
))
.
build
(),
TEST_DATA_SPEC
);
imaAdsLoader
.
setSupportedContentTypes
(
C
.
TYPE_OTHER
);
imaAdsLoader
.
start
(
adsLoaderListener
,
adViewProvider
);
verify
(
mockAdsRenderingSettings
).
setMimeTypes
(
ImmutableList
.
of
(
MimeTypes
.
AUDIO_MPEG
));
}
@Test
public
void
stop_unregistersAllVideoControlOverlays
()
{
setupPlayback
(
CONTENT_TIMELINE
,
PREROLL_CUE_POINTS_SECONDS
);
imaAdsLoader
.
start
(
adsLoaderListener
,
adViewProvider
);
...
...
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