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
e8293b92
authored
Feb 06, 2020
by
bachinger
Committed by
kim-vde
Feb 11, 2020
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
remove deprecated usage of onPlayerStateChanged in ImaAdsLoader
PiperOrigin-RevId: 293612280
parent
b69918a2
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
59 additions
and
42 deletions
extensions/ima/src/main/java/com/google/android/exoplayer2/ext/ima/ImaAdsLoader.java
extensions/ima/src/main/java/com/google/android/exoplayer2/ext/ima/ImaAdsLoader.java
View file @
e8293b92
...
...
@@ -332,7 +332,7 @@ public final class ImaAdsLoader
private
VideoProgressUpdate
lastAdProgress
;
private
int
lastVolumePercentage
;
private
AdsManager
adsManager
;
@Nullable
private
AdsManager
adsManager
;
private
boolean
initializedAdsManager
;
private
AdLoadException
pendingAdLoadError
;
private
Timeline
timeline
;
...
...
@@ -973,12 +973,21 @@ public final class ImaAdsLoader
initializedAdsManager
=
true
;
initializeAdsManager
();
}
onPositionDiscontinuity
(
Player
.
DISCONTINUITY_REASON_INTERNAL
);
checkForContentCompleteOrNewAdGroup
(
);
}
@Override
public
void
onPlayerStateChanged
(
boolean
playWhenReady
,
@Player
.
State
int
playbackState
)
{
if
(
adsManager
==
null
)
{
public
void
onPlaybackStateChanged
(
@Player
.
State
int
playbackState
)
{
if
(
adsManager
==
null
||
player
==
null
)
{
return
;
}
handlePlayerStateChanged
(
player
.
getPlayWhenReady
(),
playbackState
);
}
@Override
public
void
onPlayWhenReadyChanged
(
boolean
playWhenReady
,
@Player
.
PlayWhenReadyChangeReason
int
reason
)
{
if
(
adsManager
==
null
||
player
==
null
)
{
return
;
}
...
...
@@ -991,18 +1000,7 @@ public final class ImaAdsLoader
adsManager
.
resume
();
return
;
}
if
(
imaAdState
==
IMA_AD_STATE_NONE
&&
playbackState
==
Player
.
STATE_BUFFERING
&&
playWhenReady
)
{
checkForContentComplete
();
}
else
if
(
imaAdState
!=
IMA_AD_STATE_NONE
&&
playbackState
==
Player
.
STATE_ENDED
)
{
for
(
int
i
=
0
;
i
<
adCallbacks
.
size
();
i
++)
{
adCallbacks
.
get
(
i
).
onEnded
();
}
if
(
DEBUG
)
{
Log
.
d
(
TAG
,
"VideoAdPlayerCallback.onEnded in onPlayerStateChanged"
);
}
}
handlePlayerStateChanged
(
playWhenReady
,
player
.
getPlaybackState
());
}
@Override
...
...
@@ -1016,32 +1014,7 @@ public final class ImaAdsLoader
@Override
public
void
onPositionDiscontinuity
(
@Player
.
DiscontinuityReason
int
reason
)
{
if
(
adsManager
==
null
)
{
return
;
}
if
(!
playingAd
&&
!
player
.
isPlayingAd
())
{
checkForContentComplete
();
if
(
sentContentComplete
)
{
for
(
int
i
=
0
;
i
<
adPlaybackState
.
adGroupCount
;
i
++)
{
if
(
adPlaybackState
.
adGroupTimesUs
[
i
]
!=
C
.
TIME_END_OF_SOURCE
)
{
adPlaybackState
=
adPlaybackState
.
withSkippedAdGroup
(
i
);
}
}
updateAdPlaybackState
();
}
else
if
(!
timeline
.
isEmpty
())
{
long
positionMs
=
player
.
getCurrentPosition
();
timeline
.
getPeriod
(
0
,
period
);
int
newAdGroupIndex
=
period
.
getAdGroupIndexForPositionUs
(
C
.
msToUs
(
positionMs
));
if
(
newAdGroupIndex
!=
C
.
INDEX_UNSET
)
{
sentPendingContentPositionMs
=
false
;
pendingContentPositionMs
=
positionMs
;
if
(
newAdGroupIndex
!=
adGroupIndex
)
{
shouldNotifyAdPrepareError
=
false
;
}
}
}
}
updateImaStateForPlayerState
();
checkForContentCompleteOrNewAdGroup
();
}
// Internal methods.
...
...
@@ -1174,6 +1147,50 @@ public final class ImaAdsLoader
}
}
private
void
handlePlayerStateChanged
(
boolean
playWhenReady
,
@Player
.
State
int
playbackState
)
{
if
(
imaAdState
==
IMA_AD_STATE_NONE
&&
playbackState
==
Player
.
STATE_BUFFERING
&&
playWhenReady
)
{
checkForContentComplete
();
}
else
if
(
imaAdState
!=
IMA_AD_STATE_NONE
&&
playbackState
==
Player
.
STATE_ENDED
)
{
for
(
int
i
=
0
;
i
<
adCallbacks
.
size
();
i
++)
{
adCallbacks
.
get
(
i
).
onEnded
();
}
if
(
DEBUG
)
{
Log
.
d
(
TAG
,
"VideoAdPlayerCallback.onEnded in onPlaybackStateChanged"
);
}
}
}
private
void
checkForContentCompleteOrNewAdGroup
()
{
if
(
adsManager
==
null
||
player
==
null
)
{
return
;
}
if
(!
playingAd
&&
!
player
.
isPlayingAd
())
{
checkForContentComplete
();
if
(
sentContentComplete
)
{
for
(
int
i
=
0
;
i
<
adPlaybackState
.
adGroupCount
;
i
++)
{
if
(
adPlaybackState
.
adGroupTimesUs
[
i
]
!=
C
.
TIME_END_OF_SOURCE
)
{
adPlaybackState
=
adPlaybackState
.
withSkippedAdGroup
(
/* adGroupIndex= */
i
);
}
}
updateAdPlaybackState
();
}
else
if
(!
timeline
.
isEmpty
())
{
long
positionMs
=
player
.
getCurrentPosition
();
timeline
.
getPeriod
(
/* periodIndex= */
0
,
period
);
int
newAdGroupIndex
=
period
.
getAdGroupIndexForPositionUs
(
C
.
msToUs
(
positionMs
));
if
(
newAdGroupIndex
!=
C
.
INDEX_UNSET
)
{
sentPendingContentPositionMs
=
false
;
pendingContentPositionMs
=
positionMs
;
if
(
newAdGroupIndex
!=
adGroupIndex
)
{
shouldNotifyAdPrepareError
=
false
;
}
}
}
}
updateImaStateForPlayerState
();
}
private
void
updateImaStateForPlayerState
()
{
boolean
wasPlayingAd
=
playingAd
;
int
oldPlayingAdIndexInAdGroup
=
playingAdIndexInAdGroup
;
...
...
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