Add ExoMediaDrm.OnExpirationUpdateListener

Which mirrors MediaDrm.OnExpirationUpdateListener.

PiperOrigin-RevId: 298826713
This commit is contained in:
aquilescanta 2020-03-04 13:15:14 +00:00 committed by Oliver Woodman
parent 61935e14bf
commit 2b88961bc1
3 changed files with 45 additions and 6 deletions

View File

@ -44,6 +44,11 @@ public final class DummyExoMediaDrm<T extends ExoMediaCrypto> implements ExoMedi
// Do nothing.
}
@Override
public void setOnExpirationUpdateListener(OnExpirationUpdateListener<? super T> listener) {
// Do nothing.
}
@Override
public byte[] openSession() throws MediaDrmException {
throw new MediaDrmException("Attempting to open a session using a dummy ExoMediaDrm.");

View File

@ -149,6 +149,23 @@ public interface ExoMediaDrm<T extends ExoMediaCrypto> {
boolean hasNewUsableKey);
}
/** @see android.media.MediaDrm.OnExpirationUpdateListener */
interface OnExpirationUpdateListener<T extends ExoMediaCrypto> {
/**
* Called when a session expiration update occurs, to inform the app about the change in
* expiration time
*
* @param mediaDrm The {@link ExoMediaDrm} object on which the event occurred.
* @param sessionId The DRM session ID on which the event occurred
* @param expirationTimeMs The new expiration time for the keys in the session. The time is in
* milliseconds, relative to the Unix epoch. A time of 0 indicates that the keys never
* expire.
*/
void onExpirationUpdate(
ExoMediaDrm<? extends T> mediaDrm, byte[] sessionId, long expirationTimeMs);
}
/** @see android.media.MediaDrm.KeyStatus */
final class KeyStatus {
@ -222,9 +239,10 @@ public interface ExoMediaDrm<T extends ExoMediaCrypto> {
*/
void setOnKeyStatusChangeListener(OnKeyStatusChangeListener<? super T> listener);
/**
* @see MediaDrm#openSession()
*/
/** @see MediaDrm#setOnExpirationUpdateListener(MediaDrm.OnExpirationUpdateListener, Handler) */
void setOnExpirationUpdateListener(OnExpirationUpdateListener<? super T> listener);
/** @see MediaDrm#openSession() */
byte[] openSession() throws MediaDrmException;
/**

View File

@ -107,7 +107,7 @@ public final class FrameworkMediaDrm implements ExoMediaDrm<FrameworkMediaCrypto
@Override
public void setOnEventListener(
final ExoMediaDrm.OnEventListener<? super FrameworkMediaCrypto> listener) {
ExoMediaDrm.OnEventListener<? super FrameworkMediaCrypto> listener) {
mediaDrm.setOnEventListener(
listener == null
? null
@ -117,7 +117,7 @@ public final class FrameworkMediaDrm implements ExoMediaDrm<FrameworkMediaCrypto
@Override
public void setOnKeyStatusChangeListener(
final ExoMediaDrm.OnKeyStatusChangeListener<? super FrameworkMediaCrypto> listener) {
ExoMediaDrm.OnKeyStatusChangeListener<? super FrameworkMediaCrypto> listener) {
if (Util.SDK_INT < 23) {
throw new UnsupportedOperationException();
}
@ -133,7 +133,23 @@ public final class FrameworkMediaDrm implements ExoMediaDrm<FrameworkMediaCrypto
listener.onKeyStatusChange(
FrameworkMediaDrm.this, sessionId, exoKeyInfo, hasNewUsableKey);
},
null);
/* handler= */ null);
}
@Override
public void setOnExpirationUpdateListener(
OnExpirationUpdateListener<? super FrameworkMediaCrypto> listener) {
if (Util.SDK_INT < 23) {
throw new UnsupportedOperationException();
}
mediaDrm.setOnExpirationUpdateListener(
listener == null
? null
: (mediaDrm, sessionId, expirationTimeMs) -> {
listener.onExpirationUpdate(FrameworkMediaDrm.this, sessionId, expirationTimeMs);
},
/* handler= */ null);
}
@Override