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
0c301fef
authored
Nov 06, 2020
by
andrewlewis
Committed by
Andrew Lewis
Nov 06, 2020
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Pass AdsMediaSource to other AdsLoader methods
Issue: #3750 PiperOrigin-RevId: 341020676
parent
d94943f0
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
38 additions
and
18 deletions
extensions/ima/src/main/java/com/google/android/exoplayer2/ext/ima/ImaAdsLoader.java
extensions/ima/src/test/java/com/google/android/exoplayer2/ext/ima/ImaAdsLoaderTest.java
library/core/src/main/java/com/google/android/exoplayer2/source/ads/AdsLoader.java
library/core/src/main/java/com/google/android/exoplayer2/source/ads/AdsMediaSource.java
library/core/src/test/java/com/google/android/exoplayer2/ExoPlayerTest.java
extensions/ima/src/main/java/com/google/android/exoplayer2/ext/ima/ImaAdsLoader.java
View file @
0c301fef
...
...
@@ -494,7 +494,7 @@ public final class ImaAdsLoader
}
@Override
public
void
stop
()
{
public
void
stop
(
AdsMediaSource
adsMediaSource
)
{
if
(
player
!=
null
&&
adTagLoader
!=
null
)
{
adTagLoader
.
stop
();
}
...
...
@@ -508,14 +508,19 @@ public final class ImaAdsLoader
}
@Override
public
void
handlePrepareComplete
(
int
adGroupIndex
,
int
adIndexInAdGroup
)
{
public
void
handlePrepareComplete
(
AdsMediaSource
adsMediaSource
,
int
adGroupIndex
,
int
adIndexInAdGroup
)
{
if
(
adTagLoader
!=
null
)
{
adTagLoader
.
handlePrepareComplete
(
adGroupIndex
,
adIndexInAdGroup
);
}
}
@Override
public
void
handlePrepareError
(
int
adGroupIndex
,
int
adIndexInAdGroup
,
IOException
exception
)
{
public
void
handlePrepareError
(
AdsMediaSource
adsMediaSource
,
int
adGroupIndex
,
int
adIndexInAdGroup
,
IOException
exception
)
{
if
(
adTagLoader
!=
null
)
{
adTagLoader
.
handlePrepareError
(
adGroupIndex
,
adIndexInAdGroup
,
exception
);
}
...
...
extensions/ima/src/test/java/com/google/android/exoplayer2/ext/ima/ImaAdsLoaderTest.java
View file @
0c301fef
...
...
@@ -265,7 +265,7 @@ public final class ImaAdsLoaderTest {
imaAdsLoader
.
onPositionDiscontinuity
(
Player
.
DISCONTINUITY_REASON_SEEK
);
adEventListener
.
onAdEvent
(
getAdEvent
(
AdEventType
.
CONTENT_RESUME_REQUESTED
,
/* ad= */
null
));
imaAdsLoader
.
handlePrepareError
(
/* adGroupIndex= */
0
,
/* adIndexInAdGroup= */
0
,
new
IOException
());
adsMediaSource
,
/* adGroupIndex= */
0
,
/* adIndexInAdGroup= */
0
,
new
IOException
());
}
@Test
...
...
@@ -836,7 +836,7 @@ public final class ImaAdsLoaderTest {
imaAdsLoader
.
start
(
adsMediaSource
,
TEST_DATA_SPEC
,
TEST_ADS_ID
,
adViewProvider
,
adsLoaderListener
);
imaAdsLoader
.
requestAds
(
TEST_DATA_SPEC
,
adViewGroup
);
imaAdsLoader
.
stop
();
imaAdsLoader
.
stop
(
adsMediaSource
);
InOrder
inOrder
=
inOrder
(
mockAdDisplayContainer
);
inOrder
.
verify
(
mockAdDisplayContainer
).
registerFriendlyObstruction
(
mockFriendlyObstruction
);
...
...
library/core/src/main/java/com/google/android/exoplayer2/source/ads/AdsLoader.java
View file @
0c301fef
...
...
@@ -40,10 +40,10 @@ import java.util.List;
*
* <p>{@link #start(AdsMediaSource, DataSpec, Object, AdViewProvider, EventListener)} will be called
* when an ads media source first initializes, at which point the loader can request ads. If the
* player enters the background, {@link #stop(
)} will be called. Loaders should maintain any a
d
*
playback state in preparation for a later call to {@link #start(AdsMediaSource, DataSpec, Object
,
*
AdViewProvider, EventListener)}. If an ad is playing when the player is detached, update the ad
* playback state with the current playback position using {@link
* player enters the background, {@link #stop(
AdsMediaSource)} will be called. Loaders shoul
d
*
maintain any ad playback state in preparation for a later call to {@link #start(AdsMediaSource
,
*
DataSpec, Object, AdViewProvider, EventListener)}. If an ad is playing when the player is
*
detached, update the ad
playback state with the current playback position using {@link
* AdPlaybackState#withAdResumePositionUs(long)}.
*
* <p>If {@link EventListener#onAdPlaybackState(AdPlaybackState)} has been called, the
...
...
@@ -218,26 +218,31 @@ public interface AdsLoader {
/**
* Stops using the ads loader for playback and deregisters the event listener. Called on the main
* thread by {@link AdsMediaSource}.
*
* @param adsMediaSource The ads media source requesting to stop loading/playing ads.
*/
void
stop
();
void
stop
(
AdsMediaSource
adsMediaSource
);
/**
* Notifies the ads loader that preparation of an ad media period is complete. Called on the main
* thread by {@link AdsMediaSource}.
*
* @param adsMediaSource The ads media source for which preparation of ad media completed.
* @param adGroupIndex The index of the ad group.
* @param adIndexInAdGroup The index of the ad in the ad group.
*/
void
handlePrepareComplete
(
int
adGroupIndex
,
int
adIndexInAdGroup
);
void
handlePrepareComplete
(
AdsMediaSource
adsMediaSource
,
int
adGroupIndex
,
int
adIndexInAdGroup
);
/**
* Notifies the ads loader that the player was not able to prepare media for a given ad.
* Implementations should update the ad playback state as the specified ad has failed to load.
* Called on the main thread by {@link AdsMediaSource}.
*
* @param adsMediaSource The ads media source for which preparation of ad media failed.
* @param adGroupIndex The index of the ad group.
* @param adIndexInAdGroup The index of the ad in the ad group.
* @param exception The preparation error.
*/
void
handlePrepareError
(
int
adGroupIndex
,
int
adIndexInAdGroup
,
IOException
exception
);
void
handlePrepareError
(
AdsMediaSource
adsMediaSource
,
int
adGroupIndex
,
int
adIndexInAdGroup
,
IOException
exception
);
}
library/core/src/main/java/com/google/android/exoplayer2/source/ads/AdsMediaSource.java
View file @
0c301fef
...
...
@@ -259,7 +259,7 @@ public final class AdsMediaSource extends CompositeMediaSource<MediaPeriodId> {
contentTimeline
=
null
;
adPlaybackState
=
null
;
adMediaSourceHolders
=
new
AdMediaSourceHolder
[
0
][];
mainHandler
.
post
(
adsLoader:
:
stop
);
mainHandler
.
post
(
()
->
adsLoader
.
stop
(
/* adsMediaSource= */
this
)
);
}
@Override
...
...
@@ -385,7 +385,9 @@ public final class AdsMediaSource extends CompositeMediaSource<MediaPeriodId> {
mainHandler
.
post
(
()
->
adsLoader
.
handlePrepareComplete
(
mediaPeriodId
.
adGroupIndex
,
mediaPeriodId
.
adIndexInAdGroup
));
/* adsMediaSource= */
AdsMediaSource
.
this
,
mediaPeriodId
.
adGroupIndex
,
mediaPeriodId
.
adIndexInAdGroup
));
}
@Override
...
...
@@ -402,7 +404,10 @@ public final class AdsMediaSource extends CompositeMediaSource<MediaPeriodId> {
mainHandler
.
post
(
()
->
adsLoader
.
handlePrepareError
(
mediaPeriodId
.
adGroupIndex
,
mediaPeriodId
.
adIndexInAdGroup
,
exception
));
/* adsMediaSource= */
AdsMediaSource
.
this
,
mediaPeriodId
.
adGroupIndex
,
mediaPeriodId
.
adIndexInAdGroup
,
exception
));
}
}
...
...
library/core/src/test/java/com/google/android/exoplayer2/ExoPlayerTest.java
View file @
0c301fef
...
...
@@ -9029,13 +9029,18 @@ public final class ExoPlayerTest {
AdsLoader
.
EventListener
eventListener
)
{}
@Override
public
void
stop
()
{}
public
void
stop
(
AdsMediaSource
adsMediaSource
)
{}
@Override
public
void
handlePrepareComplete
(
int
adGroupIndex
,
int
adIndexInAdGroup
)
{}
public
void
handlePrepareComplete
(
AdsMediaSource
adsMediaSource
,
int
adGroupIndex
,
int
adIndexInAdGroup
)
{}
@Override
public
void
handlePrepareError
(
int
adGroupIndex
,
int
adIndexInAdGroup
,
IOException
exception
)
{}
public
void
handlePrepareError
(
AdsMediaSource
adsMediaSource
,
int
adGroupIndex
,
int
adIndexInAdGroup
,
IOException
exception
)
{}
}
private
static
class
FakeAdViewProvider
implements
AdsLoader
.
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